[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <612d5964-6034-4188-8da5-53f3f38a25e4@lunn.ch>
Date: Tue, 13 Jun 2023 18:18:58 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Jianhui Zhao <zhaojh329@...il.com>
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 V2] net: phy: Add sysfs attribute for PHY c45 identifiers.
> +#define DEVICE_ATTR_C45_ID(i) \
> +static ssize_t \
> +phy_c45_id##i##_show(struct device *dev, \
> + struct device_attribute *attr, char *buf) \
> +{ \
> + struct phy_device *phydev = to_phy_device(dev); \
> +\
> + if (!phydev->is_c45) \
> + return 0; \
> +\
> + return sprintf(buf, "0x%.8lx\n", \
> + (unsigned long)phydev->c45_ids.device_ids[i]); \
> +} \
That is not the most efficient implementation.
You can have one generic
static ssize_t phy_c45_id_show(struct device *dev, char *buf, int i)
{
struct phy_device *phydev = to_phy_device(dev);
if (!phydev->is_c45)
return 0;
return sprintf(buf, "0x%.8lx\n",
(unsigned long)phydev->c45_ids.device_ids[i]);
}
And then your macros becomes
#define DEVICE_ATTR_C45_ID(i) \
static ssize_t \
phy_c45_id##i##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
return phy_c45_id_show(dev, buf, i); \
}
Andrew
---
pw-bot: cr
Powered by blists - more mailing lists