drivers/watchdog/watchdog_core.c | 7 +++++++ 1 file changed, 7 insertions(+)
If the user did not pass a parent in the struct watchdog_device
then use the device used for devres as parent.
This is quite intuitive and can help avoiding having to
assign parent explicitly in every driver using devres
to add the watchdog_device.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
Linus: hope you don't mind me flat out copying the description from
https://lore.kernel.org/all/20260427-gpio-mmio-more-v3-1-fe1882351424@kernel.org/
drivers/watchdog/watchdog_core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 8300520688d0..726c85debabc 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -440,6 +440,13 @@ int devm_watchdog_register_device(struct device *dev,
if (!rcwdd)
return -ENOMEM;
+ /*
+ * We are passing the devres device here so if the user did not pass
+ * another parent, it's this one.
+ */
+ if (!wdd->parent)
+ wdd->parent = dev;
+
ret = watchdog_register_device(wdd);
if (!ret) {
*rcwdd = wdd;
--
2.54.0
On 5/23/26 19:23, Rosen Penev wrote: > If the user did not pass a parent in the struct watchdog_device > then use the device used for devres as parent. > > This is quite intuitive and can help avoiding having to > assign parent explicitly in every driver using devres > to add the watchdog_device. > > Signed-off-by: Rosen Penev <rosenp@gmail.com> > --- > Linus: hope you don't mind me flat out copying the description from > https://lore.kernel.org/all/20260427-gpio-mmio-more-v3-1-fe1882351424@kernel.org/ > drivers/watchdog/watchdog_core.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c > index 8300520688d0..726c85debabc 100644 > --- a/drivers/watchdog/watchdog_core.c > +++ b/drivers/watchdog/watchdog_core.c > @@ -440,6 +440,13 @@ int devm_watchdog_register_device(struct device *dev, > if (!rcwdd) > return -ENOMEM; > > + /* > + * We are passing the devres device here so if the user did not pass > + * another parent, it's this one. > + */ > + if (!wdd->parent) > + wdd->parent = dev; > + I understand that you consider it to be garbage, but in my opinion Sashiko has a point. If the watchdog device data structure is static, wdd->parent will be retained over multiple remove/reinsert instantiations of the driver, which in turn would result in subsequent UAF. That means I can not accept your patch. Guenter
© 2016 - 2026 Red Hat, Inc.