Skip to contentSkip to conversation

w1: Add missing of_node_put() and of_node_get()

PATCH New Liang He 1 participant 1 message Jun 22, 2022 W1 dallas's 1-wire bus

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 w1: Add missing of_node_put() and of_node_get()

In __w1_attach_slave_device(), we need to add the of_node_put() for the reference returned by of_find_matching_node() in fail path.

Besides, we will also need a of_node_get() for the first argument of of_find_matching_node() which will decrease its refcount.

---
changelog:

v2: add missing put and get
v1: only add missing put

 drivers/w1/w1.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/w1/w1.c +3 -0
index f2ae2e563dc5..378996d947cc 100644
@@ -680,6 +680,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
 	sl->dev.bus = &w1_bus_type;
 	sl->dev.release = &w1_slave_release;
 	sl->dev.groups = w1_slave_groups;
+
+	of_node_get(sl->master->dev.of_node);
 	sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node,
 						sl->family->of_match_table);
 
@@ -702,6 +704,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
 		dev_err(&sl->dev,
 			"Device registration [%s] failed. err=%d\n",
 			dev_name(&sl->dev), err);
+		of_node_put(sl->dev.of_node);
 		put_device(&sl->dev);
 		return err;
 	}
Signature · 1 line
2.25.1