[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <737294c1-258f-4780-80f8-e7a72e887f8b@lunn.ch>
Date: Thu, 12 Jun 2025 17:31:46 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Yajun Deng <yajun.deng@...ux.dev>
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
> +#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?
> +#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.
> +
> +#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.
Andrew
---
pw-bot: cr
Powered by blists - more mailing lists