diff options
author | Daniel M German <dmg@turingmachine.org> | 2019-06-20 06:50:38 +0200 |
---|---|---|
committer | Felipe Balbi <felipe.balbi@linux.intel.com> | 2019-06-20 07:53:11 +0200 |
commit | 37e444c8296c14cb5768a1197b24cfc07ee8e0cd (patch) | |
tree | 965d31cbe37f6053012fb00b2ebf545238c0df50 /drivers/usb | |
parent | usb: gadget: ether: Fix race between gether_disconnect and rx_submit (diff) | |
download | linux-37e444c8296c14cb5768a1197b24cfc07ee8e0cd.tar.xz linux-37e444c8296c14cb5768a1197b24cfc07ee8e0cd.zip |
usb: Replace snprintf with scnprintf in gether_get_ifname
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>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/function/u_ether.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 2929bb47a618..fbe96ef1ac7a 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -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); |