linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwrng: meson - Improve error handling for core clock
@ 2021-09-14 14:24 Uwe Kleine-König
  2021-09-15  8:13 ` Neil Armstrong
  2021-09-19 20:07 ` Martin Blumenstingl
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-09-14 14:24 UTC (permalink / raw)
  To: Matt Mackall, Herbert Xu, Neil Armstrong, Kevin Hilman
  Cc: Jerome Brunet, Martin Blumenstingl, linux-crypto,
	linux-arm-kernel, linux-amlogic, kernel

-ENOENT (ie. "there is no clock") is fine to ignore for an optional
clock, other values are not supposed to be ignored and should be
escalated to the caller (e.g. -EPROBE_DEFER). Ignore -ENOENT by using
devm_clk_get_optional().

While touching this code also add an error message for the fatal errors.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/char/hw_random/meson-rng.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c
index e446236e81f2..9f3e2eb8011d 100644
--- a/drivers/char/hw_random/meson-rng.c
+++ b/drivers/char/hw_random/meson-rng.c
@@ -54,9 +54,15 @@ static int meson_rng_probe(struct platform_device *pdev)
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
-	data->core_clk = devm_clk_get(dev, "core");
-	if (IS_ERR(data->core_clk))
-		data->core_clk = NULL;
+	data->core_clk = devm_clk_get_optional(dev, "core");
+	if (IS_ERR(data->core_clk)) {
+		ret = PTR_ERR(data->core_clk);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get core clock: %pe\n",
+				data->core_clk);
+
+		return ret;
+	}
 
 	if (data->core_clk) {
 		ret = clk_prepare_enable(data->core_clk);
-- 
2.30.2


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] hwrng: meson - Improve error handling for core clock
  2021-09-14 14:24 [PATCH] hwrng: meson - Improve error handling for core clock Uwe Kleine-König
@ 2021-09-15  8:13 ` Neil Armstrong
  2021-09-19 20:07 ` Martin Blumenstingl
  1 sibling, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2021-09-15  8:13 UTC (permalink / raw)
  To: Uwe Kleine-König, Matt Mackall, Herbert Xu, Kevin Hilman
  Cc: Jerome Brunet, Martin Blumenstingl, linux-crypto,
	linux-arm-kernel, linux-amlogic, kernel

On 14/09/2021 16:24, Uwe Kleine-König wrote:
> -ENOENT (ie. "there is no clock") is fine to ignore for an optional
> clock, other values are not supposed to be ignored and should be
> escalated to the caller (e.g. -EPROBE_DEFER). Ignore -ENOENT by using
> devm_clk_get_optional().
> 
> While touching this code also add an error message for the fatal errors.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/char/hw_random/meson-rng.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c
> index e446236e81f2..9f3e2eb8011d 100644
> --- a/drivers/char/hw_random/meson-rng.c
> +++ b/drivers/char/hw_random/meson-rng.c
> @@ -54,9 +54,15 @@ static int meson_rng_probe(struct platform_device *pdev)
>  	if (IS_ERR(data->base))
>  		return PTR_ERR(data->base);
>  
> -	data->core_clk = devm_clk_get(dev, "core");
> -	if (IS_ERR(data->core_clk))
> -		data->core_clk = NULL;
> +	data->core_clk = devm_clk_get_optional(dev, "core");
> +	if (IS_ERR(data->core_clk)) {
> +		ret = PTR_ERR(data->core_clk);
> +		if (ret != -EPROBE_DEFER)
> +			dev_err(dev, "Failed to get core clock: %pe\n",
> +				data->core_clk);
> +
> +		return ret;
> +	}
>  
>  	if (data->core_clk) {
>  		ret = clk_prepare_enable(data->core_clk);
> 

Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>

Thanks,
Neil

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] hwrng: meson - Improve error handling for core clock
  2021-09-14 14:24 [PATCH] hwrng: meson - Improve error handling for core clock Uwe Kleine-König
  2021-09-15  8:13 ` Neil Armstrong
@ 2021-09-19 20:07 ` Martin Blumenstingl
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Blumenstingl @ 2021-09-19 20:07 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Matt Mackall, Herbert Xu, Neil Armstrong, Kevin Hilman,
	Jerome Brunet, linux-crypto, linux-arm-kernel, linux-amlogic,
	kernel

Hi Uwe,

On Tue, Sep 14, 2021 at 4:24 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
[...]
> -       data->core_clk = devm_clk_get(dev, "core");
> -       if (IS_ERR(data->core_clk))
> -               data->core_clk = NULL;
> +       data->core_clk = devm_clk_get_optional(dev, "core");
> +       if (IS_ERR(data->core_clk)) {
> +               ret = PTR_ERR(data->core_clk);
> +               if (ret != -EPROBE_DEFER)
> +                       dev_err(dev, "Failed to get core clock: %pe\n",
> +                               data->core_clk);
> +
> +               return ret;
I suggest simplifying this by using dev_err_probe as this:
- allows you to get rid of the if (ret != -EPROBE_DEFER)
- means that the message is shown in debugfs' "devices_deferred"


Best regards,
Martin

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

end of thread, other threads:[~2021-09-19 20:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 14:24 [PATCH] hwrng: meson - Improve error handling for core clock Uwe Kleine-König
2021-09-15  8:13 ` Neil Armstrong
2021-09-19 20:07 ` Martin Blumenstingl

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).