/* ubi_close_volume - close UBI volume. @desc: volume descriptor  */
void ubi_close_volume(struct ubi_volume_desc *desc)
/* ubi_close_volume - close UBI volume. @desc: volume descriptor  */
void ubi_close_volume(struct ubi_volume_desc *desc)
{
	struct ubi_volume *vol = desc->vol;
	struct ubi_device *ubi = vol->ubi;
	dbg_gen("close device %d, volume %d, mode %d",
		ubi->ubi_num, vol->vol_id, desc->mode);
	spin_lock(&ubi->volumes_lock);
	switch (desc->mode) {
	case UBI_READONLY:
		vol->readers -= 1;
		break;
	case UBI_READWRITE:
		vol->writers -= 1;
		break;
	case UBI_EXCLUSIVE:
		vol->exclusive = 0;
		break;
	case UBI_METAONLY:
		vol->metaonly = 0;
		break;
	}
	vol->ref_count -= 1;
	spin_unlock(&ubi->volumes_lock);
	kfree(desc);
	put_device(&vol->dev);
	ubi_put_device(ubi);
	module_put(THIS_MODULE);
}