Re: [PATCH RESEND net-next v2] net: phy: Add c45_phy_ids sysfs directory entry

From: Yajun Deng
Date: Thu Jun 12 2025 - 22:07:08 EST


June 12, 2025 at 11:31 PM, "Andrew Lunn" <andrew@xxxxxxx> wrote:



>
> >
> > +#define MMD_INDICES \
> >
> > + _(1) _(2) _(3) _(4) _(5) _(6) _(7) _(8) \
> >
> > + _(9) _(10) _(11) _(12) _(13) _(14) _(15) _(16) \
> >
> > + _(17) _(18) _(19) _(20) _(21) _(22) _(23) _(24) \
> >
> > + _(25) _(26) _(27) _(28) _(29) _(30) _(31)
> >
>
> Is 0 not valid?
>

Yes, the MMD starts at 1. See "include/uapi/linux/mdio.h".

> >
> > +#define MMD_DEVICE_ID_ATTR(n) \
> >
> > +static ssize_t mmd##n##_device_id_show(struct device *dev, \
> >
> > + struct device_attribute *attr, char *buf) \
> >
> > +{ \
> >
> > + struct phy_device *phydev = to_phy_device(dev); \
> >
> > + return sysfs_emit(buf, "0x%.8lx\n", \
> >
> > + (unsigned long)phydev->c45_ids.device_ids[n]); \
> >
> > +} \
> >
> > +static DEVICE_ATTR_RO(mmd##n##_device_id)
> >
>
> This macro magic i can follow, you see this quite a bit in the kernel.
>

Okay.

> >
> > +
> >
> > +#define _(x) MMD_DEVICE_ID_ATTR(x);
> >
> > +MMD_INDICES
> >
> > +#undef _
> >
> > +
> >
> > +static struct attribute *phy_mmd_attrs[] = {
> >
> > + #define _(x) &dev_attr_mmd##x##_device_id.attr,
> >
> > + MMD_INDICES
> >
> > + #undef _
> >
> > + NULL
> >
> > +};
> >
>
> If i squint at this enough, i can work it out, but generally a much
>
> more readable KISS approach is taken, of just invoking a macro 32
>
> times. See mdio_bus.c as an example.
>

Okay.

> Andrew
>
> ---
>
> pw-bot: cr
>