Skip to contentSkip to conversation

wireless/ti/wl1251: Replace strncpy with strscpy in fw_version

PATCH New Rahul Kumar 1 participant 1 message Sep 9, 2025 TI wilink wireless drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wireless/ti/wl1251: Replace strncpy with strscpy in fw_version

strncpy is deprecated for use on NUL-terminated strings, as documented in Documentation/process/deprecated.rst. It NUL-pads the destination buffer and does not guarantee NUL termination if the source string is longer than the copy length

This patch replaces the existing strncpy() and manual NUL termination with strscpy(), which ensures safe copying and automatic NUL termination.

---
 drivers/net/wireless/ti/wl1251/acx.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/net/wireless/ti/wl1251/acx.c +2 -9
index f78fc3880423..73232f7e92d1 100644
@@ -149,15 +149,8 @@ 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';
+	/* copy firmware version safely, strscpy ensures NUL termination */
+	strscpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
 
 out:
 	kfree(rev);
Signature · 1 line
2.43.0