]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
UBI: get device when opening volume
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 17 Dec 2007 11:09:09 +0000 (13:09 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 26 Dec 2007 17:15:15 +0000 (19:15 +0200)
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>
drivers/mtd/ubi/cdev.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/vmt.c

index 24344ba3cfed879ad5d42f35e37c72feb4915d23..35d34b675c78edc69d5002c817998ca583dd2444 100644 (file)
@@ -635,9 +635,12 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
                }
 
                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;
        }
 
index 8e15002a36c3c86eae763e40e17e5b150633ee7d..96f5fef5f3fa6830376487ee6bcf2c11b4805129 100644 (file)
@@ -156,6 +156,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
                vol->exclusive = 1;
                break;
        }
+       get_device(&vol->dev);
        spin_unlock(&ubi->volumes_lock);
 
        desc->vol = vol;
@@ -274,6 +275,7 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
        spin_unlock(&vol->ubi->volumes_lock);
 
        kfree(desc);
+       put_device(&vol->dev);
        module_put(THIS_MODULE);
 }
 EXPORT_SYMBOL_GPL(ubi_close_volume);
index ec2dd3c65c43bc92c656af60ef8bec934370e3f9..9dd3689aecd3cf7de48648367ca205f63daf4d9f 100644 (file)
@@ -435,7 +435,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
        vol->eba_tbl = NULL;
        cdev_del(&vol->cdev);
        volume_sysfs_close(vol);
-       kfree(desc);
 
        spin_lock(&ubi->volumes_lock);
        ubi->rsvd_pebs -= reserved_pebs;
@@ -453,10 +452,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
        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;