[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2d5322bce3f450da329e5e146bf0a850afa55fe4@linux.dev>
Date: Fri, 13 Jun 2025 02:06:45 +0000
From: "Yajun Deng" <yajun.deng@...ux.dev>
To: "Andrew Lunn" <andrew@...n.ch>
Cc: hkallweit1@...il.com, linux@...linux.org.uk, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH RESEND net-next v2] net: phy: Add c45_phy_ids sysfs
directory entry
June 12, 2025 at 11:31 PM, "Andrew Lunn" <andrew@...n.ch> 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
>
Powered by blists - more mailing lists