Skip to contentSkip to conversation

net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()

PATCH In review Liang He 2 participants 5 messages Sep 15, 2022 – Sep 21, 2022

Subsystems (3)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()

In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration for_each_child_of_node() as it will automatically increase and decrease the 'child'.

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

---
it will be safe to call of_node_put() at the end of the function as
the of_node_put() can handle NULL.

 drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_main.c +2 -0
index ede3e53b9790..a895862b4821 100644
@@ -368,6 +368,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)
 	if (!sw->np)
 		return 0;
 
+	of_node_get(sw->np);
 	ports = of_find_node_by_name(sw->np, "ports");
 
 	for_each_child_of_node(ports, node) {
@@ -417,6 +418,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)
 	}
 
 out:
+	of_node_put(node);
 	of_node_put(ports);
 	return err;
 }
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 9 lines · On Thu, 15 Sep 2022 12:06:55 +0800 Liang He wrote:

In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration for_each_child_of_node() as it will automatically increase and decrease the 'child'.

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

Please repost and CC all the authors of the patch under Fixes.

author
#2 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 15 Sep 2022 12:06:55 +0800 Liang He wrote:

In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration for_each_child_of_node() as it will automatically increase and decrease the 'child'.

Quoted 4 lines
Quoted 2 lines
Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

Please repost and CC all the authors of the patch under Fixes.

Thanks for your reply, Jakub

As I was the only one author, you mean following tag format:

""

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")
CC Liang He <[email protected]>

""

If there is anything wrong, sorry for this trouble.

Thanks,

Liang

maintainer
#3 lore raw
Quoted 14 lines · On Wed, 21 Sep 2022 17:02:52 +0800 (CST) Liang He wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 15 Sep 2022 12:06:55 +0800 Liang He wrote:

In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration for_each_child_of_node() as it will automatically increase and decrease the 'child'.

Quoted 4 lines
Quoted 2 lines
Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

Please repost and CC all the authors of the patch under Fixes.

Quoted 8 lines

Thanks for your reply, Jakub

As I was the only one author, you mean following tag format:

""

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")
CC Liang He <[email protected]>

No, no, CC the authors of the patch under fixes, which is to say - the patch which introduced the problem. The fixes tag you have is:

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

so:

commit 52323ef75414d60b17f683076833eb55a6bffa2b

Author: Oleksandr Mazur <[email protected]>
Date:   Tue Jul 19 13:57:16 2022 +0300

net: marvell: prestera: add phylink support

For SFP port prestera driver will use kernel phylink infrastucture to configure port mode based on the module that has beed inserted

I was asking to also CC Yevhen and Oleksandr. Taras seems already CCed.

author
#4 lore raw
Quoted 49 lines · Jakub Kicinski
Quoted 14 lines · On Wed, 21 Sep 2022 17:02:52 +0800 (CST) Liang He wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 15 Sep 2022 12:06:55 +0800 Liang He wrote:

In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration for_each_child_of_node() as it will automatically increase and decrease the 'child'.

Quoted 4 lines
Quoted 2 lines
Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

Please repost and CC all the authors of the patch under Fixes.

Quoted 8 lines

Thanks for your reply, Jakub

As I was the only one author, you mean following tag format:

""

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")
CC Liang He <[email protected]>

No, no, CC the authors of the patch under fixes, which is to say - the patch which introduced the problem. The fixes tag you have is:

Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

so:

commit 52323ef75414d60b17f683076833eb55a6bffa2b

Author: Oleksandr Mazur <[email protected]>
Date:   Tue Jul 19 13:57:16 2022 +0300

net: marvell: prestera: add phylink support

For SFP port prestera driver will use kernel phylink infrastucture to configure port mode based on the module that has beed inserted

Quoted 1 line

I was asking to also CC Yevhen and Oleksandr. Taras seems already CCed.

Thanks very much, I will follow this rule in my future patches.

Liang