/* Check if length including bad blocks fits into device. */
static size_t get_len_incl_bad(nand_info_t *nand, loff_t offset, const size_t length)
/* Check if length including bad blocks fits into device. */
static size_t get_len_incl_bad(nand_info_t *nand, loff_t offset, const size_t length)
{
	size_t len_incl_bad = 0;
	size_t len_excl_bad = 0;
	size_t block_len;
	while (len_excl_bad < length) {
		block_len = nand->erasesize - (offset & (nand->erasesize - 1));
		if (!nand_block_isbad (nand, offset & ~(nand->erasesize - 1)))
			len_excl_bad += block_len;
		len_incl_bad += block_len;
		offset       += block_len;
		if (offset >= nand->size)
			break;
	}
	return len_incl_bad;
}