Re: [PATCH] watchdog: core: assign parent with devm registration

From: Guenter Roeck

Date: Sun May 24 2026 - 11:23:05 EST


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@xxxxxxxxx>
---
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@xxxxxxxxxx/
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