From: Andrew Lunn <andrew@lunn.ch>
To: Yajun Deng <yajun.deng@linux.dev>
Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND net-next v2] net: phy: Add c45_phy_ids sysfs directory entry
Date: Thu, 12 Jun 2025 17:31:46 +0200 [thread overview]
Message-ID: <737294c1-258f-4780-80f8-e7a72e887f8b@lunn.ch> (raw)
In-Reply-To: <20250612143532.4689-1-yajun.deng@linux.dev>
> +#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
next prev parent reply other threads:[~2025-06-12 15:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-12 14:35 Yajun Deng
2025-06-12 15:31 ` Andrew Lunn [this message]
2025-06-13 2:06 ` Yajun Deng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=737294c1-258f-4780-80f8-e7a72e887f8b@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yajun.deng@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®