From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796283509; b=ui2sjVhn3H+uHaPNTrHHLNvC3CcT1cMBQvpxx58CMuUGynuQT2BUEGIMVNxZCugGa1BG YPKLBicATwEuRdGO/qt+3SJV1mbZfZ6YjYpkRGhKU1pCLMMKhQDagmztc7LVjTjwML6zi 7LH9QcQb0sbxokvyVyjXG+i4atNa4y3cEvyLByp+3oNG1MOI57z8tRlc5mfRtzRbfsK7/ hkj6F+3G1tydH5oZuTnVr5jYhZeRnTCb+0l76+aPf3zJmmOKzvEMXamT+ZqwWzP7SaHJa pwl6IeteoV/QPxyzTQ3feTHIwkr9klcfx0BzAK8eb521hHeDVeB04luYU8b4y+vp6bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283509; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=xtZE1+KRLq6ofJUPXUTrVa9n1lH7Yo74zn2Zq5FJavg=; b=VBJl+JtfcJxXm+AvnrzlGIHTF6p3JPOjGUtPg1BFrqUlMid61w1byfOYpAPqBbG/s+UC o4ucHfgxp6fEzz4hTwPtBI5j9PPNYqYqnhOIgJcGtZLNyNBGV8RPIKP/m+HYUVh2K7ArJ JNydy2sHtzxmOg6G7WmE4+B3cySk98oa4q2GxLea5c/ylS+wVDKKUIy1Z3ZwOxv8U8+SI EIeZ1X2P8rzsNct3CmERVauUJ3CwxANX5mOL1d/3ehszP9ghdhFBQKigg8DKGkzhhxJ7I U+9rICTs4SRwuO42ntQuSxZznJ60I7NLlC2dc+k4xiFAMhFZAprkU0wtnDn7g5EdWbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JLyEnq8x; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9750606A322 for ; Thu, 3 Dec 2026 07:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JLyEnq8x Received: by smtp.kernel.org (Postfix) with ESMTPSA id 368B71F00896; Thu, 3 Dec 2026 07:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796283509; bh=xtZE1+KRLq6ofJUPXUTrVa9n1lH7Yo74zn2Zq5FJavg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JLyEnq8xPFdxPGa8b+oPO0hCBJDJmOJky04vLyTt/+cp26wZSlY9Y4OHqXnqD4Clv 7han9o6fLehwaH949sjgK56YWxRct4wV5kL4R9/xzShRN0lOIrqqIeVnAL/Ct+6JVm yTZonwaczAE5pd8OKjVszEAm7QLyY8yBhqi0+LZBkN6G1AHzxYqi4Nw0lvp/y3Zo6j 9Tl2Y9Z4ahcY2YF1ZXkG5fN5Kl2SiCuOGnc3iU62KixUdJUisEpvcuQM3zYO2t6Un8 O88oFq6OEOaha8EYDFxWu8iv0Y5DLDhwc+gh6WRB0gNxLIgSdCNZik9g1YUWHWVyoo 5b+/oqDKSxsMg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Reply-To: sashiko-reviews@lists.linux.dev To: "Ramesh Ramalingam" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203070906.1294171-9-r-ramalingam@ti.com> References: <20261203070906.1294171-1-r-ramalingam@ti.com> <20261203070906.1294171-9-r-ramalingam@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 07:38:28 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D container->size; > + container_data =3D 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 =3D=3D 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 =3D cc->fw_download; > + > + ret =3D 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 =3D atomic_fetch_and(0, &fw_download->pending_irqs); > + pending_irqs &=3D ~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 =3D=3D 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 !=3D 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 =3D 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 =3D 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 =3D cc33xx_cmd_get_device_info(cc, hw_info.bytes, sizeof(hw_info.by= tes)); [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 =3D 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 =3D 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 =3D sdio_enable_func(func); sdio_release_host(func); return ret; } Because cc33xx_power_on() only sets CC33XX_FLAG_GPIO_POWER when ret =3D=3D = 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203070906.1294= 171-1-r-ramalingam@ti.com?part=3D8