Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=7799308f34d3c3371a319559687c78c0f2506fcf
Commit:     7799308f34d3c3371a319559687c78c0f2506fcf
Parent:     29072b96078ffde36f03d51e6b5d0cff1ba8c7df
Author:     Artem Bityutskiy <[EMAIL PROTECTED]>
AuthorDate: Wed Oct 11 14:52:44 2006 +0300
Committer:  Artem Bityutskiy <[EMAIL PROTECTED]>
CommitDate: Wed Nov 29 17:04:31 2006 +0200

    [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 <[EMAIL PROTECTED]>
---
 drivers/mtd/mtdcore.c   |   38 ++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/mtd.h |    1 +
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c4d26de..06ec9f8 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -15,6 +15,7 @@
 #include <linux/timer.h>
 #include <linux/major.h>
 #include <linux/fs.h>
+#include <linux/err.h>
 #include <linux/ioctl.h>
 #include <linux/init.h>
 #include <linux/mtd/compatmac.h>
@@ -223,6 +224,42 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int 
num)
        return ret;
 }
 
+/**
+ *     get_mtd_device_nm - obtain a validated handle for an MTD device by
+ *     device name
+ *     @name: MTD device name to open
+ *
+ *     This function returns MTD device description structure in case of
+ *     success and an error code in case of failure.
+ */
+
+struct mtd_info *get_mtd_device_nm(const char *name)
+{
+       int i;
+       struct mtd_info *mtd = ERR_PTR(-ENODEV);
+
+       mutex_lock(&mtd_table_mutex);
+
+       for (i = 0; i < MAX_MTD_DEVICES; i++) {
+               if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) {
+                       mtd = mtd_table[i];
+                       break;
+               }
+       }
+
+       if (i == MAX_MTD_DEVICES)
+               goto out_unlock;
+
+       if (!try_module_get(mtd->owner))
+               goto out_unlock;
+
+       mtd->usecount++;
+
+out_unlock:
+       mutex_unlock(&mtd_table_mutex);
+       return mtd;
+}
+
 void put_mtd_device(struct mtd_info *mtd)
 {
        int c;
@@ -267,6 +304,7 @@ int default_mtd_writev(struct mtd_info *mtd, const struct 
kvec *vecs,
 EXPORT_SYMBOL(add_mtd_device);
 EXPORT_SYMBOL(del_mtd_device);
 EXPORT_SYMBOL(get_mtd_device);
+EXPORT_SYMBOL(get_mtd_device_nm);
 EXPORT_SYMBOL(put_mtd_device);
 EXPORT_SYMBOL(register_mtd_user);
 EXPORT_SYMBOL(unregister_mtd_user);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 18acb6d..89e937d 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);
 extern int del_mtd_device (struct mtd_info *mtd);
 
 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
+extern struct mtd_info *get_mtd_device_nm(const char *name);
 
 extern void put_mtd_device(struct mtd_info *mtd);
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to