Skip to contentSkip to conversation

drivers: hwmon: Add missing of_node_put() in gsc-hwmon.c

PATCH Superseded Liang He 2 participants 4 messages Jun 15, 2022 – Jun 16, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 drivers: hwmon: Add missing of_node_put() in gsc-hwmon.c

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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hwmon/gsc-hwmon.c +5 -1
index 1fe37418ff46..34c20d13627a 100644
@@ -268,10 +268,14 @@ 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)) {
+	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);
 	}
+	
+	/* if fan&&!of_property_read_u32 fail */
+	of_node_put(fan);
 
 	/* allocate structures for channels and count instances of each type */
 	device_for_each_child_node(dev, child) {
Signature · 1 line
2.25.1
maintainer
#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.

Quoted 1 line

---

Please use proper subject lines. Here it should have been

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

drivers/hwmon/gsc-hwmon.c gsc_hwmon_get_devtree_pdata(struct device *dev) · line 270

Quoted 11 lines
  drivers/hwmon/gsc-hwmon.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hwmon/gsc-hwmon.c +0 -0
index 1fe37418ff46..34c20d13627a 100644
@@ -268,10 +268,14 @@ 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");

A single of_node_put(fan) here would have been be sufficient.

drivers/hwmon/gsc-hwmon.c gsc_hwmon_get_devtree_pdata(struct device *dev) · line 277

Quoted 8 lines
drivers/hwmon/gsc-hwmon.c +4 -1
-	if (fan && of_property_read_u32(fan, "reg", &pdata->fan_base)) {
+	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);
  	}
+	
+	/* if fan&&!of_property_read_u32 fail */

This comment only adds confusion and does not add any value.

Guenter

Quoted 4 lines
drivers/hwmon/gsc-hwmon.c +1 -0
+	of_node_put(fan);
 
  	/* allocate structures for channels and count instances of each type */
  	device_for_each_child_node(dev, child) {
author
#2 lore raw
Quoted 4 lines · Guenter Roeck

Please use proper subject lines. Here it should have been

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

Thanks, I will change it in my new patch.

Quoted 9 lines
Quoted 9 lines
Quoted 1 line
  drivers/hwmon/gsc-hwmon.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hwmon/gsc-hwmon.c +0 -0
index 1fe37418ff46..34c20d13627a 100644
@@ -268,10 +268,14 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
 
Quoted 4 lines

drivers/hwmon/gsc-hwmon.c gsc_hwmon_get_devtree_pdata(struct device *dev) · line 270

Quoted 2 lines
drivers/hwmon/gsc-hwmon.c +0 -0
  	/* fan controller base address */
  	fan = of_find_compatible_node(dev->parent->of_node, NULL, "gw,gsc-fan");

A single of_node_put(fan) here would have been be sufficient.

I think of_node_put after should come after its usage, right?

Quoted 11 lines

drivers/hwmon/gsc-hwmon.c gsc_hwmon_get_devtree_pdata(struct device *dev) · line 277

Quoted 8 lines
drivers/hwmon/gsc-hwmon.c +4 -0
 > -	if (fan && of_property_read_u32(fan, "reg", &pdata->fan_base)) {
+	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);
  	}
+	
+	/* if fan&&!of_property_read_u32 fail */

This comment only adds confusion and does not add any value.

Sorry, I just want to say, if *fan* is not NULL, but of_property_read_u32() returns 0. In that case, we still need a of_node_put() to release fan, right?

Quoted 8 lines

Guenter

Quoted 5 lines
drivers/hwmon/gsc-hwmon.c +1 -0
+	of_node_put(fan);
 
  	/* allocate structures for channels and count instances of each type */
 
  	device_for_each_child_node(dev, child) {

Hi, Guenter, I am preparing my new patch and I want to discuss your suggestions as above.

maintainer
#3 lore raw
Quoted 23 lines · 和亮
Quoted 4 lines · Guenter Roeck

Please use proper subject lines. Here it should have been

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

Thanks, I will change it in my new patch.

Quoted 9 lines
Quoted 9 lines
Quoted 1 line
   drivers/hwmon/gsc-hwmon.c | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hwmon/gsc-hwmon.c +0 -0
index 1fe37418ff46..34c20d13627a 100644
@@ -268,10 +268,14 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
 
Quoted 10 lines
Quoted 4 lines

drivers/hwmon/gsc-hwmon.c gsc_hwmon_get_devtree_pdata(struct device *dev) · line 270

Quoted 2 lines
drivers/hwmon/gsc-hwmon.c +0 -0
   	/* fan controller base address */
   	fan = of_find_compatible_node(dev->parent->of_node, NULL, "gw,gsc-fan");

A single of_node_put(fan) here would have been be sufficient.

I think of_node_put after should come after its usage, right?

Yes, you are correct. Sorry for the noise.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
drivers/hwmon/gsc-hwmon.c +4 -0
 > -	if (fan && of_property_read_u32(fan, "reg", &pdata->fan_base)) {
+	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);
   	}
+	
+	/* if fan&&!of_property_read_u32 fail */
Quoted 6 lines
Quoted 1 line

This comment only adds confusion and does not add any value.

Sorry, I just want to say, if *fan* is not NULL, but of_property_read_u32() returns 0. In that case, we still need a of_node_put() to release fan, right?

Yes, but that is obvious, and the comment is not needed.

Thanks,
Guenter

Quoted 12 lines
Quoted 8 lines

Guenter

Quoted 5 lines
drivers/hwmon/gsc-hwmon.c +1 -0
+	of_node_put(fan);
 
   	/* allocate structures for channels and count instances of each type */
 
   	device_for_each_child_node(dev, child) {

Hi, Guenter, I am preparing my new patch and I want to discuss your suggestions as above.