Thread (3 messages) 3 messages, 3 authors, 2026-02-01

Re: [PATCH net-next] net: bridge: use sysfs_emit instead of sprintf

From: Ido Schimmel <idosch@nvidia.com>
Date: 2026-02-01 15:19:21
Also in: bridge, lkml

On Sat, Jan 31, 2026 at 04:53:09PM +0000, David Corvaglia wrote:
Replace sprintf with sysfs_emit in sysfs show() methods as outlined in
Documentation/filesystems/sysfs.rst. sysfs_emit is preferred to sprintf 
in sysfs show() methods as it is safer with buffer handling.

Signed-off-by: David Corvaglia <redacted>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>

But the patch is introducing a few alignment issues and it would be good
to fix them in v2. See below.

[...]
quoted hunk ↗ jump to hunk
@@ -87,7 +87,7 @@ static DEVICE_ATTR_RW(forward_delay);
 static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
 			       char *buf)
 {
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(to_bridge(d)->hello_time));
Here
quoted hunk ↗ jump to hunk
 }
 
@@ -108,7 +108,7 @@ static DEVICE_ATTR_RW(hello_time);
 static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
 			    char *buf)
 {
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(to_bridge(d)->max_age));
Here
 }
 
[...]
quoted hunk ↗ jump to hunk
 static int set_group_fwd_mask(struct net_bridge *br, unsigned long val,
@@ -200,7 +200,7 @@ static ssize_t priority_show(struct device *d, struct device_attribute *attr,
 			     char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
Here
 }
[...]
quoted hunk ↗ jump to hunk
@@ -425,7 +425,7 @@ static ssize_t multicast_query_use_ifaddr_show(struct device *d,
 					       char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
Here
 }
quoted hunk ↗ jump to hunk
@@ -583,7 +583,7 @@ static ssize_t multicast_last_member_interval_show(
 	struct device *d, struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval));
Here
quoted hunk ↗ jump to hunk
 }
 
@@ -606,7 +606,7 @@ static ssize_t multicast_membership_interval_show(
 	struct device *d, struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval));
Here
quoted hunk ↗ jump to hunk
 }
 
@@ -630,7 +630,7 @@ static ssize_t multicast_querier_interval_show(struct device *d,
 					       char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval));
Here
quoted hunk ↗ jump to hunk
 }
 
@@ -654,7 +654,7 @@ static ssize_t multicast_query_interval_show(struct device *d,
 					     char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval));
Here
 }
[...]
quoted hunk ↗ jump to hunk
@@ -727,7 +727,7 @@ static ssize_t multicast_stats_enabled_show(struct device *d,
 {
 	struct net_bridge *br = to_bridge(d);
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
Here
 }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help