[PATCH] hwrng: meson - Improve error handling for core clock

Subsystems: hardware random number generator core, the rest

STALE1855d

3 messages, 3 authors, 2021-09-19 · open the first message on its own page

[PATCH] hwrng: meson - Improve error handling for core clock

From: Uwe Kleine-König <hidden>
Date: 2021-09-14 14:24:54

-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 <redacted>
---
 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-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH] hwrng: meson - Improve error handling for core clock

From: Neil Armstrong <hidden>
Date: 2021-09-15 08:13:59

On 14/09/2021 16:24, Uwe Kleine-König wrote:
quoted hunk
-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 <redacted>
---
 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 <redacted>

Thanks,
Neil

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

Re: [PATCH] hwrng: meson - Improve error handling for core clock

From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Date: 2021-09-19 20:07:32

Hi Uwe,

On Tue, Sep 14, 2021 at 4:24 PM Uwe Kleine-König
[off-list ref] wrote:
[...]
quoted hunk
-       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-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help