/* Return: 0 in case of success or -ERANGE if @entry is bigger than the BBT size.  */
int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, enum nand_bbt_block_status status)
/* Return: 0 in case of success or -ERANGE if @entry is bigger than the BBT size.  */
int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, enum nand_bbt_block_status status)
{
	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 val = status & GENMASK(bits_per_block - 1, 0);
	if (entry >= nanddev_neraseblocks(nand))
		return -ERANGE;
	pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
	pos[0] |= val << offs;
	if (bits_per_block + offs > BITS_PER_LONG) {
		unsigned int rbits = bits_per_block + offs - BITS_PER_LONG;
		pos[1] &= ~GENMASK(rbits - 1, 0);
		pos[1] |= val >> rbits;
	}
	return 0;
}