Linux Watchdog driver development
 help / color / mirror / Atom feed
* [PATCH] watchdog: geodewdt: Use platform_driver_probe
@ 2014-03-14 12:16 Jean Delvare
  2014-03-14 17:59 ` Guenter Roeck
  2014-03-15 19:53 ` Wim Van Sebroeck
  0 siblings, 2 replies; 3+ messages in thread
From: Jean Delvare @ 2014-03-14 12:16 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/geodewdt.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

--- linux-3.14-rc6.orig/drivers/watchdog/geodewdt.c	2014-01-20 03:40:07.000000000 +0100
+++ linux-3.14-rc6/drivers/watchdog/geodewdt.c	2014-03-14 10:41:42.415355724 +0100
@@ -215,7 +215,7 @@ static struct miscdevice geodewdt_miscde
 	.fops = &geodewdt_fops,
 };
 
-static int geodewdt_probe(struct platform_device *dev)
+static int __init geodewdt_probe(struct platform_device *dev)
 {
 	int ret;
 
@@ -255,7 +255,6 @@ static void geodewdt_shutdown(struct pla
 }
 
 static struct platform_driver geodewdt_driver = {
-	.probe		= geodewdt_probe,
 	.remove		= geodewdt_remove,
 	.shutdown	= geodewdt_shutdown,
 	.driver		= {
@@ -268,20 +267,18 @@ static int __init geodewdt_init(void)
 {
 	int ret;
 
-	ret = platform_driver_register(&geodewdt_driver);
-	if (ret)
-		return ret;
-
 	geodewdt_platform_device = platform_device_register_simple(DRV_NAME,
 								-1, NULL, 0);
-	if (IS_ERR(geodewdt_platform_device)) {
-		ret = PTR_ERR(geodewdt_platform_device);
+	if (IS_ERR(geodewdt_platform_device))
+		return PTR_ERR(geodewdt_platform_device);
+
+	ret = platform_driver_probe(&geodewdt_driver, geodewdt_probe);
+	if (ret)
 		goto err;
-	}
 
 	return 0;
 err:
-	platform_driver_unregister(&geodewdt_driver);
+	platform_device_unregister(geodewdt_platform_device);
 	return ret;
 }
 


-- 
Jean Delvare
SUSE L3 Support

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

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

On Fri, Mar 14, 2014 at 01:16: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: geodewdt: Use platform_driver_probe
  2014-03-14 12:16 [PATCH] watchdog: geodewdt: Use platform_driver_probe Jean Delvare
  2014-03-14 17:59 ` Guenter Roeck
@ 2014-03-15 19:53 ` Wim Van Sebroeck
  1 sibling, 0 replies; 3+ messages in thread
From: Wim Van Sebroeck @ 2014-03-15 19:53 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/geodewdt.c |   17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
> 
> --- linux-3.14-rc6.orig/drivers/watchdog/geodewdt.c	2014-01-20 03:40:07.000000000 +0100
> +++ linux-3.14-rc6/drivers/watchdog/geodewdt.c	2014-03-14 10:41:42.415355724 +0100
> @@ -215,7 +215,7 @@ static struct miscdevice geodewdt_miscde
>  	.fops = &geodewdt_fops,
>  };
>  
> -static int geodewdt_probe(struct platform_device *dev)
> +static int __init geodewdt_probe(struct platform_device *dev)
>  {
>  	int ret;
>  
> @@ -255,7 +255,6 @@ static void geodewdt_shutdown(struct pla
>  }
>  
>  static struct platform_driver geodewdt_driver = {
> -	.probe		= geodewdt_probe,
>  	.remove		= geodewdt_remove,
>  	.shutdown	= geodewdt_shutdown,
>  	.driver		= {
> @@ -268,20 +267,18 @@ static int __init geodewdt_init(void)
>  {
>  	int ret;
>  
> -	ret = platform_driver_register(&geodewdt_driver);
> -	if (ret)
> -		return ret;
> -
>  	geodewdt_platform_device = platform_device_register_simple(DRV_NAME,
>  								-1, NULL, 0);
> -	if (IS_ERR(geodewdt_platform_device)) {
> -		ret = PTR_ERR(geodewdt_platform_device);
> +	if (IS_ERR(geodewdt_platform_device))
> +		return PTR_ERR(geodewdt_platform_device);
> +
> +	ret = platform_driver_probe(&geodewdt_driver, geodewdt_probe);
> +	if (ret)
>  		goto err;
> -	}
>  
>  	return 0;
>  err:
> -	platform_driver_unregister(&geodewdt_driver);
> +	platform_device_unregister(geodewdt_platform_device);
>  	return ret;
>  }
>  
> 
> 

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:53 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:16 [PATCH] watchdog: geodewdt: Use platform_driver_probe Jean Delvare
2014-03-14 17:59 ` Guenter Roeck
2014-03-15 19:53 ` 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