Linux-USB Archive on
 help / color / Atom feed
* [PATCH] usb: Replace snprintf with scnprintf in gether_get_ifname
@ 2019-06-20  4:50 dmg
  0 siblings, 0 replies; only message in thread
From: dmg @ 2019-06-20  4:50 UTC (permalink / raw)
  To: linux-usb; +Cc: balbi, Daniel M German

From: Daniel M German <>

snprintf returns the actual length of the buffer created; however,
this is not the case if snprintf truncates its parameter.
See for a detailed explanation.
The current code correctly handles this case at the expense
of extra code in the return statement.

scnprintf does returns the actual length of the buffer created
making the ?: operator unnecessary in the return

This change does not alter the functionality of the code.

Signed-off-by: Daniel M German <>
 drivers/usb/gadget/function/u_ether.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 737bd77a575d..329b4d2861ee 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -1004,9 +1004,9 @@ int gether_get_ifname(struct net_device *net, char *name, int len)
 	int ret;
-	ret = snprintf(name, len, "%s\n", netdev_name(net));
+	ret = scnprintf(name, len, "%s\n", netdev_name(net));
-	return ret < len ? ret : len;
+	return ret;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20  4:50 [PATCH] usb: Replace snprintf with scnprintf in gether_get_ifname dmg

Linux-USB Archive on

Archives are clonable:
	git clone --mirror linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ \
	public-inbox-index linux-usb

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox