Skip to contentSkip to conversation

hwmon: (gsc-hwmon) Add missing of_node_put()

PATCH Applied Liang He 2 participants 2 messages Jun 16, 2022 – Jun 17, 2022

Subsystems (2)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 hwmon: (gsc-hwmon) Add missing of_node_put()

In gsc_hwmon_get_devtree_pdata(), of_find_compatible_node() will return a node pointer with refcount incremented. We should use of_node_put() in fail path or when it is not used anymore.

---
 drivers/hwmon/gsc-hwmon.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/gsc-hwmon.c +3 -0
index 1fe37418ff46..d64be48f1ef6 100644
@@ -269,10 +269,13 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
 	/* fan controller base address */
 	fan = of_find_compatible_node(dev->parent->of_node, NULL, "gw,gsc-fan");
 	if (fan && of_property_read_u32(fan, "reg", &pdata->fan_base)) {
+		of_node_put(fan);
 		dev_err(dev, "fan node without base\n");
 		return ERR_PTR(-EINVAL);
 	}
 
+	of_node_put(fan);
+
 	/* allocate structures for channels and count instances of each type */
 	device_for_each_child_node(dev, child) {
 		if (fwnode_property_read_string(child, "label", &ch->name)) {
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Liang He

In gsc_hwmon_get_devtree_pdata(), of_find_compatible_node() will return a node pointer with refcount incremented. We should use of_node_put() in fail path or when it is not used anymore.

Applied.

Thanks,
Guenter

Quoted 22 lines
---
 drivers/hwmon/gsc-hwmon.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/gsc-hwmon.c +3 -0
index 1fe37418ff46..d64be48f1ef6 100644
@@ -269,10 +269,13 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
 	/* fan controller base address */
 	fan = of_find_compatible_node(dev->parent->of_node, NULL, "gw,gsc-fan");
 	if (fan && of_property_read_u32(fan, "reg", &pdata->fan_base)) {
+		of_node_put(fan);
 		dev_err(dev, "fan node without base\n");
 		return ERR_PTR(-EINVAL);
 	}
 
+	of_node_put(fan);
+
 	/* allocate structures for channels and count instances of each type */
 	device_for_each_child_node(dev, child) {
 		if (fwnode_property_read_string(child, "label", &ch->name)) {