linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe()
@ 2023-03-07  6:56 Uwe Kleine-König
  2023-03-07  6:56 ` [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int Uwe Kleine-König
  2023-03-07  6:56 ` [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
  0 siblings, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-07  6:56 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	linux-kernel, kernel

Hello,

changes since (implicit) v1, sent with Message-Id:
20230306090919.2206871-1-u.kleine-koenig@pengutronix.de:

 - Rework patch #1 to keep s3c2410_get_wdt_drv_data() as a separate
   function. The return value has to change however to make effective
   use of dev_err_probe(). (I thought about using

   	return ERR_PTR(dev_err_probe(...));

   but this looks too ugly and that's less effective because then
   dev_err_probe cannot be compiled into a tail call.)

 - Squash patches #2 and #3. This destroys the pretty bloatometer
   statistic, in fact bloatometer diagnoses that the code gets bigger.
   I'm a bit surprised but didn't try to understand it. I assume that's
   because the additional parameter that dev_err_probe has to get over
   dev_err is the culprit. Still given that the error code is now
   included in the error message this is an IMHO nice patch.

Now that Gunter likes patch #1 better than the one from v1, I wonder
about his position about patch #2.

Best regards
Uwe

Uwe Kleine-König (2):
  watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int
  watchdog: s3c2410_wdt: Simplify using dev_err_probe()

 drivers/watchdog/s3c2410_wdt.c | 47 +++++++++++++++-------------------
 1 file changed, 20 insertions(+), 27 deletions(-)


base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
prerequisite-patch-id: 775bdd863307268e1ef16250bf2f40862637b453
prerequisite-patch-id: 924ddfbe583e97e7c9a46c2460ecbc88c29ee319
-- 
2.39.1


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

* [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int
  2023-03-07  6:56 [PATCH v2 0/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
@ 2023-03-07  6:56 ` Uwe Kleine-König
  2023-03-07 16:37   ` Guenter Roeck
  2023-03-07  6:56 ` [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
  1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-07  6:56 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	linux-kernel, kernel

This is a preparation for making more use of dev_err_probe(). The idea
is that s3c2410_get_wdt_drv_data() (as it's called only by .probe()) can
make effective use of dev_err_probe() only if it returns an int. For
that the assignment to wdt->drv_data has to happen in the function. The
caller can then just pass on the return value in the error case.

This seems to be nicer for the compiler: bloatometer reports for an
ARCH=arm s3c6400_defconfig build:

	add/remove: 1/1 grow/shrink: 0/1 up/down: 4/-64 (-60)
	Function                                     old     new   delta
	__initcall__kmod_s3c2410_wdt__209_821_s3c2410wdt_driver_init6       -       4      +4
	__initcall__kmod_s3c2410_wdt__209_819_s3c2410wdt_driver_init6       4       -      -4
	s3c2410wdt_probe                            1332    1272     -60

There is no semantical change. (Just one minor difference: Before this
patch wdt->drv_data was always assigned, now that only happens in the
non-error case. That doesn't matter however as *wdt is freed in the
error case.)

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/watchdog/s3c2410_wdt.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 58b262ca4e88..f3de8ef499c3 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -579,8 +579,8 @@ static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wdt *wdt)
 	return 0;
 }
 
-static inline const struct s3c2410_wdt_variant *
-s3c2410_get_wdt_drv_data(struct platform_device *pdev)
+static inline int
+s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
 {
 	const struct s3c2410_wdt_variant *variant;
 	struct device *dev = &pdev->dev;
@@ -603,24 +603,26 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev)
 					   "samsung,cluster-index", &index);
 		if (err) {
 			dev_err(dev, "failed to get cluster index\n");
-			return NULL;
+			return -EINVAL;
 		}
 
 		switch (index) {
 		case 0:
-			return variant;
+			break;
 		case 1:
-			return (variant == &drv_data_exynos850_cl0) ?
+			variant = (variant == &drv_data_exynos850_cl0) ?
 				&drv_data_exynos850_cl1 :
 				&drv_data_exynosautov9_cl1;
+			break;
 		default:
 			dev_err(dev, "wrong cluster index: %u\n", index);
-			return NULL;
+			return -EINVAL;
 		}
 	}
 #endif
 
-	return variant;
+	wdt->drv_data = variant;
+	return 0;
 }
 
 static void s3c2410wdt_wdt_disable_action(void *data)
@@ -644,9 +646,9 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 	spin_lock_init(&wdt->lock);
 	wdt->wdt_device = s3c2410_wdd;
 
-	wdt->drv_data = s3c2410_get_wdt_drv_data(pdev);
-	if (!wdt->drv_data)
-		return -EINVAL;
+	ret = s3c2410_get_wdt_drv_data(pdev, wdt);
+	if (ret)
+		return ret;
 
 	if (wdt->drv_data->quirks & QUIRKS_HAVE_PMUREG) {
 		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
-- 
2.39.1


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

* [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe()
  2023-03-07  6:56 [PATCH v2 0/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
  2023-03-07  6:56 ` [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int Uwe Kleine-König
@ 2023-03-07  6:56 ` Uwe Kleine-König
  2023-03-07 16:37   ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-07  6:56 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	linux-kernel, kernel

Make use of dev_err_probe() also for error paths that don't have to
handle -EPROBE_DEFER. While the code handing -EPROBE_DEFER isn't used
for these error paths, it still simpler as it cares for pretty printing
the error code and usually needs one code line less as it combines
message emitting and error returning. This also unifies the format of
the error messages.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/watchdog/s3c2410_wdt.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index f3de8ef499c3..e14d6d9050ce 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -601,10 +601,8 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
 
 		err = of_property_read_u32(dev->of_node,
 					   "samsung,cluster-index", &index);
-		if (err) {
-			dev_err(dev, "failed to get cluster index\n");
-			return -EINVAL;
-		}
+		if (err)
+			return dev_err_probe(dev, -EINVAL, "failed to get cluster index\n");
 
 		switch (index) {
 		case 0:
@@ -615,8 +613,7 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
 				&drv_data_exynosautov9_cl1;
 			break;
 		default:
-			dev_err(dev, "wrong cluster index: %u\n", index);
-			return -EINVAL;
+			return dev_err_probe(dev, -EINVAL, "wrong cluster index: %u\n", index);
 		}
 	}
 #endif
@@ -653,10 +650,8 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 	if (wdt->drv_data->quirks & QUIRKS_HAVE_PMUREG) {
 		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
 						"samsung,syscon-phandle");
-		if (IS_ERR(wdt->pmureg)) {
-			dev_err(dev, "syscon regmap lookup failed.\n");
-			return PTR_ERR(wdt->pmureg);
-		}
+		if (IS_ERR(wdt->pmureg))
+			return dev_err_probe(dev, PTR_ERR(wdt->pmureg), "syscon regmap lookup failed.\n");
 	}
 
 	wdt_irq = platform_get_irq(pdev, 0);
@@ -694,21 +689,17 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 	if (ret) {
 		ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device,
 					       S3C2410_WATCHDOG_DEFAULT_TIME);
-		if (ret == 0) {
+		if (ret == 0)
 			dev_warn(dev, "tmr_margin value out of range, default %d used\n",
 				 S3C2410_WATCHDOG_DEFAULT_TIME);
-		} else {
-			dev_err(dev, "failed to use default timeout\n");
-			return ret;
-		}
+		else
+			return dev_err_probe(dev, ret, "failed to use default timeout\n");
 	}
 
 	ret = devm_request_irq(dev, wdt_irq, s3c2410wdt_irq, 0,
 			       pdev->name, pdev);
-	if (ret != 0) {
-		dev_err(dev, "failed to install irq (%d)\n", ret);
-		return ret;
-	}
+	if (ret != 0)
+		return dev_err_probe(dev, ret, "failed to install irq (%d)\n", ret);
 
 	watchdog_set_nowayout(&wdt->wdt_device, nowayout);
 	watchdog_set_restart_priority(&wdt->wdt_device, 128);
-- 
2.39.1


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

* Re: [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int
  2023-03-07  6:56 ` [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int Uwe Kleine-König
@ 2023-03-07 16:37   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2023-03-07 16:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Krzysztof Kozlowski, Wim Van Sebroeck, Alim Akhtar,
	linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	linux-kernel, kernel

On Tue, Mar 07, 2023 at 07:56:02AM +0100, Uwe Kleine-König wrote:
> This is a preparation for making more use of dev_err_probe(). The idea
> is that s3c2410_get_wdt_drv_data() (as it's called only by .probe()) can
> make effective use of dev_err_probe() only if it returns an int. For
> that the assignment to wdt->drv_data has to happen in the function. The
> caller can then just pass on the return value in the error case.
> 
> This seems to be nicer for the compiler: bloatometer reports for an
> ARCH=arm s3c6400_defconfig build:
> 
> 	add/remove: 1/1 grow/shrink: 0/1 up/down: 4/-64 (-60)
> 	Function                                     old     new   delta
> 	__initcall__kmod_s3c2410_wdt__209_821_s3c2410wdt_driver_init6       -       4      +4
> 	__initcall__kmod_s3c2410_wdt__209_819_s3c2410wdt_driver_init6       4       -      -4
> 	s3c2410wdt_probe                            1332    1272     -60
> 
> There is no semantical change. (Just one minor difference: Before this
> patch wdt->drv_data was always assigned, now that only happens in the
> non-error case. That doesn't matter however as *wdt is freed in the
> error case.)
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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

> ---
>  drivers/watchdog/s3c2410_wdt.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index 58b262ca4e88..f3de8ef499c3 100644
> --- a/drivers/watchdog/s3c2410_wdt.c
> +++ b/drivers/watchdog/s3c2410_wdt.c
> @@ -579,8 +579,8 @@ static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wdt *wdt)
>  	return 0;
>  }
>  
> -static inline const struct s3c2410_wdt_variant *
> -s3c2410_get_wdt_drv_data(struct platform_device *pdev)
> +static inline int
> +s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
>  {
>  	const struct s3c2410_wdt_variant *variant;
>  	struct device *dev = &pdev->dev;
> @@ -603,24 +603,26 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev)
>  					   "samsung,cluster-index", &index);
>  		if (err) {
>  			dev_err(dev, "failed to get cluster index\n");
> -			return NULL;
> +			return -EINVAL;
>  		}
>  
>  		switch (index) {
>  		case 0:
> -			return variant;
> +			break;
>  		case 1:
> -			return (variant == &drv_data_exynos850_cl0) ?
> +			variant = (variant == &drv_data_exynos850_cl0) ?
>  				&drv_data_exynos850_cl1 :
>  				&drv_data_exynosautov9_cl1;
> +			break;
>  		default:
>  			dev_err(dev, "wrong cluster index: %u\n", index);
> -			return NULL;
> +			return -EINVAL;
>  		}
>  	}
>  #endif
>  
> -	return variant;
> +	wdt->drv_data = variant;
> +	return 0;
>  }
>  
>  static void s3c2410wdt_wdt_disable_action(void *data)
> @@ -644,9 +646,9 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
>  	spin_lock_init(&wdt->lock);
>  	wdt->wdt_device = s3c2410_wdd;
>  
> -	wdt->drv_data = s3c2410_get_wdt_drv_data(pdev);
> -	if (!wdt->drv_data)
> -		return -EINVAL;
> +	ret = s3c2410_get_wdt_drv_data(pdev, wdt);
> +	if (ret)
> +		return ret;
>  
>  	if (wdt->drv_data->quirks & QUIRKS_HAVE_PMUREG) {
>  		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
> -- 
> 2.39.1
> 

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

* Re: [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe()
  2023-03-07  6:56 ` [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
@ 2023-03-07 16:37   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2023-03-07 16:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Krzysztof Kozlowski, Wim Van Sebroeck, Alim Akhtar,
	linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	linux-kernel, kernel

On Tue, Mar 07, 2023 at 07:56:03AM +0100, Uwe Kleine-König wrote:
> Make use of dev_err_probe() also for error paths that don't have to
> handle -EPROBE_DEFER. While the code handing -EPROBE_DEFER isn't used
> for these error paths, it still simpler as it cares for pretty printing
> the error code and usually needs one code line less as it combines
> message emitting and error returning. This also unifies the format of
> the error messages.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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

> ---
>  drivers/watchdog/s3c2410_wdt.c | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index f3de8ef499c3..e14d6d9050ce 100644
> --- a/drivers/watchdog/s3c2410_wdt.c
> +++ b/drivers/watchdog/s3c2410_wdt.c
> @@ -601,10 +601,8 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
>  
>  		err = of_property_read_u32(dev->of_node,
>  					   "samsung,cluster-index", &index);
> -		if (err) {
> -			dev_err(dev, "failed to get cluster index\n");
> -			return -EINVAL;
> -		}
> +		if (err)
> +			return dev_err_probe(dev, -EINVAL, "failed to get cluster index\n");
>  
>  		switch (index) {
>  		case 0:
> @@ -615,8 +613,7 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev, struct s3c2410_wdt *wdt)
>  				&drv_data_exynosautov9_cl1;
>  			break;
>  		default:
> -			dev_err(dev, "wrong cluster index: %u\n", index);
> -			return -EINVAL;
> +			return dev_err_probe(dev, -EINVAL, "wrong cluster index: %u\n", index);
>  		}
>  	}
>  #endif
> @@ -653,10 +650,8 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
>  	if (wdt->drv_data->quirks & QUIRKS_HAVE_PMUREG) {
>  		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
>  						"samsung,syscon-phandle");
> -		if (IS_ERR(wdt->pmureg)) {
> -			dev_err(dev, "syscon regmap lookup failed.\n");
> -			return PTR_ERR(wdt->pmureg);
> -		}
> +		if (IS_ERR(wdt->pmureg))
> +			return dev_err_probe(dev, PTR_ERR(wdt->pmureg), "syscon regmap lookup failed.\n");
>  	}
>  
>  	wdt_irq = platform_get_irq(pdev, 0);
> @@ -694,21 +689,17 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
>  	if (ret) {
>  		ret = s3c2410wdt_set_heartbeat(&wdt->wdt_device,
>  					       S3C2410_WATCHDOG_DEFAULT_TIME);
> -		if (ret == 0) {
> +		if (ret == 0)
>  			dev_warn(dev, "tmr_margin value out of range, default %d used\n",
>  				 S3C2410_WATCHDOG_DEFAULT_TIME);
> -		} else {
> -			dev_err(dev, "failed to use default timeout\n");
> -			return ret;
> -		}
> +		else
> +			return dev_err_probe(dev, ret, "failed to use default timeout\n");
>  	}
>  
>  	ret = devm_request_irq(dev, wdt_irq, s3c2410wdt_irq, 0,
>  			       pdev->name, pdev);
> -	if (ret != 0) {
> -		dev_err(dev, "failed to install irq (%d)\n", ret);
> -		return ret;
> -	}
> +	if (ret != 0)
> +		return dev_err_probe(dev, ret, "failed to install irq (%d)\n", ret);
>  
>  	watchdog_set_nowayout(&wdt->wdt_device, nowayout);
>  	watchdog_set_restart_priority(&wdt->wdt_device, 128);
> -- 
> 2.39.1
> 

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

end of thread, other threads:[~2023-03-07 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07  6:56 [PATCH v2 0/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
2023-03-07  6:56 ` [PATCH v2 1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int Uwe Kleine-König
2023-03-07 16:37   ` Guenter Roeck
2023-03-07  6:56 ` [PATCH v2 2/2] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
2023-03-07 16:37   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).