Re: [RFC PATCH 2/2] net: include: mii: Refactor: Use BIT() for ADVERTISE_* bits

From: Andrew Lunn
Date: Wed Jun 05 2024 - 12:48:23 EST


On Wed, Jun 05, 2024 at 04:47:27PM +0200, Csókás Bence wrote:
> Hi!
>
> On 6/5/24 16:13, Vladimir Oltean wrote:
> > On Wed, Jun 05, 2024 at 02:16:49PM +0200, Csókás, Bence wrote:
> > > Replace hex values with BIT() and GENMASK() for readability
> > >
> > > Cc: trivial@xxxxxxxxxx
> > >
> > > Signed-off-by: "Csókás, Bence" <csokas.bence@xxxxxxxxx>
> > > ---
> >
> > You can't use BIT() and GENMASK() in headers exported to user space.
> >
> > I mean you can, but the BIT() and GENMASK() macros themselves aren't
> > exported to user space, and you would break any application which used
> > values dependent on them.
> >
>
> I thought the vDSO headers (which currently hold the definition for `BIT()`)
> *are* exported. Though `GENMASK()`, and the headers which would normally
> include vdso/bits.h, might not be... But then again, is uapi/linux/mii.h
> itself even exported?

uapi .... I would expect everything below that is considered exported.

Take a look at the sources for mii-tool.c:

if (bmcr & BMCR_ANENABLE) {
if (bmsr & BMSR_ANEGCOMPLETE) {
if (advert & lkpar) {
strcat(buf, (lkpar & LPA_LPACK) ?
"negotiated" : "no autonegotiation,");
strcat(buf, media_list(advert & lkpar, bmcr2 & lpa2>>2, 1));
strcat(buf, ", ");
} else {
strcat(buf, "autonegotiation failed, ");
}
} else if (bmcr & BMCR_ANRESTART) {
strcat(buf, "autonegotiation restarted, ");
}
} else {
sprintf(buf+strlen(buf), "%s Mbit, %s duplex, ",
((bmcr2 & (ADVERTISE_1000HALF | ADVERTISE_1000FULL)) & lpa2 >> 2)
? "1000"
: (bmcr & BMCR_SPEED100) ? "100" : "10",
(bmcr & BMCR_FULLDPLX) ? "full" : "half");
}
strcat(buf, (bmsr & BMSR_LSTATUS) ? "link ok" : "no link");

So they are actually used as well. Try compiling this with your
changes made.

Andrew