Skip to contentSkip to conversation

watchdog: ts4800_wdt: Fix refcount leak in ts4800_wdt_probe

PATCH In review Miaoqian Lin 2 participants 2 messages May 11, 2022 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: ts4800_wdt: Fix refcount leak in ts4800_wdt_probe

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() in some error paths.

Fixes bf9006399939 ("watchdog: ts4800: add driver for TS-4800 watchdog")
---
 drivers/watchdog/ts4800_wdt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/watchdog/ts4800_wdt.c +4 -1
index c137ad2bd5c3..0ea554c7cda5 100644
@@ -125,13 +125,16 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
 	ret = of_property_read_u32_index(np, "syscon", 1, &reg);
 	if (ret < 0) {
 		dev_err(dev, "no offset in syscon\n");
+		of_node_put(syscon_np);
 		return ret;
 	}
 
 	/* allocate memory for watchdog struct */
 	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
-	if (!wdt)
+	if (!wdt) {
+		of_node_put(syscon_np);
 		return -ENOMEM;
+	}
 
 	/* set regmap and offset to know where to write */
 	wdt->feed_offset = reg;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Miaoqian Lin

of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() in some error paths.

Fixes bf9006399939 ("watchdog: ts4800: add driver for TS-4800 watchdog")
Quoted 26 lines
---
  drivers/watchdog/ts4800_wdt.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/watchdog/ts4800_wdt.c +4 -1
index c137ad2bd5c3..0ea554c7cda5 100644
@@ -125,13 +125,16 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
  	ret = of_property_read_u32_index(np, "syscon", 1, &reg);
  	if (ret < 0) {
  		dev_err(dev, "no offset in syscon\n");
+		of_node_put(syscon_np);
  		return ret;
  	}
 
  	/* allocate memory for watchdog struct */
  	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
-	if (!wdt)
+	if (!wdt) {
+		of_node_put(syscon_np);
  		return -ENOMEM;
+	}
 
  	/* set regmap and offset to know where to write */
  	wdt->feed_offset = reg;