diff mbox series

[v2,1/2] watchdog: s3c2410: Make s3c2410_get_wdt_drv_data() return an int

Message ID 20230307065603.2253054-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State Accepted
Commit 16d477a1dba9f214d1229d0a122d6d3a9636aa79
Headers show
Series watchdog: s3c2410_wdt: Simplify using dev_err_probe() | expand

Commit Message

Uwe Kleine-König March 7, 2023, 6:56 a.m. UTC
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(-)

Comments

Guenter Roeck March 7, 2023, 4:37 p.m. UTC | #1
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
>
diff mbox series

Patch

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,