/* Returns zero on success, a negative error code otherwise.  */
static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf, u8 *oobbuf, int start, int nbytes, int(*iter)(struct mtd_info *, int section, struct mtd_oob_region *oobregion))
/* Returns zero on success, a negative error code otherwise.  */
static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf, u8 *oobbuf, int start, int nbytes, int(*iter)(struct mtd_info *, int section, struct mtd_oob_region *oobregion))
{
	struct mtd_oob_region oobregion;
	int section, ret;
	ret = mtd_ooblayout_find_region(mtd, start, &section,
					&oobregion, iter);
	while (!ret) {
		int cnt;
		cnt = min_t(int, nbytes, oobregion.length);
		memcpy(oobbuf + oobregion.offset, buf, cnt);
		buf += cnt;
		nbytes -= cnt;
		if (!nbytes)
			break;
		ret = iter(mtd, ++section, &oobregion);
	}
	return ret;
}