public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Ma Ke <make24@iscas.ac.cn>
Cc: olteanv@gmail.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	florian.fainelli@broadcom.com, stephen@networkplumber.org,
	robh@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] net: dsa: Fix error handling in dsa_port_parse_of
Date: Fri, 21 Nov 2025 14:40:58 +0100	[thread overview]
Message-ID: <aec90f22-da8d-4d03-bde6-43fa2bee2e25@lunn.ch> (raw)
In-Reply-To: <20251121035130.16020-1-make24@iscas.ac.cn>

On Fri, Nov 21, 2025 at 11:51:30AM +0800, Ma Ke wrote:
> When of_find_net_device_by_node() successfully acquires a reference to
> a network device but the subsequent call to dsa_port_parse_cpu()
> fails, dsa_port_parse_of() returns without releasing the reference
> count on the network device.
> 
> of_find_net_device_by_node() increments the reference count of the
> returned structure, which should be balanced with a corresponding
> put_device() when the reference is no longer needed.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 6ca80638b90c ("net: dsa: Use conduit and user terms")

Why did you pick this commit for the Fixes tag?

> @@ -1259,7 +1260,13 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
>  			return -EPROBE_DEFER;
>  
>  		user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL);
> -		return dsa_port_parse_cpu(dp, conduit, user_protocol);
> +		err = dsa_port_parse_cpu(dp, conduit, user_protocol);
> +		if (err) {
> +			put_device(conduit);
> +			return err;
> +		}
> +
> +		return 0;
>  	}
>  
>  	if (link)
> -- 
> 2.17.1

You can simplify this to:

		err = dsa_port_parse_cpu(dp, conduit, user_protocol);
		if (err) 
			put_device(conduit);

		return err;

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

    Andrew

---
pw-bot: cr

  reply	other threads:[~2025-11-21 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21  3:51 [PATCH] net: dsa: Fix error handling in dsa_port_parse_of Ma Ke
2025-11-21 13:40 ` Andrew Lunn [this message]
2025-11-21 18:07 ` kernel test robot
2025-11-21 19:13 ` kernel test robot
2025-11-22 19:58 ` Markus Elfring
2025-11-23  6:22   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aec90f22-da8d-4d03-bde6-43fa2bee2e25@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox