From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org,
linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] watchdog: s3c2410_wdt: Use Use devm_clk_get[_optional]_enabled() helpers
Date: Sun, 5 Mar 2023 12:15:00 +0100 [thread overview]
Message-ID: <20230305111500.jvass6ymkity4nnd@pengutronix.de> (raw)
In-Reply-To: <431a8ae1-54a7-e71a-484d-cab618a2a1c4@roeck-us.net>
[-- Attachment #1: Type: text/plain, Size: 5164 bytes --]
Hello Guenter,
On Sat, Mar 04, 2023 at 02:10:47PM -0800, Guenter Roeck wrote:
> On 3/4/23 13:46, Christophe JAILLET wrote:
> > Le 04/03/2023 à 17:56, Guenter Roeck a écrit :
> > > The devm_clk_get[_optional]_enabled() helpers:
> > > - call devm_clk_get[_optional]()
> > > - call clk_prepare_enable() and register what is needed in order to
> > > call clk_disable_unprepare() when needed, as a managed resource.
> > >
> > > This simplifies the code and avoids the calls to clk_disable_unprepare().
> > >
> > > While at it, use dev_err_probe consistently, and use its return value
> > > to return the error code.
> > >
> > > Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > > ---
> > > drivers/watchdog/s3c2410_wdt.c | 45 +++++++---------------------------
> > > 1 file changed, 9 insertions(+), 36 deletions(-)
> > >
> > > diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> > > index 200ba236a72e..a1fcb79b0b7c 100644
> > > --- a/drivers/watchdog/s3c2410_wdt.c
> > > +++ b/drivers/watchdog/s3c2410_wdt.c
> > > @@ -661,35 +661,17 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
> > > if (IS_ERR(wdt->reg_base))
> > > return PTR_ERR(wdt->reg_base);
> > > - wdt->bus_clk = devm_clk_get(dev, "watchdog");
> > > - if (IS_ERR(wdt->bus_clk)) {
> > > - dev_err(dev, "failed to find bus clock\n");
> > > - return PTR_ERR(wdt->bus_clk);
> > > - }
> > > -
> > > - ret = clk_prepare_enable(wdt->bus_clk);
> > > - if (ret < 0) {
> > > - dev_err(dev, "failed to enable bus clock\n");
> > > - return ret;
> > > - }
> > > + wdt->bus_clk = devm_clk_get_enabled(dev, "watchdog");
> > > + if (IS_ERR(wdt->bus_clk))
> > > + return dev_err_probe(dev, PTR_ERR(wdt->bus_clk), "failed to get bus clock\n");
> > > /*
> > > * "watchdog_src" clock is optional; if it's not present -- just skip it
> > > * and use "watchdog" clock as both bus and source clock.
> > > */
> > > - wdt->src_clk = devm_clk_get_optional(dev, "watchdog_src");
> > > - if (IS_ERR(wdt->src_clk)) {
> > > - dev_err_probe(dev, PTR_ERR(wdt->src_clk),
> > > - "failed to get source clock\n");
> > > - ret = PTR_ERR(wdt->src_clk);
> > > - goto err_bus_clk;
> > > - }
> > > -
> > > - ret = clk_prepare_enable(wdt->src_clk);
> > > - if (ret) {
> > > - dev_err(dev, "failed to enable source clock\n");
> > > - goto err_bus_clk;
> > > - }
> > > + wdt->src_clk = devm_clk_get_optional_enabled(dev, "watchdog_src");
> > > + if (IS_ERR(wdt->src_clk))
> > > + return dev_err_probe(dev, PTR_ERR(wdt->src_clk), "failed to get source clock\n");
> > > wdt->wdt_device.min_timeout = 1;
> > > wdt->wdt_device.max_timeout = s3c2410wdt_max_timeout(wdt);
> > > @@ -710,7 +692,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
> > > S3C2410_WATCHDOG_DEFAULT_TIME);
> > > } else {
> > > dev_err(dev, "failed to use default timeout\n");
> > > - goto err_src_clk;
> > > + return ret;
> >
> > Hi,
> >
> > Nit: this also could be "return dev_err_probe()"
> >
> > > }
> > > }
> > > @@ -718,7 +700,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
> > > pdev->name, pdev);
> > > if (ret != 0) {
> > > dev_err(dev, "failed to install irq (%d)\n", ret);
> > > - goto err_src_clk;
> > > + return ret;
> >
> > Nit: this also could be "return dev_err_probe()"
> >
>
> The primary reason to call dev_err_probe() is that the error may be
> -EPROBE_DEFER, in which case the error message is suppressed.
> That is not the case for those two functions; they never return
> -EPROBE_DEFER. Calling dev_err_probe() would give the false impression
> that the functions _might_ return -EPROBE_DEFER.
That is subjective. In my book dev_err_probe() handling -EPROBE_DEFER is
only one aspect. Another is that using it allows to have return and error
message in a single line and also that if already other exit paths use
it to get a consistent style for the emitted messages. Having said that
*I* wouldn't assume that the previous call might return -EPROBE_DEFER
just because dev_err_probe() is used.
Having said that, I also don't think there is much harm if someone
thinks that a given function (here devm_request_irq()) might return
-EPROBE_DEFER.
Just my 0.02€
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2023-03-05 11:15 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 [this message]
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
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=20230305111500.jvass6ymkity4nnd@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=alim.akhtar@samsung.com \
--cc=christophe.jaillet@wanadoo.fr \
--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=linux@roeck-us.net \
--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).