/* Return: a positive number nand_bbt_block_status status or -ERANGE if @entry is bigger than the BBT size.  */
int nanddev_bbt_get_block_status(const struct nand_device *nand, unsigned int entry)
/* Return: a positive number nand_bbt_block_status status or -ERANGE if @entry is bigger than the BBT size.  */
int nanddev_bbt_get_block_status(const struct nand_device *nand, unsigned int entry)
{
	unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
	unsigned long *pos = nand->bbt.cache +
			     ((entry * bits_per_block) / BITS_PER_LONG);
	unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
	unsigned long status;
	if (entry >= nanddev_neraseblocks(nand))
		return -ERANGE;
	status = pos[0] >> offs;
	if (bits_per_block + offs > BITS_PER_LONG)
		status |= pos[1] << (BITS_PER_LONG - offs);
	return status & GENMASK(bits_per_block - 1, 0);
}