Linux Watchdog driver development
 help / color / mirror / Atom feed
* [PATCH] watchdog: ib700wdt: Use platform_driver_probe
@ 2014-03-14 12:18 Jean Delvare
  2014-03-14 18:00 ` Guenter Roeck
  2014-03-15 19:54 ` Wim Van Sebroeck
  0 siblings, 2 replies; 3+ messages in thread
From: Jean Delvare @ 2014-03-14 12:18 UTC (permalink / raw)
  To: linux-watchdog; +Cc: Wim Van Sebroeck

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.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Cc: Wim Van Sebroeck <wim@iguana.be>
---
 drivers/watchdog/ib700wdt.c |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

--- linux-3.14-rc6.orig/drivers/watchdog/ib700wdt.c	2014-01-20 03:40:07.000000000 +0100
+++ linux-3.14-rc6/drivers/watchdog/ib700wdt.c	2014-03-13 15:31:38.097211632 +0100
@@ -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;
 }
 


-- 
Jean Delvare
SUSE L3 Support

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] watchdog: ib700wdt: Use platform_driver_probe
  2014-03-14 12:18 [PATCH] watchdog: ib700wdt: Use platform_driver_probe Jean Delvare
@ 2014-03-14 18:00 ` Guenter Roeck
  2014-03-15 19:54 ` Wim Van Sebroeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2014-03-14 18:00 UTC (permalink / raw)
  To: Jean Delvare; +Cc: linux-watchdog, Wim Van Sebroeck

On Fri, Mar 14, 2014 at 01:18:47PM +0100, Jean Delvare wrote:
> 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.
> 
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
> Cc: Wim Van Sebroeck <wim@iguana.be>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] watchdog: ib700wdt: Use platform_driver_probe
  2014-03-14 12:18 [PATCH] watchdog: ib700wdt: Use platform_driver_probe Jean Delvare
  2014-03-14 18:00 ` Guenter Roeck
@ 2014-03-15 19:54 ` Wim Van Sebroeck
  1 sibling, 0 replies; 3+ messages in thread
From: Wim Van Sebroeck @ 2014-03-15 19:54 UTC (permalink / raw)
  To: Jean Delvare; +Cc: linux-watchdog

Hi Jean,

> 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.
> 
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
> Cc: Wim Van Sebroeck <wim@iguana.be>
> ---
>  drivers/watchdog/ib700wdt.c |   21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
> 
> --- linux-3.14-rc6.orig/drivers/watchdog/ib700wdt.c	2014-01-20 03:40:07.000000000 +0100
> +++ linux-3.14-rc6/drivers/watchdog/ib700wdt.c	2014-03-13 15:31:38.097211632 +0100
> @@ -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;
>  }
>  
> 
> 

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-15 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-14 12:18 [PATCH] watchdog: ib700wdt: Use platform_driver_probe Jean Delvare
2014-03-14 18:00 ` Guenter Roeck
2014-03-15 19:54 ` Wim Van Sebroeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox