]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wl1251: Replace strncpy with strscpy in wl1251_acx_fw_version
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 11 Jan 2026 13:42:57 +0000 (14:42 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 12 Jan 2026 18:43:15 +0000 (19:43 +0100)
strncpy() is deprecated [1] for NUL-terminated destination buffers since
it does not guarantee NUL termination. Remove the manual NUL termination
and replace strncpy() with strscpy() to ensure NUL termination of the
destination buffer.

Using strscpy_pad() to retain the NUL-padding behavior of strncpy() is
not needed because ->fw_ver is only used as a C-string.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260111134301.598839-1-thorsten.blum@linux.dev
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/ti/wl1251/acx.c

index cb8b3102fa6cf0a28bee019ed3eec03e1d510709..166efac812fe691202267950b8b2c1d18e21b960 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 
 #include "wl1251.h"
 #include "reg.h"
@@ -149,15 +150,7 @@ int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
                goto out;
        }
 
-       /* be careful with the buffer sizes */
-       strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
-
-       /*
-        * if the firmware version string is exactly
-        * sizeof(rev->fw_version) long or fw_len is less than
-        * sizeof(rev->fw_version) it won't be null terminated
-        */
-       buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
+       strscpy(buf, rev->fw_version, len);
 
 out:
        kfree(rev);