aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-01-20 11:04:09 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-01-20 11:13:53 -0500
commit36b477d005fbda29e7581c3cef7ee31a59d8970b (patch)
treecacdcc1b18bfce9f627a87c115d4c6192a626b8b /drivers/mtd/ubi
parent8c4c19f1367435afdc16ac122a2a95a4d6cff9f0 (diff)
UBI: fix resource de-allocation
GregKH asked to fix UBI which has fake device release method. Indeed, we have to free UBI device description object from the release method, because otherwise we'll oops is someone opens a UBI device sysfs file, then the device is removed, and he reads the file. With this fix, he will get -ENODEV instead of an oops. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/build.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 09a326ecd05b..4048db83aef6 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -263,8 +263,12 @@ static ssize_t dev_attribute_show(struct device *dev,
263 return ret; 263 return ret;
264} 264}
265 265
266/* Fake "release" method for UBI devices */ 266static void dev_release(struct device *dev)
267static void dev_release(struct device *dev) { } 267{
268 struct ubi_device *ubi = container_of(dev, struct ubi_device, dev);
269
270 kfree(ubi);
271}
268 272
269/** 273/**
270 * ubi_sysfs_init - initialize sysfs for an UBI device. 274 * ubi_sysfs_init - initialize sysfs for an UBI device.
@@ -944,6 +948,12 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
944 if (ubi->bgt_thread) 948 if (ubi->bgt_thread)
945 kthread_stop(ubi->bgt_thread); 949 kthread_stop(ubi->bgt_thread);
946 950
951 /*
952 * Get a reference to the device in order to prevent 'dev_release()'
953 * from freeing @ubi object.
954 */
955 get_device(&ubi->dev);
956
947 uif_close(ubi); 957 uif_close(ubi);
948 ubi_wl_close(ubi); 958 ubi_wl_close(ubi);
949 free_internal_volumes(ubi); 959 free_internal_volumes(ubi);
@@ -955,7 +965,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
955 vfree(ubi->dbg_peb_buf); 965 vfree(ubi->dbg_peb_buf);
956#endif 966#endif
957 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); 967 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
958 kfree(ubi); 968 put_device(&ubi->dev);
959 return 0; 969 return 0;
960} 970}
961 971