[PATCH v2] w1: Add missing of_node_put() and of_node_get()

From: Liang He
Date: Tue Jun 21 2022 - 23:42:56 EST


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.

Signed-off-by: Liang He <windhl@xxxxxxx>
---
changelog:

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

drivers/w1/w1.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index f2ae2e563dc5..378996d947cc 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -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;
}
--
2.25.1