[PATCH wireless-next 03/10] wifi: cw1200: bounce SDIO transfers that use stack buffers

From: Arthur Heymans

Date: Thu Nov 19 2026 - 12:51:15 EST


Register accesses pass stack words to sdio_memcpy_fromio() and
sdio_memcpy_toio(). Use a heap buffer for stack and non-linear
addresses; keep the direct path for ordinary packet buffers.

Prepared with OpenAI Codex.

Fixes: a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
Signed-off-by: Arthur Heymans <arthur@xxxxxxxxxxxx>
---
drivers/net/wireless/st/cw1200/cw1200_sdio.c | 35 ++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/st/cw1200/cw1200_sdio.c b/drivers/net/wireless/st/cw1200/cw1200_sdio.c
index 2b6afe221268..1894359ee9b4 100644
--- a/drivers/net/wireless/st/cw1200/cw1200_sdio.c
+++ b/drivers/net/wireless/st/cw1200/cw1200_sdio.c
@@ -10,6 +10,9 @@
#include <linux/interrupt.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/sched/task_stack.h>
#include <linux/mmc/host.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/card.h>
@@ -61,14 +64,42 @@ static int cw1200_sdio_memcpy_fromio(struct hwbus_priv *self,
unsigned int addr,
void *dst, int count)
{
- return sdio_memcpy_fromio(self->func, dst, addr, count);
+ void *bounce;
+ int ret;
+
+ if (virt_addr_valid(dst) && !object_is_on_stack(dst))
+ return sdio_memcpy_fromio(self->func, dst, addr, count);
+
+ bounce = kmalloc(count, GFP_KERNEL);
+ if (!bounce)
+ return -ENOMEM;
+
+ ret = sdio_memcpy_fromio(self->func, bounce, addr, count);
+ if (!ret)
+ memcpy(dst, bounce, count);
+ kfree(bounce);
+
+ return ret;
}

static int cw1200_sdio_memcpy_toio(struct hwbus_priv *self,
unsigned int addr,
const void *src, int count)
{
- return sdio_memcpy_toio(self->func, addr, (void *)src, count);
+ void *bounce;
+ int ret;
+
+ if (virt_addr_valid(src) && !object_is_on_stack(src))
+ return sdio_memcpy_toio(self->func, addr, (void *)src, count);
+
+ bounce = kmemdup(src, count, GFP_KERNEL);
+ if (!bounce)
+ return -ENOMEM;
+
+ ret = sdio_memcpy_toio(self->func, addr, bounce, count);
+ kfree(bounce);
+
+ return ret;
}

static void cw1200_sdio_lock(struct hwbus_priv *self)
--
2.56.0