When a volume is opened, get its kref via get_device() call.
And put the reference when closing the volume. With this, we
may have a bit saner volume delete.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
}
err = ubi_remove_volume(desc);
- if (err)
- ubi_close_volume(desc);
-
+ /*
+ * The volume is deleted, and the 'struct ubi_volume' object
+ * will be freed when 'ubi_close_volume()' will call
+ * 'put_device()'.
+ */
+ ubi_close_volume(desc);
break;
}
vol->exclusive = 1;
break;
}
+ get_device(&vol->dev);
spin_unlock(&ubi->volumes_lock);
desc->vol = vol;
spin_unlock(&vol->ubi->volumes_lock);
kfree(desc);
+ put_device(&vol->dev);
module_put(THIS_MODULE);
}
EXPORT_SYMBOL_GPL(ubi_close_volume);
vol->eba_tbl = NULL;
cdev_del(&vol->cdev);
volume_sysfs_close(vol);
- kfree(desc);
spin_lock(&ubi->volumes_lock);
ubi->rsvd_pebs -= reserved_pebs;
spin_unlock(&ubi->volumes_lock);
paranoid_check_volumes(ubi);
- mutex_unlock(&ubi->volumes_mutex);
- module_put(THIS_MODULE);
- return 0;
-
out:
mutex_unlock(&ubi->volumes_mutex);
return err;