usb: Replace snprintf with scnprintf in gether_get_ifname
authorDaniel M German <dmg@turingmachine.org>
Thu, 20 Jun 2019 04:50:38 +0000 (21:50 -0700)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 20 Jun 2019 05:53:11 +0000 (08:53 +0300)
snprintf returns the actual length of the buffer created; however,
this is not the case if snprintf truncates its parameter.
See https://lwn.net/Articles/69419/ 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
statement.

This change does not alter the functionality of the code.

Signed-off-by: Daniel M German <dmg@turingmachine.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/gadget/function/u_ether.c

index 2929bb4..fbe96ef 100644 (file)
@@ -1006,9 +1006,9 @@ int gether_get_ifname(struct net_device *net, char *name, int len)
        int ret;
 
        rtnl_lock();
-       ret = snprintf(name, len, "%s\n", netdev_name(net));
+       ret = scnprintf(name, len, "%s\n", netdev_name(net));
        rtnl_unlock();
-       return ret < len ? ret : len;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(gether_get_ifname);