From: sashiko-bot@kernel.org
To: "Ramesh Ramalingam" <r-ramalingam@ti.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h
Date: Thu, 03 Dec 2026 07:38:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-247305@kernel.org> (raw)
In-Reply-To: <20261203070906.1294171-9-r-ramalingam@ti.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] wifi: cc33xx: non-portable bitfield overlay in struct
hwinfo_bitmap
- [Medium] wifi: cc33xx: unlocked reinit_completion() race in
wait_for_boot_irq()
- [Medium] wifi: cc33xx: non-errno negative returns (-1, -2, -3) in
boot.c
- [Medium] wifi: cc33xx: slab OOB write in __cc33xx_cmd_send() on device
info response
- [Medium] wifi: cc33xx: runtime PM refcount leak in
cc33xx_sdio_power_on() on error
- [Medium] wifi: cc33xx: unlocked free-before-NULL in fw_download_free()
- [Low] wifi: cc33xx: redundant vmalloc/memcpy/vfree firmware copy in
fetch_container()
- [Low] wifi: cc33xx: missing zero-size check before vmalloc() in
fetch_container()
--
commit db57acc2ac6854560fb4bce9d60e1ec4b1b3f3c3
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add boot.c, boot.h
This commit adds the CC33xx firmware download and boot sequence in
boot.c and boot.h, loading the second-stage bootloader and main
firmware image in chunks and waiting on boot IRQs between stages.
> diff --git a/drivers/net/wireless/ti/cc33xx/boot.c b/drivers/net/wireless/ti/cc33xx/boot.c
> new file mode 100644
> index 0000000000000..4ec7c315be778
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/boot.c
[ ... ]
> +struct hwinfo_bitmap {
> + u32 disable_5g : 1u;
> + u32 disable_6g : 1u;
> + u32 disable_ble : 1u;
> + u32 disable_ble_m0plus : 1u;
> + u32 disable_m33 : 1u;
> + u64 udi : 64u;
> + u32 pg_version : 4u;
> + u32 metal_version : 4u;
> + u32 boot_rom_version : 4u;
> + u32 m3_rom_version : 4u;
> + u32 fuse_rom_structure_version : 4u;
> + u64 mac_address : 48u;
> + u32 device_part_number : 6u;
> + u32 package_type : 4u;
> + u32 fw_rollback_protection_1 : 32u;
> + u32 fw_rollback_protection_2 : 32u;
> + u32 fw_rollback_protection_3 : 32u;
> + u32 reserved : 13u;
> +} /* Aligned with boot code, must not be __packed */;
> +
> +union hw_info {
> + struct hwinfo_bitmap bitmap;
> + u8 bytes[sizeof(struct hwinfo_bitmap)];
> +};
[Severity: Medium]
Can struct hwinfo_bitmap misparse the firmware response on 32-bit or
big-endian architectures?
Because the struct is unpacked and mixes u32 and u64 bitfields, padding
before udi and mac_address depends on alignof(u64) (48 bytes on 64-bit
versus 40 bytes on i386, shifting every field after disable_m33), and
big-endian hosts lay out bitfields MSB-first without byte-swapping the
little-endian response bytes. get_device_info() then silently populates
corrupted values for cc->efuse_mac_address, cc->disable_5g, and the chip
version fields.
Describing the wire format with fixed-width __le32/__le64 fields and
decoding via le32_to_cpu()/le64_to_cpu()/FIELD_GET() would avoid ABI and
endianness dependence.
[ ... ]
> + if (container->size % 4) {
> + dev_err(cc->dev, "container size is not word-aligned: %zu\n",
> + container->size);
> + goto out;
> + }
> +
> + *container_len = container->size;
> + container_data = vmalloc(container->size);
[Severity: Low]
Can vmalloc(container->size) be called with a zero size here?
container->size % 4 passes when container->size is 0, which hits
WARN_ON_ONCE(!size) in __vmalloc_node_range_noprof(). While single-caller
request_firmware() rejects empty files, a second concurrent caller on the
batched path in _request_firmware_prepare() can wake up with
firmware->size == 0 when fw_state_done() runs for an empty .xz stream or
sysfs fallback before fw_abort_batch_reqs(). Checking !container->size
alongside container->size % 4 prevents the warning.
> + if (!container_data)
> + goto out;
> +
> + memcpy(container_data, container->data, container->size);
> +
> +out:
> + release_firmware(container);
> + return container_data;
> +}
[Severity: Low]
Is the vmalloc() and memcpy() copy of the firmware image needed here?
cc33xx_cmd_download_container_chunk() only reads from the buffer to copy
chunks into a kzalloc'd command buffer. Duplicating the image doubles
peak memory usage during boot, keeps the copy allocated across
wait_for_boot_irq(), and discards the errno from request_firmware().
Passing container->data directly to download_container() and calling
release_firmware() right after avoids the extra allocation and copy.
[ ... ]
> +static int wait_for_boot_irq(struct cc33xx *cc, u32 boot_irq_mask,
> + unsigned long timeout)
> +{
> + int ret;
> + u32 pending_irqs;
> + struct cc33xx_fw_download *fw_download;
> +
> + fw_download = cc->fw_download;
> +
> + ret = wait_for_completion_interruptible_timeout(&fw_download->wait_on_irq,
> + msecs_to_jiffies(timeout));
> +
> + /* Fetch pending IRQs while clearing them in fw_download */
> + pending_irqs = atomic_fetch_and(0, &fw_download->pending_irqs);
> + pending_irqs &= ~HINT_COMMAND_COMPLETE;
> +
> + reinit_completion(&fw_download->wait_on_irq);
[Severity: Medium]
Can reinit_completion() race with cc33xx_handle_boot_irqs() and lose a
boot IRQ wakeup?
wait_for_boot_irq() cc33xx_handle_boot_irqs()
wait_for_completion_...()
atomic_fetch_and(0, ...)
atomic_or(..., &pending_irqs)
complete(&wait_on_irq)
reinit_completion(&wait_on_irq) <-- clears done without wait.lock
reinit_completion() performs an unlocked write to done while hardware
interrupts are still enabled, so a concurrent complete() can be
overwritten and stall the next wait_for_boot_irq() for 2000 ms. If a
second boot IRQ arrives before atomic_fetch_and(), both bits are also
cleared together and the exact boot_irq_mask check fails.
Using a wait_queue_head_t with wait_event_interruptible_timeout() testing
pending_irqs avoids both the data race and the lost wakeup.
> + if (ret == 0) {
> + dev_err(cc->dev, "boot IRQ timeout\n");
> + return -1;
> + } else if (ret < 0) {
> + dev_err(cc->dev, "boot IRQ completion error %d\n", ret);
> + return -2;
> + }
> +
> + if (boot_irq_mask != pending_irqs) {
> + dev_err(cc->dev, "Unexpected IRQ received @ boot: 0x%x\n",
> + pending_irqs);
> + return -3;
> + }
[Severity: Medium]
Should wait_for_boot_irq() return standard negative errnos instead of
-1, -2, and -3?
cc33xx_init_fw() propagates these values out of probe, where they map to
-EPERM, -ENOENT, and -ESRCH instead of -ETIMEDOUT, the error from
wait_for_completion_interruptible_timeout(), and -EIO or -EPROTO.
container_download_and_wait() likewise returns -1 when fetch_container()
fails, hiding the error from request_firmware(), alignment validation,
or allocation.
[ ... ]
> +static void fw_download_free(struct cc33xx *cc)
> +{
> + if (WARN_ON(!cc->fw_download))
> + return;
> +
> + kfree(cc->fw_download);
> + cc->fw_download = NULL;
> +}
[Severity: Medium]
Can fw_download_free() race with cc33xx_handle_boot_irqs() and cause a
use-after-free or NULL pointer dereference?
cc33xx_init_fw() cc33xx_irq() / cc33xx_irq_work()
goto out; /* IRQs enabled */ process_core_status()
fw_download_free() cc33xx_handle_boot_irqs()
if (WARN_ON(!cc->fw_download))
kfree(cc->fw_download)
atomic_or(...,
&cc->fw_download->pending_irqs)
<-- use-after-free
cc->fw_download = NULL
process_core_status() invokes cc33xx_handle_boot_irqs() under
claim_core_status_lock(cc) whenever a BOOT_TIME_INTERRUPTS bit is
observed, whereas fw_download_free() takes no lock and frees
cc->fw_download before setting it to NULL. On the success path of
cc33xx_init_fw(), interrupts remain enabled when fw_download_free() runs,
and on the error path cc33xx_disable_line_irq() uses disable_irq_nosync().
Clearing cc->fw_download into a local pointer under
claim_core_status_lock(cc) before calling kfree() closes this race.
> +static int get_device_info(struct cc33xx *cc)
> +{
> + int ret;
> + union hw_info hw_info;
> + u64 mac_address;
> +
> + ret = cc33xx_cmd_get_device_info(cc, hw_info.bytes, sizeof(hw_info.bytes));
[Severity: Medium]
Can cc33xx_cmd_get_device_info() trigger a slab out-of-bounds write in
__cc33xx_cmd_send()?
cc33xx_cmd_get_device_info() allocates cmd (712 bytes) and passes
sizeof(*cmd) as res_len, while parse_control_message() accepts
device-reported lengths up to CC33XX_CMD_MAX_SIZE (896 bytes):
drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
...
if (WARN_ON(cc->result_length > res_len)) {
dev_err(cc->dev, "Error, insufficient response buffer\n");
return -EINVAL;
}
switch (id) {
case CMD_INTERROGATE:
case CMD_DEBUG_READ:
case CMD_TEST_MODE:
case CMD_BM_READ_DEVICE_INFO:
memcpy(buf + sizeof(struct nab_header), cc->command_result,
cc->result_length);
break;
...
}
Because the bounds check compares cc->result_length against res_len
instead of res_len - sizeof(struct nab_header), a response length of
705..712 bytes writes up to 8 bytes past the end of cmd.
[ ... ]
> + ret = cc33xx_chip_wakeup(cc);
> + if (ret < 0)
> + goto power_off;
[Severity: Medium]
Does a failed cc33xx_chip_wakeup() leak a runtime PM reference on
&card->dev?
cc33xx_chip_wakeup() calls cc33xx_power_on() -> cc33xx_sdio_power_on(),
which returns an error from sdio_enable_func() without releasing the
runtime PM reference:
drivers/net/wireless/ti/cc33xx/sdio.c:cc33xx_sdio_power_on() {
...
ret = pm_runtime_get_sync(&card->dev);
if (ret < 0) {
pm_runtime_put_noidle(&card->dev);
dev_err(glue->dev, "%s: failed to get_sync(%d)\n",
__func__, ret);
return ret;
}
sdio_claim_host(func);
ret = sdio_enable_func(func);
sdio_release_host(func);
return ret;
}
Because cc33xx_power_on() only sets CC33XX_FLAG_GPIO_POWER when ret == 0,
cc33xx_power_off() at power_off: returns early without calling
cc33xx_sdio_power_off(), leaving the runtime PM usage count leaked and
preventing the SDIO card and host from runtime suspending.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=8
next prev parent reply other threads:[~2026-12-03 7:38 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
2026-12-03 7:20 ` sashiko-bot
2026-12-03 18:27 ` Rob Herring
2026-12-03 7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
2026-12-03 7:26 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
2026-12-03 7:42 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
2026-12-03 7:32 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
2026-12-03 7:38 ` sashiko-bot [this message]
2026-12-03 7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
2026-12-03 9:12 ` Uwe Kleine-König
2026-12-03 7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
2026-12-03 7:47 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
2026-12-03 7:43 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
2026-12-03 7:52 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 14/17] wifi: cc33xx: Add conf.h Ramesh Ramalingam
2026-12-03 7:50 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h Ramesh Ramalingam
2026-12-03 7:43 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h Ramesh Ramalingam
2026-12-03 7:48 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile Ramesh Ramalingam
2026-12-03 7:46 ` sashiko-bot
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=sashiko-outbox-247305@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=r-ramalingam@ti.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.