mtd: partitions: add module_mtd_part_parser() helper

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 12 15:59:09 PST 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=b9eab01125bf3cb6f5fbab1811402d16c9fcf4ec
Commit:     b9eab01125bf3cb6f5fbab1811402d16c9fcf4ec
Parent:     1d158315c13b6989f7ddb1d8d334965d14d958d8
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Wed Nov 11 19:13:29 2015 -0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Thu Nov 19 18:46:28 2015 -0800

    mtd: partitions: add module_mtd_part_parser() helper
    
    This can help eliminate some boilerplate by generating the module_init()
    and module_exit() functions, and by automatically assigning the module
    owner.
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/mtdpart.c          |  8 ++++++--
 include/linux/mtd/partitions.h | 14 +++++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 46dfbf5..1fa3ca9 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -703,13 +703,17 @@ static struct mtd_part_parser *get_partition_parser(const char *name)
 
 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
 
-void register_mtd_parser(struct mtd_part_parser *p)
+int __register_mtd_parser(struct mtd_part_parser *p, struct module *owner)
 {
+	p->owner = owner;
+
 	spin_lock(&part_parser_lock);
 	list_add(&p->list, &part_parsers);
 	spin_unlock(&part_parser_lock);
+
+	return 0;
 }
-EXPORT_SYMBOL_GPL(register_mtd_parser);
+EXPORT_SYMBOL_GPL(__register_mtd_parser);
 
 void deregister_mtd_parser(struct mtd_part_parser *p)
 {
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 8421520..d002d9b 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -73,9 +73,21 @@ struct mtd_part_parser {
 			struct mtd_part_parser_data *);
 };
 
-extern void register_mtd_parser(struct mtd_part_parser *parser);
+extern int __register_mtd_parser(struct mtd_part_parser *parser,
+				 struct module *owner);
+#define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE)
+
 extern void deregister_mtd_parser(struct mtd_part_parser *parser);
 
+/*
+ * module_mtd_part_parser() - Helper macro for MTD partition parsers that don't
+ * do anything special in module init/exit. Each driver may only use this macro
+ * once, and calling it replaces module_init() and module_exit().
+ */
+#define module_mtd_part_parser(__mtd_part_parser) \
+	module_driver(__mtd_part_parser, register_mtd_parser, \
+		      deregister_mtd_parser)
+
 int mtd_is_partition(const struct mtd_info *mtd);
 int mtd_add_partition(struct mtd_info *master, const char *name,
 		      long long offset, long long length);



More information about the linux-mtd-cvs mailing list