/* This function calculates the gap between current number of PEBs reserved for bad eraseblock handling and the required level of PEBs that must be reserved, and if necessary, reserves more PEBs to fill that gap, according to availability. Should be called with ubi->volumes_lock held.  */
void ubi_update_reserved(struct ubi_device *ubi)
/* This function calculates the gap between current number of PEBs reserved for bad eraseblock handling and the required level of PEBs that must be reserved, and if necessary, reserves more PEBs to fill that gap, according to availability. Should be called with ubi->volumes_lock held.  */
void ubi_update_reserved(struct ubi_device *ubi)
{
	int need = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
	if (need <= 0 || ubi->avail_pebs == 0)
		return;
	need = min_t(int, need, ubi->avail_pebs);
	ubi->avail_pebs -= need;
	ubi->rsvd_pebs += need;
	ubi->beb_rsvd_pebs += need;
	ubi_msg(ubi, "reserved more %d PEBs for bad PEB handling", need);
}