diff mbox series

[v3] net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register

Message ID 20220526145208.25673-1-linmq006@gmail.com (mailing list archive)
State Accepted
Commit 02ded5a173619b11728b8bf75a3fd995a2c1ff28
Delegated to: Netdev Maintainers
Headers show
Series [v3] net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Miaoqian Lin May 26, 2022, 2:52 p.m. UTC
of_get_child_by_name() returns a node pointer with refcount
incremented, we should use of_node_put() on it when done.

mv88e6xxx_mdio_register() pass the device node to of_mdiobus_register().
We don't need the device node after it.

Add missing of_node_put() to avoid refcount leak.

Fixes: a3c53be55c95 ("net: dsa: mv88e6xxx: Support multiple MDIO busses")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- Add fixes tag.
changes in v3:
- Move of_node_put() statement to cover normal path.
- Update commit message.

I do cross-check to determine we should release the node after
of_mdiobus_register(), refer to functions like lan78xx_mdio_init(),
ave_init() and ag71xx_mdio_probe().

v1 link: https://lore.kernel.org/r/20220526083748.39816-1-linmq006@gmail.com/
v2 link: https://lore.kernel.org/all/20220526112415.13835-1-linmq006@gmail.com/
---
 drivers/net/dsa/mv88e6xxx/chip.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Marek Behún May 26, 2022, 4:23 p.m. UTC | #1
On Thu, 26 May 2022 18:52:08 +0400
Miaoqian Lin <linmq006@gmail.com> wrote:

> of_get_child_by_name() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when done.
> 
> mv88e6xxx_mdio_register() pass the device node to of_mdiobus_register().
> We don't need the device node after it.
> 
> Add missing of_node_put() to avoid refcount leak.
> 
> Fixes: a3c53be55c95 ("net: dsa: mv88e6xxx: Support multiple MDIO busses")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - Add fixes tag.
> changes in v3:
> - Move of_node_put() statement to cover normal path.
> - Update commit message.
> 
> I do cross-check to determine we should release the node after
> of_mdiobus_register(), refer to functions like lan78xx_mdio_init(),
> ave_init() and ag71xx_mdio_probe().
> 
> v1 link: https://lore.kernel.org/r/20220526083748.39816-1-linmq006@gmail.com/
> v2 link: https://lore.kernel.org/all/20220526112415.13835-1-linmq006@gmail.com/
> ---
>  drivers/net/dsa/mv88e6xxx/chip.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
> index 5d2c57a7c708..0b49d243e00b 100644
> --- a/drivers/net/dsa/mv88e6xxx/chip.c
> +++ b/drivers/net/dsa/mv88e6xxx/chip.c
> @@ -3960,6 +3960,7 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
>  	 */
>  	child = of_get_child_by_name(np, "mdio");
>  	err = mv88e6xxx_mdio_register(chip, child, false);
> +	of_node_put(child);
>  	if (err)
>  		return err;
>  

Reviewed-by: Marek Behún <kabel@kernel.org>
patchwork-bot+netdevbpf@kernel.org May 27, 2022, 7:10 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 26 May 2022 18:52:08 +0400 you wrote:
> of_get_child_by_name() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when done.
> 
> mv88e6xxx_mdio_register() pass the device node to of_mdiobus_register().
> We don't need the device node after it.
> 
> Add missing of_node_put() to avoid refcount leak.
> 
> [...]

Here is the summary with links:
  - [v3] net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register
    https://git.kernel.org/netdev/net/c/02ded5a17361

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 5d2c57a7c708..0b49d243e00b 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -3960,6 +3960,7 @@  static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
 	 */
 	child = of_get_child_by_name(np, "mdio");
 	err = mv88e6xxx_mdio_register(chip, child, false);
+	of_node_put(child);
 	if (err)
 		return err;