/* This function is used by ubi_leb_read() and ubi_leb_read_sg() to perform sanity checks.  */
static int leb_read_sanity_check(struct ubi_volume_desc *desc, int lnum, int offset, int len)
/* This function is used by ubi_leb_read() and ubi_leb_read_sg() to perform sanity checks.  */
static int leb_read_sanity_check(struct ubi_volume_desc *desc, int lnum, int offset, int len)
{
	struct ubi_volume *vol = desc->vol;
	struct ubi_device *ubi = vol->ubi;
	int vol_id = vol->vol_id;
	if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 ||
	    lnum >= vol->used_ebs || offset < 0 || len < 0 ||
	    offset + len > vol->usable_leb_size)
		return -EINVAL;
	if (vol->vol_type == UBI_STATIC_VOLUME) {
		if (vol->used_ebs == 0)
			return 0;
		if (lnum == vol->used_ebs - 1 &&
		    offset + len > vol->last_eb_bytes)
			return -EINVAL;
	}
	if (vol->upd_marker)
		return -EBADF;
	return 0;
}