Re: [PATCH V3 2/4 net-next?] net: dsa: b53: prefer CPU port 8 for Northstar devices

[email protected]
Newsgroups org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing NULL pointer check on the result of `dsa_to_port()` before passing it to `dsa_port_is_cpu()`, leading to a potential NULL pointer dereference.
--

--- Patch [2]: [PATCH V3 2/4 net-next?] net: dsa: b53: prefer CPU port 8 for Northstar devices ---
commit 2ae0d011f243e38dabfab275559b868d62bf66f6
Author: Rafał Miłecki <[email protected]>

net: dsa: b53: prefer CPU port 8 for Northstar devices

This patch prefers CPU port 8 if available for Northstar devices. Ports
5 and 7 have limitations with CPU trapping features compared to port 8.

> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 5fd8362d04304..052812d2faa93 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c

[ ... ]

> +static struct dsa_port *b53_preferred_default_local_cpu_port(struct dsa_switch *ds)
> +{
> +	struct b53_device *dev = ds->priv;
> +	struct dsa_port *cpu_dp;

[ ... ]

> +	if (is5301x(dev)) {
> +		cpu_dp = dsa_to_port(ds, B53_CPU_PORT);
> +
> +		if (dsa_port_is_cpu(cpu_dp))

[Severity: High]
Does this code risk a NULL pointer dereference during device probe?

If a Northstar SoC is configured without port 8 (for example, in setups
using only port 5 or 7 as the CPU port), dsa_to_port() will return NULL.
The dsa_port_is_cpu() function dereferences the passed port pointer directly:

include/net/dsa.h:dsa_port_is_cpu() {
	return port->type == DSA_PORT_TYPE_CPU;
}

Passing NULL to dsa_port_is_cpu() would cause a panic. Could cpu_dp be
checked for NULL before calling dsa_port_is_cpu()?

> +			return cpu_dp;
> +	}
> +
> +	return NULL;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.