From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: "Rafał Miłecki" <zajec5@gmail.com>,
"Brian Norris" <computersforpeace@gmail.com>
Subject: [PATCH 1/2] mtd: partitions: add module_mtd_part_parser() helper
Date: Wed, 11 Nov 2015 19:13:29 -0800 [thread overview]
Message-ID: <1447298010-7756-1-git-send-email-computersforpeace@gmail.com> (raw)
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@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 3ace53342fd2..aaa08428cf93 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -704,13 +704,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 34388ced421a..75def3067d71 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -74,9 +74,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);
--
2.6.0.rc2.230.g3dd15c0
next reply other threads:[~2015-11-12 3:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-12 3:13 Brian Norris [this message]
2015-11-12 3:13 ` [PATCH 2/2] mtd: kill off MTD partition parser boilerplate Brian Norris
2015-11-20 2:47 ` [PATCH 1/2] mtd: partitions: add module_mtd_part_parser() helper Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447298010-7756-1-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=zajec5@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).