Re: [PATCH v6 07/12] watchdog: wdt-uclass.c: add wdt_stop_all() helper

2021-08-19 Thread Wolfgang Denk
Dear Rasmus,

again: error handling.

In message <20210819095706.3585923-8-rasmus.villem...@prevas.dk> you wrote:
>
> --- a/drivers/watchdog/wdt-uclass.c
> +++ b/drivers/watchdog/wdt-uclass.c
> @@ -116,6 +116,31 @@ int wdt_stop(struct udevice *dev)
>   return ret;
>  }
>  
> +int wdt_stop_all(void)
> +{
> + struct wdt_priv *priv;
> + struct udevice *dev;
> + struct uclass *uc;
> + int ret, err;
> +
> + ret = uclass_get(UCLASS_WDT, );
> + if (ret)
> + return ret;
> +
> + uclass_foreach_dev(dev, uc) {
> + if (!device_active(dev))
> + continue;
> + priv = dev_get_uclass_priv(dev);
> + if (!priv->running)
> + continue;

Potential NULL pointer dereferencing.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
I paid too much for it, but its worth it.


[PATCH v6 07/12] watchdog: wdt-uclass.c: add wdt_stop_all() helper

2021-08-19 Thread Rasmus Villemoes
Since the watchdog_dev member of struct global_data is going away in
favor of the wdt-uclass handling all watchdog devices, prepare for
that by adding a helper to call wdt_stop() on all known devices.

If an error is encountered, still do wdt_stop() on remaining devices,
but remember and return the first error seen.

Initially, this will only be used in one single
place (board/alliedtelesis/x530/x530.c).

Signed-off-by: Rasmus Villemoes 
---
 drivers/watchdog/wdt-uclass.c | 25 +
 include/wdt.h |  8 
 2 files changed, 33 insertions(+)

diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
index 358fc68e27..5b1c0df5d6 100644
--- a/drivers/watchdog/wdt-uclass.c
+++ b/drivers/watchdog/wdt-uclass.c
@@ -116,6 +116,31 @@ int wdt_stop(struct udevice *dev)
return ret;
 }
 
+int wdt_stop_all(void)
+{
+   struct wdt_priv *priv;
+   struct udevice *dev;
+   struct uclass *uc;
+   int ret, err;
+
+   ret = uclass_get(UCLASS_WDT, );
+   if (ret)
+   return ret;
+
+   uclass_foreach_dev(dev, uc) {
+   if (!device_active(dev))
+   continue;
+   priv = dev_get_uclass_priv(dev);
+   if (!priv->running)
+   continue;
+   err = wdt_stop(dev);
+   if (!ret)
+   ret = err;
+   }
+
+   return ret;
+}
+
 int wdt_reset(struct udevice *dev)
 {
const struct wdt_ops *ops = device_get_ops(dev);
diff --git a/include/wdt.h b/include/wdt.h
index bc242c2eb2..baaa9db08a 100644
--- a/include/wdt.h
+++ b/include/wdt.h
@@ -37,6 +37,14 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong 
flags);
  */
 int wdt_stop(struct udevice *dev);
 
+/*
+ * Stop all registered watchdog devices.
+ *
+ * @return: 0 if ok, first error encountered otherwise (but wdt_stop()
+ * is still called on following devices)
+ */
+int wdt_stop_all(void);
+
 /*
  * Reset the timer, typically restoring the counter to
  * the value configured by start()
-- 
2.31.1