public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Jakub Kicinski <kuba@kernel.org>
Cc: lxu@maxlinear.com, hkallweit1@gmail.com, yweng@maxlinear.com,
	ajayaraman@maxlinear.com, andrew@lunn.ch, netdev@vger.kernel.org,
	bxu@maxlinear.com, olteanv@gmail.com, krzk+dt@kernel.org,
	linux-kernel@vger.kernel.org, lrosu@maxlinear.com,
	chad@monroe.io, conor+dt@kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, edumazet@google.com, pabeni@redhat.com,
	cezary.wilmanski@adtran.com, davem@davemloft.net,
	john@phrozen.org, frankwu@gmx.de, jpovazanec@maxlinear.com,
	linux@armlinux.org.uk, fchan@maxlinear.com, horms@kernel.org
Subject: Re: [net-next,v11,4/4] net: dsa: add basic initial driver for MxL862xx switches
Date: Sun, 1 Feb 2026 00:55:22 +0000	[thread overview]
Message-ID: <aX6keghdVMI-A6Fq@makrotopia.org> (raw)
In-Reply-To: <20260131175243.1122906-2-kuba@kernel.org>

On Sat, Jan 31, 2026 at 09:52:44AM -0800, Jakub Kicinski wrote:
> > [...]
> > +/**
> > + * struct mxl862xx_bridge_port_alloc - Bridge Port Allocation
> > + * @bridge_port_id: If the bridge port allocation is successful, a valid ID
> > + *                  will be returned in this field. Otherwise, INVALID_HANDLE
> > + *                  is returned. For bridge port free, this field should
> > + *                  contain a valid ID returned by the bridge port allocation.
> > + *
> > + * Used by MXL862XX_BRIDGE_PORT_ALLOC and MXL862XX_BRIDGE_PORT_FREE.
> > + */
> > +struct mxl862xx_bridge_port_alloc {
> > +	__le16 bridge_port_id;
> > +};
> 
> Is the __packed attribute missing here? The similar struct
> mxl862xx_bridge_alloc has __packed, and both structures have identical
> layout with a single __le16 field. Both are used for firmware
> communication where padding could break the protocol.
> 
> [Jakub] please remove the __packed attribute on structs which are
>         naturally packed according to C rules.

I'll do that for the upcoming submission of v12, but wonder if using
'#pragma pack(push, 1)' around the complete API header file wouldn't be
the better option, as anyway *everything* should always be packed there,
as the switch firmware expects data byte-aligned.

> > [...]
> > +static int mxl862xx_setup_mdio(struct dsa_switch *ds)
> > +{
> > +	struct mxl862xx_priv *priv = ds->priv;
> > +	struct device *dev = ds->dev;
> > +	struct device_node *mdio_np;
> > +	struct mii_bus *bus;
> > +	static int idx;
> > +	int ret;
> > +
> > +	bus = devm_mdiobus_alloc(dev);
> > +	if (!bus)
> > +		return -ENOMEM;
> > +
> > +	bus->priv = priv;
> > +	ds->user_mii_bus = bus;
> > +	bus->name = KBUILD_MODNAME "-mii";
> > +	snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++);
> 
> Can concurrent probes race on the idx variable?
> 
> The static int idx is shared across all driver instances and accessed
> without synchronization. If multiple instances of this driver are probed
> concurrently on different CPU cores, they could race on the idx++
> operation potentially leading to duplicate MII bus IDs. MII bus IDs must
> be unique system-wide.
> 

Do you think it's worth to fix this also in other drivers which follow
the same pattern? (bcm_sf2, mt7530 and mv88e6xxx if OF node is NULL --
if there is an OF node it uses %pOF, and I'm not sure that's such a good
idea either)

Apart from being racy, this also means the MII bus name depends on probe
order which isn't very nice either. Using

snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(priv->dev));

may result in a slightly more ugly-looking, but predictable and
non-racy (ie. always unique) name.

Other than that there is also
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d.%d",
         KBUILD_MODNAME, ds->dst->index, ds->index);

The real question here is if we consider MII bus names to be ABI,
ie. if they should never change once a driver is part of the kernel.

  reply	other threads:[~2026-02-01  0:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31  0:10 [PATCH net-next v11 0/4] net: dsa: initial support for MaxLinear MxL862xx switches Daniel Golle
2026-01-31  0:10 ` [PATCH net-next v11 1/4] dt-bindings: net: dsa: add MaxLinear MxL862xx Daniel Golle
2026-01-31  0:11 ` [PATCH net-next v11 2/4] net: dsa: add tag format for MxL862xx switches Daniel Golle
2026-01-31  0:11 ` [PATCH net-next v11 3/4] net: mdio: add unlocked mdiodev C45 bus accessors Daniel Golle
2026-02-02 11:03   ` Russell King (Oracle)
2026-01-31  0:11 ` [PATCH net-next v11 4/4] net: dsa: add basic initial driver for MxL862xx switches Daniel Golle
2026-01-31 17:52   ` [net-next,v11,4/4] " Jakub Kicinski
2026-02-01  0:55     ` Daniel Golle [this message]
2026-02-02 11:10       ` Russell King (Oracle)
2026-02-02 11:15         ` Daniel Golle
2026-02-02  9:44     ` Vladimir Oltean
2026-02-02 10:49       ` Daniel Golle
2026-02-02 11:15         ` Vladimir Oltean

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=aX6keghdVMI-A6Fq@makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=ajayaraman@maxlinear.com \
    --cc=andrew@lunn.ch \
    --cc=bxu@maxlinear.com \
    --cc=cezary.wilmanski@adtran.com \
    --cc=chad@monroe.io \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=fchan@maxlinear.com \
    --cc=frankwu@gmx.de \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=john@phrozen.org \
    --cc=jpovazanec@maxlinear.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lrosu@maxlinear.com \
    --cc=lxu@maxlinear.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=yweng@maxlinear.com \
    /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