From: Lars-Peter Clausen <lars@metafoo.de>
To: Greg Kroah-Hartman <gregkh@suse.de>,
Jean Delvare <khali@linux-fr.org>,
Grant Likely <grant.likely@secretlab.ca>
Cc: Jonathan Cameron <jic23@kernel.org>,
Michael Hennerich <Michael.Hennerich@analog.com>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-i2c@vger.kernel.org>,
<spi-devel-general@lists.sourceforge.net>,
Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 1/5] drivercore: Generalize module_platform_driver
Date: Wed, 16 Nov 2011 10:13:35 +0100 [thread overview]
Message-ID: <1321434819-23678-2-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1321434819-23678-1-git-send-email-lars@metafoo.de>
This patch generalizes the module_platform_driver macro and introduces a new
module_driver macro. The module_driver macro takes a driver name, a register
and a unregister function for this driver type. Using these it construct the
module init and exit sections which register and unregister the driver. Since
such init/exit sections are commonly found in drivers this macro can be used
to eliminate a lot of boilerplate code.
The macro is not intended to be used by driver modules directly, instead it
should be used to generate bus specific macros for registering drivers like
the module_platform_driver macro.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
include/linux/init.h | 21 +++++++++++++++++++++
include/linux/platform_device.h | 12 ++----------
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/include/linux/init.h b/include/linux/init.h
index 9146f39..3e2d238 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -346,4 +346,25 @@ void __init parse_early_options(char *cmdline);
#define __exit_p(x) NULL
#endif
+/**
+ * module_driver() - Helper macro for drivers that don't do anything
+ * special in module init/exit. This eliminates a lot of boilerplate.
+ * Each module may only use this macro once, and calling it replaces
+ * module_init() and module_exit().
+ * Use this macro to construct bus specific macros for registering
+ * drivers.
+ */
+#define module_driver(__driver, __register, __unregister) \
+static int __init __driver##_init(void) \
+{ \
+ return __register(&(__driver)); \
+} \
+module_init(__driver##_init); \
+static void __exit __driver##_exit(void) \
+{ \
+ __unregister(&(__driver)); \
+} \
+module_exit(__driver##_exit);
+
#endif /* _LINUX_INIT_H */
+
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 2a23f7d..165a8d1 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -196,16 +196,8 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data
* calling it replaces module_init() and module_exit()
*/
#define module_platform_driver(__platform_driver) \
-static int __init __platform_driver##_init(void) \
-{ \
- return platform_driver_register(&(__platform_driver)); \
-} \
-module_init(__platform_driver##_init); \
-static void __exit __platform_driver##_exit(void) \
-{ \
- platform_driver_unregister(&(__platform_driver)); \
-} \
-module_exit(__platform_driver##_exit);
+ module_driver(__platform_driver, platform_driver_register, \
+ platform_driver_unregister)
extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
int (*probe)(struct platform_device *),
--
1.7.7.1
next prev parent reply other threads:[~2011-11-16 9:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 9:13 [PATCH 0/5] Generalize module_platform_driver Lars-Peter Clausen
2011-11-16 9:13 ` Lars-Peter Clausen [this message]
[not found] ` <1321434819-23678-2-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-16 17:11 ` [PATCH 1/5] drivercore: " Grant Likely
[not found] ` <CACxGe6twCU9Nb+b00ei83jxaz0YnVa6nT0ra6Kp0c4PO7hjT6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-17 6:51 ` Jonathan Cameron
2011-11-17 20:04 ` Greg KH
2012-01-13 9:07 ` Guennadi Liakhovetski
2012-01-13 18:23 ` Greg KH
2011-11-16 9:13 ` [PATCH 2/5] I2C: Add helper macro for i2c_driver boilerplate Lars-Peter Clausen
[not found] ` <1321434819-23678-3-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-16 17:12 ` Grant Likely
[not found] ` <CACxGe6toOFjOdP7-oZ4O2J=g2U+Y+aWOUzHDoCaX6goAs6zKsQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-17 6:47 ` Jonathan Cameron
2011-11-16 9:13 ` [PATCH 3/5] SPI: Add helper macro for spi_driver boilerplate Lars-Peter Clausen
[not found] ` <1321434819-23678-4-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-16 17:12 ` Grant Likely
[not found] ` <CACxGe6tz0ppZj=a_e4rkgNxzhQ4MSCtXKXGk_dPov80QDU4MCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-24 0:13 ` Ben Dooks
[not found] ` <20111124001342.GN19115-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2011-11-24 7:29 ` Lars-Peter Clausen
2011-11-16 9:13 ` [PATCH 4/5] staging:iio: Use module_i2c_driver to register I2C drivers Lars-Peter Clausen
[not found] ` <1321434819-23678-5-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-17 6:50 ` Jonathan Cameron
[not found] ` <1321434819-23678-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-16 9:13 ` [PATCH 5/5] staging:iio: Use module_spi_driver to register SPI driver Lars-Peter Clausen
2011-11-16 17:15 ` Grant Likely
[not found] ` <CACxGe6su+18Ct6E7z8VfbXcOwftxMm49A9Q49Eat8+StT17F4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-17 6:48 ` Jonathan Cameron
[not found] ` <1321434819-23678-6-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2011-11-17 6:49 ` Jonathan Cameron
2011-11-16 16:02 ` [PATCH 0/5] Generalize module_platform_driver Greg KH
2011-11-16 16:36 ` Jean Delvare
2011-11-16 16:37 ` Greg KH
[not found] ` <20111116163728.GA7196-l3A5Bk7waGM@public.gmane.org>
2011-11-16 17:13 ` Grant Likely
[not found] ` <CACxGe6sMJN6ZuF2E5vtbf-jquJRUPizzo_Ttdy1UkwtMO4axUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-17 19:49 ` Greg KH
2011-11-16 20:14 ` Wolfram Sang
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=1321434819-23678-2-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=Michael.Hennerich@analog.com \
--cc=grant.likely@secretlab.ca \
--cc=gregkh@suse.de \
--cc=jic23@kernel.org \
--cc=khali@linux-fr.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=spi-devel-general@lists.sourceforge.net \
/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).