From: Heyang Tan <thy15333007817@163.com>
To: jeff.chen_1@nxp.com
Cc: francesco@dolcini.it, johannes@sipsolutions.net,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] wifi: nxpwifi: bound debug info output
Date: Sat, 19 Sep 2026 12:44:39 +0800 [thread overview]
Message-ID: <20260919044439.1042-1-thy15333007817@163.com> (raw)
In-Reply-To: <20260919040253.590-1-thy15333007817@163.com>
nxpwifi_debug_read() provides a PAGE_SIZE buffer to
nxpwifi_debug_info_to_buffer(), which formats debug state with
unbounded sprintf() calls. The same helper is also used for the firmware
dump.
Pass the output size to the helper and use scnprintf() while formatting.
Clamp the debug table counts and window size to the backing array lengths
before accessing them.
Assisted-by: LLM
Signed-off-by: Heyang Tan <thy15333007817@163.com>
---
drivers/net/wireless/nxp/nxpwifi/debugfs.c | 2 +-
drivers/net/wireless/nxp/nxpwifi/main.c | 5 ++-
drivers/net/wireless/nxp/nxpwifi/util.c | 43 +++++++++++++---------
drivers/net/wireless/nxp/nxpwifi/util.h | 1 +
4 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/drivers/net/wireless/nxp/nxpwifi/debugfs.c b/drivers/net/wireless/nxp/nxpwifi/debugfs.c
index fd738a811..cd6e73a21 100644
--- a/drivers/net/wireless/nxp/nxpwifi/debugfs.c
+++ b/drivers/net/wireless/nxp/nxpwifi/debugfs.c
@@ -304,7 +304,7 @@ nxpwifi_debug_read(struct file *file, char __user *ubuf,
if (ret)
goto free_and_exit;
- p += nxpwifi_debug_info_to_buffer(priv, p, &info);
+ p += nxpwifi_debug_info_to_buffer(priv, p, PAGE_SIZE, &info);
ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
(unsigned long)p - page);
diff --git a/drivers/net/wireless/nxp/nxpwifi/main.c b/drivers/net/wireless/nxp/nxpwifi/main.c
index 55b962430..b4cac1df9 100644
--- a/drivers/net/wireless/nxp/nxpwifi/main.c
+++ b/drivers/net/wireless/nxp/nxpwifi/main.c
@@ -1113,7 +1113,10 @@ void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter)
continue;
priv = adapter->priv[i];
nxpwifi_get_debug_info(priv, debug_info);
- p += nxpwifi_debug_info_to_buffer(priv, p, debug_info);
+ p += nxpwifi_debug_info_to_buffer(priv, p,
+ NXPWIFI_FW_DUMP_SIZE -
+ (p - (char *)adapter->devdump_data),
+ debug_info);
break;
}
kfree(debug_info);
diff --git a/drivers/net/wireless/nxp/nxpwifi/util.c b/drivers/net/wireless/nxp/nxpwifi/util.c
index bbfefb81d..27a91e205 100644
--- a/drivers/net/wireless/nxp/nxpwifi/util.c
+++ b/drivers/net/wireless/nxp/nxpwifi/util.c
@@ -220,19 +220,24 @@ int nxpwifi_get_debug_info(struct nxpwifi_private *priv,
}
int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf,
+ size_t buf_size,
struct nxpwifi_debug_info *info)
{
- char *p = buf;
+ size_t used = 0;
struct nxpwifi_debug_data *d = &items[0];
size_t size, addr;
long val;
+ u32 tx_tbl_num, rx_tbl_num, win_size;
int i, j;
if (!info)
return 0;
+ tx_tbl_num = min_t(u32, info->tx_tbl_num, ARRAY_SIZE(info->tx_tbl));
+ rx_tbl_num = min_t(u32, info->rx_tbl_num, ARRAY_SIZE(info->rx_tbl));
+
for (i = 0; i < num_of_items; i++) {
- p += sprintf(p, "%s=", d[i].name);
+ used += scnprintf(buf + used, buf_size - used, "%s=", d[i].name);
size = d[i].size / d[i].num;
@@ -260,41 +265,43 @@ int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf,
break;
}
- p += sprintf(p, "%#lx ", val);
+ used += scnprintf(buf + used, buf_size - used, "%#lx ", val);
addr += size;
}
- p += sprintf(p, "\n");
+ used += scnprintf(buf + used, buf_size - used, "\n");
}
- if (info->tx_tbl_num) {
- p += sprintf(p, "Tx BA stream table:\n");
- for (i = 0; i < info->tx_tbl_num; i++)
- p += sprintf(p, "tid = %d, ra = %pM\n",
+ if (tx_tbl_num) {
+ used += scnprintf(buf + used, buf_size - used, "Tx BA stream table:\n");
+ for (i = 0; i < tx_tbl_num; i++)
+ used += scnprintf(buf + used, buf_size - used, "tid = %d, ra = %pM\n",
info->tx_tbl[i].tid, info->tx_tbl[i].ra);
}
- if (info->rx_tbl_num) {
- p += sprintf(p, "Rx reorder table:\n");
- for (i = 0; i < info->rx_tbl_num; i++) {
- p += sprintf(p, "tid = %d, ta = %pM, ",
+ if (rx_tbl_num) {
+ used += scnprintf(buf + used, buf_size - used, "Rx reorder table:\n");
+ for (i = 0; i < rx_tbl_num; i++) {
+ used += scnprintf(buf + used, buf_size - used, "tid = %d, ta = %pM, ",
info->rx_tbl[i].tid,
info->rx_tbl[i].ta);
- p += sprintf(p, "start_win = %d, ",
+ used += scnprintf(buf + used, buf_size - used, "start_win = %d, ",
info->rx_tbl[i].start_win);
- p += sprintf(p, "win_size = %d, buffer: ",
+ used += scnprintf(buf + used, buf_size - used, "win_size = %d, buffer: ",
info->rx_tbl[i].win_size);
- for (j = 0; j < info->rx_tbl[i].win_size; j++)
- p += sprintf(p, "%c ",
+ win_size = min_t(u32, info->rx_tbl[i].win_size,
+ ARRAY_SIZE(info->rx_tbl[i].buffer));
+ for (j = 0; j < win_size; j++)
+ used += scnprintf(buf + used, buf_size - used, "%c ",
info->rx_tbl[i].buffer[j] ?
'1' : '0');
- p += sprintf(p, "\n");
+ used += scnprintf(buf + used, buf_size - used, "\n");
}
}
- return p - buf;
+ return used;
}
bool nxpwifi_is_channel_setting_allowable(struct nxpwifi_private *priv,
diff --git a/drivers/net/wireless/nxp/nxpwifi/util.h b/drivers/net/wireless/nxp/nxpwifi/util.h
index 1a47c8c5b..a0ec722e6 100644
--- a/drivers/net/wireless/nxp/nxpwifi/util.h
+++ b/drivers/net/wireless/nxp/nxpwifi/util.h
@@ -82,6 +82,7 @@ static inline dma_addr_t NXPWIFI_SKB_DMA_ADDR(struct sk_buff *skb)
}
int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf,
+ size_t buf_size,
struct nxpwifi_debug_info *info);
static inline void le16_unaligned_add_cpu(__le16 *var, u16 val)
--
2.34.1
next prev parent reply other threads:[~2026-09-19 4:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 4:02 [PATCH v3 0/2] wifi: nxpwifi: bound debugfs output Heyang Tan
2026-09-19 4:02 ` [PATCH v3 1/2] wifi: nxpwifi: bound histogram " Heyang Tan
2026-09-21 8:08 ` Jeff Chen
2026-09-19 4:44 ` Heyang Tan [this message]
2026-09-21 8:59 ` [PATCH v3 2/2] wifi: nxpwifi: bound debug info output Jeff Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919044439.1042-1-thy15333007817@163.com \
--to=thy15333007817@163.com \
--cc=francesco@dolcini.it \
--cc=jeff.chen_1@nxp.com \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox