aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <dedekind@infradead.org>2006-10-11 07:52:44 -0400
committerArtem Bityutskiy <dedekind@infradead.org>2006-11-29 10:04:31 -0500
commit7799308f34d3c3371a319559687c78c0f2506fcf (patch)
tree2e4f48326e848060aa8ffe104887a8d1d5bb1759
parent29072b96078ffde36f03d51e6b5d0cff1ba8c7df (diff)
[MTD] add get_mtd_device_nm() function
This patch adds one more function to the MTD interface to make it possible to open MTD devices by their names, not only numbers. This is very handy in many situations. Also, MTD device number depend on load order and may vary, while names are fixed. Signed-off-by: Artem Bityutskiy <dedekind@infradead.org>
-rw-r--r--drivers/mtd/mtdcore.c38
-rw-r--r--include/linux/mtd/mtd.h1
2 files changed, 39 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c4d26de74349..06ec9f836ae5 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -15,6 +15,7 @@
15#include <linux/timer.h> 15#include <linux/timer.h>
16#include <linux/major.h> 16#include <linux/major.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/err.h>
18#include <linux/ioctl.h> 19#include <linux/ioctl.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/mtd/compatmac.h> 21#include <linux/mtd/compatmac.h>
@@ -223,6 +224,42 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
223 return ret; 224 return ret;
224} 225}
225 226
227/**
228 * get_mtd_device_nm - obtain a validated handle for an MTD device by
229 * device name
230 * @name: MTD device name to open
231 *
232 * This function returns MTD device description structure in case of
233 * success and an error code in case of failure.
234 */
235
236struct mtd_info *get_mtd_device_nm(const char *name)
237{
238 int i;
239 struct mtd_info *mtd = ERR_PTR(-ENODEV);
240
241 mutex_lock(&mtd_table_mutex);
242
243 for (i = 0; i < MAX_MTD_DEVICES; i++) {
244 if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) {
245 mtd = mtd_table[i];
246 break;
247 }
248 }
249
250 if (i == MAX_MTD_DEVICES)
251 goto out_unlock;
252
253 if (!try_module_get(mtd->owner))
254 goto out_unlock;
255
256 mtd->usecount++;
257
258out_unlock:
259 mutex_unlock(&mtd_table_mutex);
260 return mtd;
261}
262
226void put_mtd_device(struct mtd_info *mtd) 263void put_mtd_device(struct mtd_info *mtd)
227{ 264{
228 int c; 265 int c;
@@ -267,6 +304,7 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
267EXPORT_SYMBOL(add_mtd_device); 304EXPORT_SYMBOL(add_mtd_device);
268EXPORT_SYMBOL(del_mtd_device); 305EXPORT_SYMBOL(del_mtd_device);
269EXPORT_SYMBOL(get_mtd_device); 306EXPORT_SYMBOL(get_mtd_device);
307EXPORT_SYMBOL(get_mtd_device_nm);
270EXPORT_SYMBOL(put_mtd_device); 308EXPORT_SYMBOL(put_mtd_device);
271EXPORT_SYMBOL(register_mtd_user); 309EXPORT_SYMBOL(register_mtd_user);
272EXPORT_SYMBOL(unregister_mtd_user); 310EXPORT_SYMBOL(unregister_mtd_user);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 18acb6d0033b..89e937dfef55 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -216,6 +216,7 @@ extern int add_mtd_device(struct mtd_info *mtd);
216extern int del_mtd_device (struct mtd_info *mtd); 216extern int del_mtd_device (struct mtd_info *mtd);
217 217
218extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); 218extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
219extern struct mtd_info *get_mtd_device_nm(const char *name);
219 220
220extern void put_mtd_device(struct mtd_info *mtd); 221extern void put_mtd_device(struct mtd_info *mtd);
221 222