linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	linux-samsung-soc@vger.kernel.org,
	Alim Akhtar <alim.akhtar@samsung.com>,
	linux-kernel@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	kernel@pengutronix.de, Wim Van Sebroeck <wim@linux-watchdog.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-watchdog@vger.kernel.org
Subject: Re: [PATCH 1/3] watchdog: s3c2410_wdt: Fold s3c2410_get_wdt_drv_data() into only caller
Date: Mon, 6 Mar 2023 10:12:21 -0800	[thread overview]
Message-ID: <eef4ad5a-17d5-c118-7807-f1054ed78c2d@roeck-us.net> (raw)
In-Reply-To: <20230306174722.rl2fws2p7pseo465@pengutronix.de>

On 3/6/23 09:47, Uwe Kleine-König wrote:
> On Mon, Mar 06, 2023 at 09:17:23AM -0800, Guenter Roeck wrote:
>> On 3/6/23 01:09, Uwe Kleine-König wrote:
>>> s3c2410_get_wdt_drv_data() is only called by s3c2410wdt_probe(), so the
>>> implementation of the former can move to the latter.
>>>
>>> scripts/bloat-o-meter reports for this change (on an ARCH=arm
>>> allmodconfig build):
>>>
>>> 	add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-129 (-125)
>>>
>>
>> The reason for separating functions in this case wasn't that the separate function
>> would be called several times. It was to improve code readability. If anything,
>> I would argue that it might sense to split the already lengthy probe function
>> further instead of combining it.
> 
> Agreed. For dev_err_probe() to work the following would be alternatively
> possible:
> 

That looks ok to me.

Thanks,
Guenter

> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index 58b262ca4e88..564919717761 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
> +	wdt->drv_data = variant;
>   
> -	return 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,
> 
> I didn't check if it's the same as for my initial patch #1, but for an
> allmodconfig ARCH=arm build this also has a nice bloatometer output:
> 
> 	add/remove: 1/1 grow/shrink: 0/1 up/down: 4/-104 (-100)
> 
> This would allow to make use of dev_err_probe() in
> s3c2410_get_wdt_drv_data() and still maintain the split into two
> functions.
> 
> Best regards
> Uwe
> 


  reply	other threads:[~2023-03-06 18:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-04 16:56 [PATCH 1/2] watchdog: s3c2410_wdt: Use Use devm_clk_get[_optional]_enabled() helpers Guenter Roeck
2023-03-04 16:56 ` [PATCH 2/2] watchdog: s3c2410_wdt: Use devm_add_action_or_reset() to disable watchdog Guenter Roeck
2023-03-06  9:15   ` Uwe Kleine-König
2023-03-06 15:23     ` Guenter Roeck
2023-03-04 21:46 ` [PATCH 1/2] watchdog: s3c2410_wdt: Use Use devm_clk_get[_optional]_enabled() helpers Christophe JAILLET
2023-03-04 22:10   ` Guenter Roeck
2023-03-05 11:15     ` Uwe Kleine-König
2023-03-05 13:27       ` Krzysztof Kozlowski
2023-03-05 14:31       ` Guenter Roeck
2023-03-06  9:09         ` [PATCH 0/3] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
2023-03-06  9:09           ` [PATCH 1/3] watchdog: s3c2410_wdt: Fold s3c2410_get_wdt_drv_data() into only caller Uwe Kleine-König
2023-03-06 17:17             ` Guenter Roeck
2023-03-06 17:47               ` Uwe Kleine-König
2023-03-06 18:12                 ` Guenter Roeck [this message]
2023-03-06  9:09           ` [PATCH 2/3] watchdog: s3c2410_wdt: Unify error logging format in probe function Uwe Kleine-König
2023-03-06  9:09           ` [PATCH 3/3] watchdog: s3c2410_wdt: Simplify using dev_err_probe() Uwe Kleine-König
2023-03-06  9:10 ` [PATCH 1/2] watchdog: s3c2410_wdt: Use Use devm_clk_get[_optional]_enabled() helpers Uwe Kleine-König
2023-04-18  6:56   ` Uwe Kleine-König
2023-04-22 11:22     ` Wim Van Sebroeck
2023-04-23  8:08       ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eef4ad5a-17d5-c118-7807-f1054ed78c2d@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=alim.akhtar@samsung.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=kernel@pengutronix.de \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).