public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Omer Zalman <omerzalman42@gmail.com>
To: oliver@neukum.org
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, linux-usb@vger.kernel.org,
	netdev@vger.kernel.org, Omer Zalman <omerzalman42@gmail.com>
Subject: [PATCH 1/2] net: usb: cdc_ncm: convert sysfs show() callbacks to sysfs_emit()
Date: Tue, 17 Mar 2026 23:06:31 -0500	[thread overview]
Message-ID: <20260318040632.69531-1-omerzalman42@gmail.com> (raw)

sysfs_emit() was introduced in v5.10 as the preferred replacement for
sprintf() in sysfs show() handlers. It bounds output to PAGE_SIZE and
avoids potential buffer overruns.

Convert all show() callbacks and the NCM_PARM_ATTR macro from sprintf()
to sysfs_emit().

Signed-off-by: Omer Zalman <omerzalman42@gmail.com>
---
 drivers/net/usb/cdc_ncm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 7057c6c0cfc6..6fcb4d711a64 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -204,7 +204,7 @@ static ssize_t min_tx_pkt_show(struct device *d,
 	struct usbnet *dev = netdev_priv(to_net_dev(d));
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
 
-	return sprintf(buf, "%u\n", ctx->min_tx_pkt);
+	return sysfs_emit(buf, "%u\n", ctx->min_tx_pkt);
 }
 
 static ssize_t rx_max_show(struct device *d,
@@ -213,7 +213,7 @@ static ssize_t rx_max_show(struct device *d,
 	struct usbnet *dev = netdev_priv(to_net_dev(d));
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
 
-	return sprintf(buf, "%u\n", ctx->rx_max);
+	return sysfs_emit(buf, "%u\n", ctx->rx_max);
 }
 
 static ssize_t tx_max_show(struct device *d,
@@ -222,7 +222,7 @@ static ssize_t tx_max_show(struct device *d,
 	struct usbnet *dev = netdev_priv(to_net_dev(d));
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
 
-	return sprintf(buf, "%u\n", ctx->tx_max);
+	return sysfs_emit(buf, "%u\n", ctx->tx_max);
 }
 
 static ssize_t tx_timer_usecs_show(struct device *d,
@@ -231,7 +231,7 @@ static ssize_t tx_timer_usecs_show(struct device *d,
 	struct usbnet *dev = netdev_priv(to_net_dev(d));
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
 
-	return sprintf(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC);
+	return sysfs_emit(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC);
 }
 
 static ssize_t min_tx_pkt_store(struct device *d,
@@ -313,7 +313,7 @@ static ssize_t ndp_to_end_show(struct device *d, struct device_attribute *attr,
 	struct usbnet *dev = netdev_priv(to_net_dev(d));
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
 
-	return sprintf(buf, "%c\n", ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END ? 'Y' : 'N');
+	return sysfs_emit(buf, "%c\n", ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END ? 'Y' : 'N');
 }
 
 static ssize_t ndp_to_end_store(struct device *d,  struct device_attribute *attr, const char *buf, size_t len)
@@ -362,7 +362,7 @@ static ssize_t cdc_ncm_show_##name(struct device *d, struct device_attribute *at
 { \
 	struct usbnet *dev = netdev_priv(to_net_dev(d)); \
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; \
-	return sprintf(buf, format "\n", tocpu(ctx->ncm_parm.name));	\
+	return sysfs_emit(buf, format "\n", tocpu(ctx->ncm_parm.name));	\
 } \
 static DEVICE_ATTR(name, 0444, cdc_ncm_show_##name, NULL)
 
-- 
2.39.5 (Apple Git-154)


             reply	other threads:[~2026-03-18  4:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18  4:06 Omer Zalman [this message]
2026-03-18  4:06 ` [PATCH 2/2] net: usb: cdc_ncm: prevent silent u16 truncation in min_tx_pkt_store() Omer Zalman
2026-03-18  6:37   ` Greg KH
2026-03-18  6:36 ` [PATCH 1/2] net: usb: cdc_ncm: convert sysfs show() callbacks to sysfs_emit() Greg KH

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=20260318040632.69531-1-omerzalman42@gmail.com \
    --to=omerzalman42@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oliver@neukum.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