Skip to contentSkip to conversation

Staging: most: Use module_platform_driver

PATCH In review Shraddha Barke 3 participants 4 messages Oct 3, 2015 – Oct 5, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: most: Use module_platform_driver

Use module_platform_driver for drivers whose init and exit functions only register and unregister, respectively. Thus remove some boilerplate code.

A simplified version of Coccinelle patch -

@a@
identifier f, x;
@@
-static f(...) { return platform_driver_register(&x); } @b depends on a@
identifier e, a.x;
@@
-static e(...) { platform_driver_unregister(&x); } @c depends on a && b@
identifier a.f;
declarer name module_init;
@@
-module_init(f);

@d depends on a && b && c@
identifier b.e, a.x;
declarer name module_exit;
declarer name module_platform_driver;
@@
-module_exit(e);
+module_platform_driver(x);

---
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/staging/most/hdm-dim2/dim2_hdm.c +1 -20
index 1bb70b7..c7e956f 100644
@@ -926,26 +926,7 @@ static struct platform_driver dim2_driver = {
 	},
 };
 
-/**
- * dim2_hdm_init - Driver Registration Routine
- */
-static int __init dim2_hdm_init(void)
-{
-	pr_info("dim2_hdm_init()\n");
-	return platform_driver_register(&dim2_driver);
-}
-
-/**
- * dim2_hdm_exit - Driver Cleanup Routine
- **/
-static void __exit dim2_hdm_exit(void)
-{
-	pr_info("dim2_hdm_exit()\n");
-	platform_driver_unregister(&dim2_driver);
-}
-
-module_init(dim2_hdm_init);
-module_exit(dim2_hdm_exit);
+module_platform_driver(dim2_driver);
 
 MODULE_AUTHOR("Jain Roy Ambi <[email protected]>");
 MODULE_AUTHOR("Andrey Shvetsov <[email protected]>");
Signature · 1 line
2.1.4
#1 lore raw

drivers/staging/most/hdm-dim2/dim2_hdm.c static struct platform_driver dim2_driver = { · line 937

Quoted 11 lines · On Saturday 03 October 2015 17:31:30 Shraddha Barke wrote:
drivers/staging/most/hdm-dim2/dim2_hdm.c +0 -9
-/**
- * dim2_hdm_init - Driver Registration Routine
- */
-static int __init dim2_hdm_init(void)
-{
-       pr_info("dim2_hdm_init()\n");
-       return platform_driver_register(&dim2_driver);
-}
-

Your changelog does not mention that you are removing the pr_info() lines in the process of the conversion.

Removing those lines is a good idea, but that should better be done as a separate patch upfront, possibly removing other debug statements from the same driver as well.

Arnd

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 17 lines · On Sunday 04 October 2015 20:41:44 Greg KH wrote:
Quoted 16 lines · Arnd Bergmann

drivers/staging/most/hdm-dim2/dim2_hdm.c static struct platform_driver dim2_driver = { · line 937

Quoted 11 lines · On Saturday 03 October 2015 17:31:30 Shraddha Barke wrote:
drivers/staging/most/hdm-dim2/dim2_hdm.c +0 -9
-/**
- * dim2_hdm_init - Driver Registration Routine
- */
-static int __init dim2_hdm_init(void)
-{
-       pr_info("dim2_hdm_init()\n");
-       return platform_driver_register(&dim2_driver);
-}
-

Your changelog does not mention that you are removing the pr_info() lines in the process of the conversion.

Quoted 8 lines
Quoted 3 lines

Removing those lines is a good idea, but that should better be done as a separate patch upfront, possibly removing other debug statements from the same driver as well.

No, this is how we converted all of the other drivers to this api a long time ago, no need to break it up into 2 patches. This is also one of the main reasons to use this api, to keep things "quiet".

Ok, fair enough. It's probably worth mentioning that in the changelog though.

Arnd

maintainer
#4 lore raw
Quoted 22 lines · Arnd Bergmann
Quoted 21 lines · On Sunday 04 October 2015 20:41:44 Greg KH wrote:
Quoted 19 lines · Arnd Bergmann

drivers/staging/most/hdm-dim2/dim2_hdm.c static struct platform_driver dim2_driver = { · line 937

Quoted 11 lines · On Saturday 03 October 2015 17:31:30 Shraddha Barke wrote:
drivers/staging/most/hdm-dim2/dim2_hdm.c +0 -9
-/**
- * dim2_hdm_init - Driver Registration Routine
- */
-static int __init dim2_hdm_init(void)
-{
-       pr_info("dim2_hdm_init()\n");
-       return platform_driver_register(&dim2_driver);
-}
-

Your changelog does not mention that you are removing the pr_info() lines in the process of the conversion.

Removing those lines is a good idea, but that should better be done as a separate patch upfront, possibly removing other debug statements from the same driver as well.

Quoted 6 lines
Quoted 4 lines

No, this is how we converted all of the other drivers to this api a long time ago, no need to break it up into 2 patches. This is also one of the main reasons to use this api, to keep things "quiet".

Ok, fair enough. It's probably worth mentioning that in the changelog though.

I don't think I ever did that when I converted drivers to this api, so I wouldn't expect a new developer to do something I wasn't willing to do :)

thanks,

greg k-h