Skip to contentSkip to conversation

watchdog: ib700wdt: Use platform_driver_probe

PATCH In review Jean Delvare 3 participants 3 messages Mar 14, 2014 – Mar 15, 2014 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: ib700wdt: Use platform_driver_probe

Using platform_driver_probe instead of platform_driver_register has two benefits:
* The driver will fail to load if device probing fails.
* The probe function can be marked __init.

Cc Wim Van Sebroeck <[email protected]>
---
 drivers/watchdog/ib700wdt.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/watchdog/ib700wdt.c +9 -12
@@ -277,7 +277,7 @@ static struct miscdevice ibwdt_miscdev =
  *	Init & exit routines
  */
 
-static int ibwdt_probe(struct platform_device *dev)
+static int __init ibwdt_probe(struct platform_device *dev)
 {
 	int res;
 
@@ -336,7 +336,6 @@ static void ibwdt_shutdown(struct platfo
 }
 
 static struct platform_driver ibwdt_driver = {
-	.probe		= ibwdt_probe,
 	.remove		= ibwdt_remove,
 	.shutdown	= ibwdt_shutdown,
 	.driver		= {
@@ -351,21 +350,19 @@ static int __init ibwdt_init(void)
 
 	pr_info("WDT driver for IB700 single board computer initialising\n");
 
-	err = platform_driver_register(&ibwdt_driver);
-	if (err)
-		return err;
-
 	ibwdt_platform_device = platform_device_register_simple(DRV_NAME,
 								-1, NULL, 0);
-	if (IS_ERR(ibwdt_platform_device)) {
-		err = PTR_ERR(ibwdt_platform_device);
-		goto unreg_platform_driver;
-	}
+	if (IS_ERR(ibwdt_platform_device))
+		return PTR_ERR(ibwdt_platform_device);
+
+	err = platform_driver_probe(&ibwdt_driver, ibwdt_probe);
+	if (err)
+		goto unreg_platform_device;
 
 	return 0;
 
-unreg_platform_driver:
-	platform_driver_unregister(&ibwdt_driver);
+unreg_platform_device:
+	platform_device_unregister(ibwdt_platform_device);
 	return err;
 }
 
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#2 lore raw
In reply to Jean Delvare

Hi Jean,

Quoted 52 lines

Using platform_driver_probe instead of platform_driver_register has two benefits:
* The driver will fail to load if device probing fails.
* The probe function can be marked __init.

Cc Wim Van Sebroeck <[email protected]>
---
 drivers/watchdog/ib700wdt.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/watchdog/ib700wdt.c +7 -10
@@ -277,7 +277,7 @@ static struct miscdevice ibwdt_miscdev =
  *	Init & exit routines
  */
 
-static int ibwdt_probe(struct platform_device *dev)
+static int __init ibwdt_probe(struct platform_device *dev)
 {
 	int res;
 
@@ -336,7 +336,6 @@ static void ibwdt_shutdown(struct platfo
 }
 
 static struct platform_driver ibwdt_driver = {
-	.probe		= ibwdt_probe,
 	.remove		= ibwdt_remove,
 	.shutdown	= ibwdt_shutdown,
 	.driver		= {
@@ -351,21 +350,19 @@ static int __init ibwdt_init(void)
 
 	pr_info("WDT driver for IB700 single board computer initialising\n");
 
-	err = platform_driver_register(&ibwdt_driver);
-	if (err)
-		return err;
-
 	ibwdt_platform_device = platform_device_register_simple(DRV_NAME,
 								-1, NULL, 0);
-	if (IS_ERR(ibwdt_platform_device)) {
-		err = PTR_ERR(ibwdt_platform_device);
-		goto unreg_platform_driver;
-	}
+	if (IS_ERR(ibwdt_platform_device))
+		return PTR_ERR(ibwdt_platform_device);
+
+	err = platform_driver_probe(&ibwdt_driver, ibwdt_probe);
+	if (err)
+		goto unreg_platform_device;

drivers/watchdog/ib700wdt.c static int __init ibwdt_init(void) · line 368

Quoted 10 lines
drivers/watchdog/ib700wdt.c +2 -2
 
 	return 0;
 
-unreg_platform_driver:
-	platform_driver_unregister(&ibwdt_driver);
+unreg_platform_device:
+	platform_device_unregister(ibwdt_platform_device);
 	return err;
 }
 

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.