[PATCH wireless v2 1/2] wifi: nxpwifi: fix hex parsing in nxpwifi_parse_cal_cfg()

From: Viktor Korsnes

Date: Tue Nov 03 2026 - 02:15:43 EST


nxpwifi_parse_cal_cfg() passes a pointer into the raw firmware buffer to
kstrtou8(). Because kstrtou8() requires a NUL- or newline-terminated
string, it fails with -EINVAL as soon as it encounters a space after the
first byte, causing nxpwifi_parse_cal_cfg() to return 0 bytes.

Use hex2bin() instead to parse each two-character hex byte, bound the
output buffer to the command buffer capacity, and return -EINVAL when
no calibration data is parsed.

Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")
Assisted-by: GitHub-Copilot:Gemini-4-Argon
Signed-off-by: Viktor Korsnes <viktor.korsnes@xxxxxxxxxxxxx>
---
v2:
- Add missing <linux/hex.h> include for hex2bin() (kernel test robot)
- Change src to const char * in nxpwifi_parse_cal_cfg() to avoid
-Wpointer-sign on architectures with signed char

drivers/net/wireless/nxp/nxpwifi/sta_cmd.c | 28 ++++++++++++++++------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/nxp/nxpwifi/sta_cmd.c b/drivers/net/wireless/nxp/nxpwifi/sta_cmd.c
index 5e8ffd306b31..c2ab32fc8e12 100644
--- a/drivers/net/wireless/nxp/nxpwifi/sta_cmd.c
+++ b/drivers/net/wireless/nxp/nxpwifi/sta_cmd.c
@@ -5,6 +5,8 @@
* Copyright 2011-2024 NXP
*/

+#include <linux/hex.h>
+
#include "cfg.h"
#include "util.h"
#include "fw.h"
@@ -1391,9 +1393,11 @@ nxpwifi_ret_sta_mem_access(struct nxpwifi_private *priv,
return 0;
}

-static u32 nxpwifi_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
+static u32 nxpwifi_parse_cal_cfg(const char *src, size_t len, u8 *dst,
+ size_t dst_size)
{
- u8 *s = src, *d = dst;
+ const char *s = src;
+ u8 *d = dst;

while (s - src < len) {
if (*s && (isspace(*s) || *s == '\t')) {
@@ -1401,7 +1405,8 @@ static u32 nxpwifi_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
continue;
}
if (isxdigit(*s)) {
- if (kstrtou8(s, 16, d))
+ if (d - dst >= dst_size || src + len - s < 2 ||
+ hex2bin(d, s, 1))
return 0;
d++;
s += 2;
@@ -1423,14 +1428,18 @@ nxpwifi_cmd_sta_cfg_data(struct nxpwifi_private *priv,
u32 len;
u8 *data = (u8 *)cmd + S_DS_GEN;

- if (adapter->cal_data->data && adapter->cal_data->size > 0) {
- len = nxpwifi_parse_cal_cfg((u8 *)adapter->cal_data->data,
- adapter->cal_data->size, data);
- nxpwifi_dbg(adapter, INFO,
- "download cfg_data from config file\n");
- } else {
+ if (!adapter->cal_data || !adapter->cal_data->data ||
+ !adapter->cal_data->size)
return -EINVAL;
- }
+
+ len = nxpwifi_parse_cal_cfg((const char *)adapter->cal_data->data,
+ adapter->cal_data->size, data,
+ NXPWIFI_SIZE_OF_CMD_BUFFER - S_DS_GEN);
+ if (!len)
+ return -EINVAL;
+
+ nxpwifi_dbg(adapter, INFO,
+ "download cfg_data from config file\n");

cmd->command = cpu_to_le16(HOST_CMD_CFG_DATA);
cmd->size = cpu_to_le16(S_DS_GEN + len);
--
2.53.0