Re: [PATCH net-next v9 3/3] net: dsa: yt921x: Add support for Motorcomm YT921x

From: Andrew Lunn
Date: Tue Sep 16 2025 - 20:08:55 EST


> > +static int yt921x_reg_mdio_read(void *context, u32 reg, u32 *valp)
> > +{
> > + struct yt921x_reg_mdio *mdio = context;
> > + struct mii_bus *bus = mdio->bus;
> > + int addr = mdio->addr;
> > + u32 reg_addr;
> > + u32 reg_data;
> > + u32 val;
> > + int res;
> > +
> > + /* Hold the mdio bus lock to avoid (un)locking for 4 times */
> > + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
>
> Andrew, are you satisfied with this lock?

This is O.K. You snipped too much context. As the comment says, the
code is about to do 4 MDIO bus transactions. Each will take and
release the lock. By taking it now, and then using the unlocked
version for read/write, it will make it a tiny bit faster. The time to
do the bus transaction will however dominate.

> Perhaps I missed some part of
> the conversation, but didn't you say "leave the mdio lock alone"?

Yes, i did, but then the mdio lock was being abused as a DSA driver
lock. The DSA driver now has its own lock. So what we see above is
purely an optimisation, not a locking scheme.

Andrew