public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>, Andrew Lunn <andrew+netdev@lunn.ch>,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	David Miller <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute
Date: Fri, 27 Feb 2026 23:05:18 +0100	[thread overview]
Message-ID: <ce9f85d2-4f72-4b15-b868-210a8ced662d@gmail.com> (raw)
In-Reply-To: <799114be-1456-442b-b479-142e7ee9d254@gmail.com>

Currently the var member of struct dev_ext_attribute is used in a very
ugly way. Extend struct mdio_bus_stat_attr instead, what allows to
simplify the code and also slightly reduces memory footprint.

Note: Member addr is renamed to avoid a conflict in macro
      MDIO_BUS_STATS_ADDR_ATTR_DECL.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/mdio_bus.c | 45 +++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index afdf1ad6c0e..4fe9859369b 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -124,10 +124,16 @@ static void mdiobus_release(struct device *d)
 }
 
 struct mdio_bus_stat_attr {
-	int addr;
+	struct device_attribute attr;
+	int address;
 	unsigned int field_offset;
 };
 
+static struct mdio_bus_stat_attr *to_sattr(struct device_attribute *attr)
+{
+	return container_of(attr, struct mdio_bus_stat_attr, attr);
+}
+
 static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
 {
 	const char *p = (const char *)s + offset;
@@ -157,18 +163,14 @@ static ssize_t mdio_bus_stat_field_show(struct device *dev,
 					struct device_attribute *attr,
 					char *buf)
 {
+	struct mdio_bus_stat_attr *sattr = to_sattr(attr);
 	struct mii_bus *bus = to_mii_bus(dev);
-	struct mdio_bus_stat_attr *sattr;
-	struct dev_ext_attribute *eattr;
 	u64 val;
 
-	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	sattr = eattr->var;
-
-	if (sattr->addr < 0)
+	if (sattr->address < 0)
 		val = mdio_bus_get_global_stat(bus, sattr->field_offset);
 	else
-		val = mdio_bus_get_stat(&bus->stats[sattr->addr],
+		val = mdio_bus_get_stat(&bus->stats[sattr->address],
 					sattr->field_offset);
 
 	return sysfs_emit(buf, "%llu\n", val);
@@ -178,37 +180,31 @@ static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
 					       struct device_attribute *attr,
 					       char *buf)
 {
+	struct mdio_bus_stat_attr *sattr = to_sattr(attr);
 	struct mdio_device *mdiodev = to_mdio_device(dev);
 	struct mii_bus *bus = mdiodev->bus;
-	struct mdio_bus_stat_attr *sattr;
-	struct dev_ext_attribute *eattr;
 	int addr = mdiodev->addr;
 	u64 val;
 
-	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	sattr = eattr->var;
-
 	val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset);
 
 	return sysfs_emit(buf, "%llu\n", val);
 }
 
 #define MDIO_BUS_STATS_ATTR_DECL(field, file)				\
-static struct dev_ext_attribute dev_attr_mdio_bus_##field = {		\
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = {		\
 	.attr = { .attr = { .name = file, .mode = 0444 },		\
 		     .show = mdio_bus_stat_field_show,			\
 	},								\
-	.var = &((struct mdio_bus_stat_attr) {				\
-		-1, offsetof(struct mdio_bus_stats, field)		\
-	}),								\
+	.address = -1,							\
+	.field_offset = offsetof(struct mdio_bus_stats, field),		\
 };									\
-static struct dev_ext_attribute dev_attr_mdio_bus_device_##field = {	\
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = {	\
 	.attr = { .attr = { .name = file, .mode = 0444 },		\
 		     .show = mdio_bus_device_stat_field_show,		\
 	},								\
-	.var = &((struct mdio_bus_stat_attr) {				\
-		-1, offsetof(struct mdio_bus_stats, field)		\
-	}),								\
+	.address = -1,							\
+	.field_offset = offsetof(struct mdio_bus_stats, field),		\
 };
 
 #define MDIO_BUS_STATS_ATTR(field)					\
@@ -220,13 +216,12 @@ MDIO_BUS_STATS_ATTR(writes);
 MDIO_BUS_STATS_ATTR(reads);
 
 #define MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, file)		\
-static struct dev_ext_attribute dev_attr_mdio_bus_addr_##field##_##addr = { \
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_addr_##field##_##addr = { \
 	.attr = { .attr = { .name = file, .mode = 0444 },		\
 		     .show = mdio_bus_stat_field_show,			\
 	},								\
-	.var = &((struct mdio_bus_stat_attr) {				\
-		addr, offsetof(struct mdio_bus_stats, field)		\
-	}),								\
+	.address = addr,						\
+	.field_offset = offsetof(struct mdio_bus_stats, field),		\
 }
 
 #define MDIO_BUS_STATS_ADDR_ATTR(field, addr)				\
-- 
2.53.0



  reply	other threads:[~2026-02-27 22:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
2026-02-27 22:05 ` Heiner Kallweit [this message]
2026-02-27 22:06 ` [PATCH net-next 2/8] net: mdio: use macro __ATTR to simplify the code Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 4/8] net: phy: avoid extra casting in mdio_bus_get_stat Heiner Kallweit
2026-02-27 22:08 ` [PATCH net-next 5/8] net: mdio: constify attributes and attribute arrays Heiner Kallweit
2026-02-27 22:09 ` [PATCH net-next 6/8] net: mdio: use macro __ATTRIBUTE_GROUPS Heiner Kallweit
2026-02-27 22:10 ` [PATCH net-next 7/8] net: phy: inline helper mdio_bus_get_global_stat Heiner Kallweit
2026-02-27 22:11 ` [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct Heiner Kallweit
2026-03-05  8:31   ` Marek Szyprowski
2026-03-05  9:57     ` Heiner Kallweit
2026-03-03 12:30 ` [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c patchwork-bot+netdevbpf

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=ce9f85d2-4f72-4b15-b868-210a8ced662d@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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