Skip to contentSkip to conversation

staging: octeon: convert all uses of strlcpy to strscpy in ethernet-mdio.c

PATCH Superseded Phillip Potter 3 participants 3 messages Feb 7, 2021 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: octeon: convert all uses of strlcpy to strscpy in ethernet-mdio.c

Convert three calls to strlcpy inside the cvm_oct_get_drvinfo function to strscpy calls. Fixes a style warning.

---
 drivers/staging/octeon/ethernet-mdio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/octeon/ethernet-mdio.c +3 -3
index b0fd083a5bf2..b3049108edc4 100644
@@ -21,9 +21,9 @@
 static void cvm_oct_get_drvinfo(struct net_device *dev,
 				struct ethtool_drvinfo *info)
 {
-	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
-	strlcpy(info->version, UTS_RELEASE, sizeof(info->version));
-	strlcpy(info->bus_info, "Builtin", sizeof(info->bus_info));
+	strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
+	strscpy(info->version, UTS_RELEASE, sizeof(info->version));
+	strscpy(info->bus_info, "Builtin", sizeof(info->bus_info));
 }
 
 static int cvm_oct_nway_reset(struct net_device *dev)
Signature · 1 line
2.29.2
maintainer
#1 lore raw
Quoted 2 lines · Phillip Potter

Convert three calls to strlcpy inside the cvm_oct_get_drvinfo function to strscpy calls. Fixes a style warning.

Is it really safe to do this type of conversion here? If so, you need to provide evidence of it in the changelog, otherwise we could just do a search/replace across the whole kernel and be done with it :)

thanks,

greg k-h

#2 lore raw
Quoted 5 lines · Greg KH
Quoted 2 lines · Phillip Potter

Convert three calls to strlcpy inside the cvm_oct_get_drvinfo function to strscpy calls. Fixes a style warning.

Is it really safe to do this type of conversion here?

Yes. No locks are taken by either strlcpy or strscpy, and the conversion is only done where the return value is unused.

strscpy is:

lib/string.c: * Preferred to strlcpy() since the API doesn't require reading memory lib/string.c- * from the src string beyond the specified "count" bytes, and since lib/string.c: * the return value is easier to error-check than strlcpy()'s. lib/string.c- * In addition, the implementation is robust to the string changing out lib/string.c: * from underneath it, unlike the current strlcpy() implementation.

Quoted 3 lines

If so, you need
to provide evidence of it in the changelog, otherwise we could just do a search/replace across the whole kernel and be done with it :)

Yes please.

There's a cocci script for that in commit 75b1a8f9d62e ("ALSA: Convert strlcpy to strscpy when return value is unused")