diff options
author | Artem Bityutskiy <dedekind@infradead.org> | 2006-10-11 07:52:47 -0400 |
---|---|---|
committer | Artem Bityutskiy <dedekind@infradead.org> | 2006-11-29 10:06:38 -0500 |
commit | 9c74034f8fc5d93fbe5656421cbbdc4c76ddda28 (patch) | |
tree | e5a205e124c0e42899743d765598f82a228156c2 /drivers | |
parent | 9fe912cea32aec18f860c95e8574410b5892481b (diff) |
[MTD] return error code from get_mtd_device()
get_mtd_device() returns NULL in case of any failure. Teach it to return an
error code instead. Fix all users as well.
Signed-off-by: Artem Bityutskiy <dedekind@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/maps/nettel.c | 3 | ||||
-rw-r--r-- | drivers/mtd/mtdchar.c | 5 | ||||
-rw-r--r-- | drivers/mtd/mtdcore.c | 24 |
3 files changed, 18 insertions, 14 deletions
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c index f9e8e5bcbc33..528e523245c2 100644 --- a/drivers/mtd/maps/nettel.c +++ b/drivers/mtd/maps/nettel.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/mtd/partitions.h> | 20 | #include <linux/mtd/partitions.h> |
21 | #include <linux/mtd/cfi.h> | 21 | #include <linux/mtd/cfi.h> |
22 | #include <linux/reboot.h> | 22 | #include <linux/reboot.h> |
23 | #include <linux/err.h> | ||
23 | #include <linux/kdev_t.h> | 24 | #include <linux/kdev_t.h> |
24 | #include <linux/root_dev.h> | 25 | #include <linux/root_dev.h> |
25 | #include <asm/io.h> | 26 | #include <asm/io.h> |
@@ -178,7 +179,7 @@ int nettel_eraseconfig(void) | |||
178 | 179 | ||
179 | init_waitqueue_head(&wait_q); | 180 | init_waitqueue_head(&wait_q); |
180 | mtd = get_mtd_device(NULL, 2); | 181 | mtd = get_mtd_device(NULL, 2); |
181 | if (mtd) { | 182 | if (!IS_ERR(mtd)) { |
182 | nettel_erase.mtd = mtd; | 183 | nettel_erase.mtd = mtd; |
183 | nettel_erase.callback = nettel_erasecallback; | 184 | nettel_erase.callback = nettel_erasecallback; |
184 | nettel_erase.callback = NULL; | 185 | nettel_erase.callback = NULL; |
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 7c4adc641328..3013d0883b97 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include <linux/device.h> | 8 | #include <linux/device.h> |
9 | #include <linux/fs.h> | 9 | #include <linux/fs.h> |
10 | #include <linux/err.h> | ||
10 | #include <linux/init.h> | 11 | #include <linux/init.h> |
11 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -100,8 +101,8 @@ static int mtd_open(struct inode *inode, struct file *file) | |||
100 | 101 | ||
101 | mtd = get_mtd_device(NULL, devnum); | 102 | mtd = get_mtd_device(NULL, devnum); |
102 | 103 | ||
103 | if (!mtd) | 104 | if (IS_ERR(mtd)) |
104 | return -ENODEV; | 105 | return PTR_ERR(mtd); |
105 | 106 | ||
106 | if (MTD_ABSENT == mtd->type) { | 107 | if (MTD_ABSENT == mtd->type) { |
107 | put_mtd_device(mtd); | 108 | put_mtd_device(mtd); |
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index f11f55f02413..60f237f91bb2 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -193,14 +193,14 @@ int unregister_mtd_user (struct mtd_notifier *old) | |||
193 | * Given a number and NULL address, return the num'th entry in the device | 193 | * Given a number and NULL address, return the num'th entry in the device |
194 | * table, if any. Given an address and num == -1, search the device table | 194 | * table, if any. Given an address and num == -1, search the device table |
195 | * for a device with that address and return if it's still present. Given | 195 | * for a device with that address and return if it's still present. Given |
196 | * both, return the num'th driver only if its address matches. Return NULL | 196 | * both, return the num'th driver only if its address matches. Return |
197 | * if not. | 197 | * error code if not. |
198 | */ | 198 | */ |
199 | 199 | ||
200 | struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) | 200 | struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) |
201 | { | 201 | { |
202 | struct mtd_info *ret = NULL; | 202 | struct mtd_info *ret = NULL; |
203 | int i; | 203 | int i, err = -ENODEV; |
204 | 204 | ||
205 | mutex_lock(&mtd_table_mutex); | 205 | mutex_lock(&mtd_table_mutex); |
206 | 206 | ||
@@ -217,22 +217,24 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) | |||
217 | if (!ret) | 217 | if (!ret) |
218 | goto out_unlock; | 218 | goto out_unlock; |
219 | 219 | ||
220 | if (!try_module_get(ret->owner)) { | 220 | if (!try_module_get(ret->owner)) |
221 | ret = NULL; | ||
222 | goto out_unlock; | 221 | goto out_unlock; |
223 | } | ||
224 | 222 | ||
225 | if (ret->get_device && ret->get_device(ret)) { | 223 | if (ret->get_device) { |
226 | module_put(ret->owner); | 224 | err = ret->get_device(ret); |
227 | ret = NULL; | 225 | if (err) |
228 | goto out_unlock; | 226 | goto out_put; |
229 | } | 227 | } |
230 | 228 | ||
231 | ret->usecount++; | 229 | ret->usecount++; |
230 | mutex_unlock(&mtd_table_mutex); | ||
231 | return ret; | ||
232 | 232 | ||
233 | out_put: | ||
234 | module_put(ret->owner); | ||
233 | out_unlock: | 235 | out_unlock: |
234 | mutex_unlock(&mtd_table_mutex); | 236 | mutex_unlock(&mtd_table_mutex); |
235 | return ret; | 237 | return ERR_PTR(err); |
236 | } | 238 | } |
237 | 239 | ||
238 | /** | 240 | /** |