Skip to contentSkip to conversation

watchdog: acquirewdt: 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: acquirewdt: 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/acquirewdt.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/watchdog/acquirewdt.c +9 -12
@@ -239,7 +239,7 @@ static struct miscdevice acq_miscdev = {
  *	Init & exit routines
  */
 
-static int acq_probe(struct platform_device *dev)
+static int __init acq_probe(struct platform_device *dev)
 {
 	int ret;
 
@@ -291,7 +291,6 @@ static void acq_shutdown(struct platform
 }
 
 static struct platform_driver acquirewdt_driver = {
-	.probe		= acq_probe,
 	.remove		= acq_remove,
 	.shutdown	= acq_shutdown,
 	.driver		= {
@@ -306,20 +305,18 @@ static int __init acq_init(void)
 
 	pr_info("WDT driver for Acquire single board computer initialising\n");
 
-	err = platform_driver_register(&acquirewdt_driver);
-	if (err)
-		return err;
-
 	acq_platform_device = platform_device_register_simple(DRV_NAME,
 								-1, NULL, 0);
-	if (IS_ERR(acq_platform_device)) {
-		err = PTR_ERR(acq_platform_device);
-		goto unreg_platform_driver;
-	}
+	if (IS_ERR(acq_platform_device))
+		return PTR_ERR(acq_platform_device);
+
+	err = platform_driver_probe(&acquirewdt_driver, acq_probe);
+	if (err)
+		goto unreg_platform_device;
 	return 0;
 
-unreg_platform_driver:
-	platform_driver_unregister(&acquirewdt_driver);
+unreg_platform_device:
+	platform_device_unregister(acq_platform_device);
 	return err;
 }
 
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#2 lore raw
In reply to Jean Delvare

Hi Jean,

Quoted 51 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/acquirewdt.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/watchdog/acquirewdt.c +6 -10
@@ -239,7 +239,7 @@ static struct miscdevice acq_miscdev = {
  *	Init & exit routines
  */
 
-static int acq_probe(struct platform_device *dev)
+static int __init acq_probe(struct platform_device *dev)
 {
 	int ret;
 
@@ -291,7 +291,6 @@ static void acq_shutdown(struct platform
 }
 
 static struct platform_driver acquirewdt_driver = {
-	.probe		= acq_probe,
 	.remove		= acq_remove,
 	.shutdown	= acq_shutdown,
 	.driver		= {
@@ -306,20 +305,18 @@ static int __init acq_init(void)
 
 	pr_info("WDT driver for Acquire single board computer initialising\n");
 
-	err = platform_driver_register(&acquirewdt_driver);
-	if (err)
-		return err;
-
 	acq_platform_device = platform_device_register_simple(DRV_NAME,
 								-1, NULL, 0);
-	if (IS_ERR(acq_platform_device)) {
-		err = PTR_ERR(acq_platform_device);
-		goto unreg_platform_driver;
-	}
+	if (IS_ERR(acq_platform_device))
+		return PTR_ERR(acq_platform_device);
+
+	err = platform_driver_probe(&acquirewdt_driver, acq_probe);
+	if (err)

drivers/watchdog/acquirewdt.c static int __init acq_init(void) · line 322

Quoted 10 lines
drivers/watchdog/acquirewdt.c +3 -2
+		goto unreg_platform_device;
 	return 0;
 
-unreg_platform_driver:
-	platform_driver_unregister(&acquirewdt_driver);
+unreg_platform_device:
+	platform_device_unregister(acq_platform_device);
 	return err;
 }
 

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.