w1: fix wrong dt refcount in attach slave device
diff mbox series

Message ID 20181203121951.1230-1-nsaenzjulienne@suse.de
State New, archived
Headers show
Series
  • w1: fix wrong dt refcount in attach slave device
Related show

Commit Message

Nicolas Saenz Julienne Dec. 3, 2018, 12:19 p.m. UTC
With each call to of_find_matching_node() we're decresing the reference
count on the master's dt node. This is not what we actually want. So we
get a refernce to the dt node before calling it.

Fixes: fae68031f7fbc ("w1: core: match sub-nodes of bus masters in devicetree")
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/w1/w1.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 890c038c25f8..09514fa6c6b9 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -680,15 +680,17 @@  static int w1_family_notify(unsigned long action, struct w1_slave *sl)
 
 static int __w1_attach_slave_device(struct w1_slave *sl)
 {
+	struct device_node *np;
 	int err;
 
+	np = of_node_get(sl->master->dev.of_node);
+
 	sl->dev.parent = &sl->master->dev;
 	sl->dev.driver = &w1_slave_driver;
 	sl->dev.bus = &w1_bus_type;
 	sl->dev.release = &w1_slave_release;
 	sl->dev.groups = w1_slave_groups;
-	sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node,
-						sl->family->of_match_table);
+	sl->dev.of_node = of_find_matching_node(np, sl->family->of_match_table);
 
 	dev_set_name(&sl->dev, "%02x-%012llx",
 		 (unsigned int) sl->reg_num.family,