mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fabio Porcedda <fabio.porcedda@gmail.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-watchdog@vger.kernel.org, linux-usb@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 1/3] driver core: add helper macro for platform_driver_probe() boilerplate
Date: Wed,  9 Jan 2013 12:15:26 +0100	[thread overview]
Message-ID: <1357730128-23018-2-git-send-email-fabio.porcedda@gmail.com> (raw)
In-Reply-To: <1357730128-23018-1-git-send-email-fabio.porcedda@gmail.com>

For simple modules that contain a single platform_driver without any
additional setup code then ends up being a block of duplicated
boilerplate.  This patch adds a new macro,
module_platform_driver_probe(), which replaces the
module_init()/module_exit() registrations with template functions.

This macro use the same idea of module_platform_driver().

This macro is useful to stop the misuse of module_platform_driver() for
removing the platform_driver_probe() boilerplate.

Signed-off-by: Fabio Porcedda <fabio.porcedda@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
---
 include/linux/platform_device.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index a9ded9a..c082c71 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -204,6 +204,24 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data
 	module_driver(__platform_driver, platform_driver_register, \
 			platform_driver_unregister)
 
+/* module_platform_driver_probe() - 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()
+ */
+#define module_platform_driver_probe(__platform_driver, __platform_probe) \
+static int __init __platform_driver##_init(void) \
+{ \
+	return platform_driver_probe(&(__platform_driver), \
+				     __platform_probe);    \
+} \
+module_init(__platform_driver##_init); \
+static void __exit __platform_driver##_exit(void) \
+{ \
+	platform_driver_unregister(&(__platform_driver)); \
+} \
+module_exit(__platform_driver##_exit);
+
 extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
 					int (*probe)(struct platform_device *),
 					struct resource *res, unsigned int n_res,
-- 
1.8.0.3


  reply	other threads:[~2013-01-09 11:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09 11:15 [PATCH 0/3] Add and use new macro module_platform_driver_probe() Fabio Porcedda
2013-01-09 11:15 ` Fabio Porcedda [this message]
2013-01-10 12:50   ` [PATCH 1/3] driver core: add helper macro for platform_driver_probe() boilerplate Fabio Porcedda
2013-01-09 11:15 ` [PATCH 2/3] watchdog: convert drivers/watchdog/* to use module_platform_driver_probe Fabio Porcedda
2013-01-09 11:15 ` [PATCH 3/3] usb: converto drivers/usb/* to use module_platform_driver_probe() Fabio Porcedda

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=1357730128-23018-2-git-send-email-fabio.porcedda@gmail.com \
    --to=fabio.porcedda@gmail.com \
    --cc=gregkh@suse.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®