target/linux/generic/files/drivers/mtd/nand/mtk_bmt_nmbm.c
static int nmbn_read_data(struct nmbm_instance *ni, uint64_t addr, void *data,
			  uint32_t size)
{
	uint64_t off = addr;
	uint8_t *ptr = data;
	uint32_t sizeremain = size, chunksize, leading;
	int ret;

	while (sizeremain) {
		leading = off & (bmtd.pg_size - 1);
		chunksize = bmtd.pg_size - leading;
		if (chunksize > sizeremain)
			chunksize = sizeremain;

		if (chunksize == bmtd.pg_size) {
			ret = nmbm_read_phys_page(ni, off - leading, ptr, NULL);
			if (ret < 0)
				return ret;
		} else {
			ret = nmbm_read_phys_page(ni, off - leading,
						  ni->page_cache, NULL);
			if (ret < 0)
				return ret;

			memcpy(ptr, ni->page_cache + leading, chunksize);
		}

		off += chunksize;
		ptr += chunksize;
		sizeremain -= chunksize;
	}

	return 0;
}
/*
 * nmbn_read_data - Read data
 * @ni: NMBM instance structure
 * @addr: linear address where the data will be read from
 * @data: the data to be read
 * @size: the size of data
 *
 * Read data range.
 * Every page will be tried for at most NMBM_TRY_COUNT times.
 *
 * Return 0 for success, positive value for corrected bitflip count,
 * -EBADMSG for ecc error, other negative values for other errors
 */
Read data
@ni: NMBM instance structure
@addr: linear address where the data will be read from
@data: the data to be read
@size: the size of data

Read data range.
Every page will be tried for at most NMBM_TRY_COUNT times.

Return 0 for success, positive value for corrected bitflip count,
-EBADMSG for ecc error, other negative values for other errors
Read data @ni : NMBM instance structure @addr : linear address where the data will be read from @data : the data to be read @size : the size of data Read data range . Every page will be tried for at most NMBM_TRY_COUNT times . Return 0 for success positive value for corrected bitflip count - EBADMSG for ecc error other negative values for other errors
static int nmbn_read_data(struct nmbm_instance *ni, uint64_t addr, void *data,
			  uint32_t size)
{
	uint64_t off = addr;
	uint8_t *ptr = data;
	uint32_t sizeremain = size, chunksize, leading;
	int ret;
	while (sizeremain) {
		leading = off & (bmtd.pg_size - 1);
		chunksize = bmtd.pg_size - leading;
		if (chunksize > sizeremain)
			chunksize = sizeremain;
		if (chunksize == bmtd.pg_size) {
			ret = nmbm_read_phys_page(ni, off - leading, ptr, NULL);
			if (ret < 0)
				return ret;
		} else {
			ret = nmbm_read_phys_page(ni, off - leading,
						  ni->page_cache, NULL);
			if (ret < 0)
				return ret;
			memcpy(ptr, ni->page_cache + leading, chunksize);
		}
		off += chunksize;
		ptr += chunksize;
		sizeremain -= chunksize;
	}
	return 0;
}
static int nmbn_read_data ( struct nmbm_instance * ni , uint64_t addr , void * data , uint32_t size ) { uint64_t off = addr ; uint8_t * ptr = data ; uint32_t sizeremain = size , chunksize , leading ; int ret ; while ( sizeremain ) { leading = off & ( bmtd . pg_size - 1 ) ; chunksize = bmtd . pg_size - leading ; if ( chunksize > sizeremain ) chunksize = sizeremain ; if ( chunksize == bmtd . pg_size ) { ret = nmbm_read_phys_page ( ni , off - leading , ptr , NULL ) ; if ( ret < 0 ) return ret ; } else { ret = nmbm_read_phys_page ( ni , off - leading , ni -> page_cache , NULL ) ; if ( ret < 0 ) return ret ; memcpy ( ptr , ni -> page_cache + leading , chunksize ) ; } off += chunksize ; ptr += chunksize ; sizeremain -= chunksize ; } return 0 ; }
nmbn_read_data - Read data
 @ni: NMBM instance structure
 @addr: linear address where the data will be read from
 @data: the data to be read
 @size: the size of data
nmbn_read_data - Read data @ni : NMBM instance structure @addr : linear address where the data will be read from @data : the data to be read @size : the size of data