From: sashiko-bot@kernel.org
To: "Nas Chung" <nas.chung@chipsnmedia.com>
Cc: conor+dt@kernel.org, media-ci@linuxtv.org, robh@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v7 8/9] media: chips-media: wave6: Add Wave6 control driver
Date: Fri, 04 Sep 2026 07:05:31 +0000 [thread overview]
Message-ID: <20260904070531.674551F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <9a39dbcd48c8326394992cc048a635fb2472537e.1788496816.git.nas.chung@chipsnmedia.com>
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] Data race on shared work_buffers_avail counter leads to DMA memory corruption.
- [High] Incompatible pointer type passed to `gen_pool_dma_alloc` causes structure memory corruption and invalid DMA mappings.
- [High] Use-after-free of the driver device structure in the async firmware load callback on unbind.
- [High] System deadlock caused by holding the parent's mutex while synchronously unregistering child devices.
- [High] Failure in work buffer initialization leaves the VPU state machine permanently corrupted.
- [High] Auxiliary power domains are never powered on because they lack device links.
- [Medium] Leaked runtime PM usage counter due to an improper conditional check on device suspend state.
- [Medium] Using a value of 0 to validate a DMA mapping leads to an IOMMU resource leak.
- [Medium] Mixing scoped guards with goto-based error handling violates kernel cleanup API rules.
--
commit 373df31fcd64a0ed065b0d792d9b1dac72e53fd5
Author: Nas Chung <nas.chung@chipsnmedia.com>
Subject: media: chips-media: wave6: Add Wave6 control driver
This commit adds the control driver for the Chips&Media Wave6 video codec IP.
It manages shared resources, firmware memory allocation, and power states for
the child core devices.
> --- /dev/null
> +++ b/drivers/media/platform/chips-media/wave6/wave6-vpu.c
[ ... ]
> +static int wave6_vpu_init_vpu(struct wave6_vpu_device *vpu,
> + struct vpu_core_device *core)
> +{
[ ... ]
> + wave6_vpu_set_state(vpu, WAVE6_VPU_STATE_PREPARE);
[ ... ]
> +init_done:
> + ret = wave6_vpu_init_work_buf(vpu, core);
> + if (ret)
> + return ret;
[Severity: High]
If wave6_vpu_init_work_buf() fails here, the function returns immediately
without resetting vpu->state. Will this leave the driver permanently in
WAVE6_VPU_STATE_PREPARE, causing subsequent attempts to boot to skip the init
sequence?
> +
> + wave6_vpu_set_state(vpu, WAVE6_VPU_STATE_ON);
> +
> + return 0;
> +}
[ ... ]
> +static int wave6_vpu_get(struct wave6_vpu_device *vpu,
> + struct vpu_core_device *core)
> +{
> + int ret;
> +
> + if (WARN_ON(!vpu || !core))
> + return -EINVAL;
> +
> + guard(mutex)(&vpu->lock);
> +
> + if (!vpu->fw_available)
> + return -EINVAL;
[ ... ]
> + ret = wave6_vpu_try_boot(vpu, core);
> + if (ret)
> + goto error_boot;
> +
> + return 0;
> +
> +error_boot:
> + pm_runtime_put_sync(vpu->dev);
> +error_pm:
[Severity: Medium]
Does this mix goto-based error handling with guard() cleanup in the same
function? The kernel cleanup API expects that a function either uses scoped
guards entirely or goto entirely to prevent confusing ownership and cleanup
ordering.
> + atomic_dec(&vpu->core_count);
> +
> + return ret;
> +}
> +
> +static void wave6_vpu_put(struct wave6_vpu_device *vpu,
> + struct vpu_core_device *core)
> +{
[ ... ]
> + guard(mutex)(&vpu->lock);
[Severity: High]
Will this cause a system deadlock when the parent unregisters child devices?
During wave6_vpu_release(), the parent takes vpu->lock and triggers core
destruction. The child's remove callback will then try to put the VPU, leading
back into this function which attempts to acquire the exact same lock.
> +
> + if (!vpu->fw_available)
> + return;
[ ... ]
> + wave6_vpu_sleep(vpu, core);
> +
> + if (!pm_runtime_suspended(vpu->dev))
> + pm_runtime_put_sync(vpu->dev);
[Severity: Medium]
Does conditionally skipping the put operation cause a usage counter leak?
If the device was suspended by other system events, skipping this symmetrical
put prevents the device from ever entering lower power states in the future.
> +}
> +
> +static void wave6_vpu_require_work_buffer(struct wave6_vpu_device *vpu,
> + struct vpu_core_device *core)
> +{
> + struct vpu_buf *vb;
> + u32 size;
[ ... ]
> + if (WARN_ON(vpu->work_buffers_avail == 0))
> + goto exit;
> +
> + vpu->work_buffers_avail--;
> + vb = &vpu->work_buffers[vpu->work_buffers_avail];
[Severity: High]
Is there a data race on the work_buffers_avail counter here? If multiple
VPU cores trigger requests concurrently without holding vpu->lock, could the
counter underflow and lead to an out-of-bounds array access that corrupts DMA
memory?
> +
> + wave6_vdi_writel(core->reg_base, W6_CMD_SET_WORK_BUF_ADDR, vb->daddr);
> +
> +exit:
> + wave6_vdi_writel(core->reg_base, W6_CMD_SET_WORK_BUF_SIZE, SET_WORK_BUF_SIZE_ACK);
> +}
[ ... ]
> +static void wave6_vpu_release(struct wave6_vpu_device *vpu)
> +{
> + guard(mutex)(&vpu->lock);
> +
> + vpu->fw_available = false;
> + wave6_vpu_destroy_cores(vpu);
> + wave6_vpu_free_work_buffers(vpu);
> + if (vpu->sram_pool && vpu->sram_buf.vaddr) {
[ ... ]
> + }
> + if (vpu->code_buf.dma_addr)
> + dma_unmap_resource(vpu->dev,
[Severity: Medium]
Could this condition leak valid IOMMU mappings if the DMA allocator returns 0?
Since 0 is a valid DMA address on many platforms, skipping the unmap when the
address evaluates to false can lead to a resource leak.
> + vpu->code_buf.dma_addr,
> + vpu->code_buf.size,
> + DMA_BIDIRECTIONAL,
> + 0);
> +}
> +
> +static void wave6_vpu_load_firmware(const struct firmware *fw, void *context)
> +{
> + struct wave6_vpu_device *vpu = context;
> +
> + guard(mutex)(&vpu->lock);
[Severity: High]
Can this cause a use-after-free if the device unbinds while firmware loading
is in progress? If the driver is removed and devres frees the vpu memory,
this async callback might try to acquire a mutex that resides in freed memory.
> +
> + if (!fw || !fw->data) {
[ ... ]
> + if (fw->size + W6_EXTRA_CODE_BUF_SIZE > wave6_vpu_get_code_buf_size(vpu)) {
> + dev_err(vpu->dev, "firmware size (%zd > %zd) is too big\n",
> + fw->size, vpu->code_buf.size);
> + vpu->fw_available = false;
> + goto exit;
[Severity: Medium]
Is this mixing goto-based error handling and scoped guard cleanup again? This
violates the cleanup API guidelines.
> + }
[ ... ]
> +static int wave6_vpu_attach_pm_domains(struct wave6_vpu_device *vpu)
> +{
> + int ret;
[ ... ]
> + if (vpu->num_pm_domains == 1) {
> + /* genpd_dev_pm_attach() attach automatically if count is 1 */
> + vpu->num_pm_domains = 0;
> + return 0;
> + }
> +
> + ret = dev_pm_domain_attach_list(vpu->dev, NULL, &vpu->pd_list);
[Severity: High]
By passing NULL for the data parameter, does this skip creating device links
for the auxiliary domains? Without DL_FLAG_PM_RUNTIME links, the PM core won't
power on these domains during runtime, which might lead to exceptions when
accessing unpowered hardware registers.
> + if (ret < 0) {
[ ... ]
> +static int wave6_vpu_probe(struct platform_device *pdev)
> +{
[ ... ]
> + vpu->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
> + if (vpu->sram_pool) {
> + vpu->sram_buf.size = vpu->res->sram_size;
> + vpu->sram_buf.vaddr = gen_pool_dma_alloc(vpu->sram_pool,
> + vpu->sram_buf.size,
> + &vpu->sram_buf.phys_addr);
> + if (!vpu->sram_buf.vaddr) {
> + vpu->sram_buf.size = 0;
> + } else {
> + vpu->sram_buf.dma_addr = dma_map_resource(&pdev->dev,
> + vpu->sram_buf.phys_addr,
[Severity: High]
gen_pool_dma_alloc() expects a dma_addr_t pointer for its third argument to
write back the DMA address, but a phys_addr_t pointer is being passed here.
Could this cause out-of-bounds memory corruption on architectures where the
sizes differ? Additionally, is the returned DMA address being incorrectly
passed to dma_map_resource() as if it were a physical address?
> + vpu->sram_buf.size,
> + DMA_BIDIRECTIONAL,
> + 0);
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788496816.git.nas.chung@chipsnmedia.com?part=8
next prev parent reply other threads:[~2026-09-04 7:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 6:46 [PATCH v7 0/9] Add support for Wave6 video codec driver Nas Chung
2026-09-04 6:46 ` [PATCH v7 1/9] media: v4l2-common: Fix P010 format info Nas Chung
2026-09-04 6:46 ` [PATCH v7 2/9] dt-bindings: media: nxp: Add Wave6 video codec device Nas Chung
2026-09-08 9:50 ` Krzysztof Kozlowski
2026-09-09 16:33 ` Frank Li
2026-09-04 6:46 ` [PATCH v7 3/9] media: chips-media: wave6: Add Wave6 VPU interface Nas Chung
2026-09-04 7:04 ` sashiko-bot
2026-09-09 16:39 ` Frank Li
2026-09-09 23:53 ` Nas Chung
2026-09-09 19:49 ` Frank Li
2026-09-10 8:14 ` Nas Chung
2026-09-10 19:50 ` Frank Li
2026-09-04 6:46 ` [PATCH v7 4/9] media: chips-media: wave6: Add v4l2 m2m driver support Nas Chung
2026-09-04 7:21 ` sashiko-bot
2026-09-10 20:37 ` Frank Li
2026-09-11 7:12 ` Nas Chung
2026-09-04 6:46 ` [PATCH v7 5/9] media: chips-media: wave6: Add Wave6 core driver Nas Chung
2026-09-04 7:03 ` sashiko-bot
2026-09-10 20:48 ` Frank Li
2026-09-11 8:35 ` Nas Chung
2026-09-04 6:46 ` [PATCH v7 6/9] media: chips-media: wave6: Improve debugging capabilities Nas Chung
2026-09-04 7:02 ` sashiko-bot
2026-09-09 20:40 ` Frank Li
2026-09-10 4:38 ` Nas Chung
2026-09-10 16:16 ` Frank Li
2026-09-11 3:53 ` Nas Chung
2026-09-04 6:46 ` [PATCH v7 7/9] media: chips-media: wave6: Add Wave6 thermal cooling device Nas Chung
2026-09-04 7:00 ` sashiko-bot
2026-09-04 6:46 ` [PATCH v7 8/9] media: chips-media: wave6: Add Wave6 control driver Nas Chung
2026-09-04 7:05 ` sashiko-bot [this message]
2026-09-10 21:04 ` Frank Li
2026-09-11 7:07 ` Nas Chung
2026-09-04 6:46 ` [PATCH v7 9/9] arm64: dts: freescale: imx95: Add video codec node Nas Chung
2026-09-10 20:00 ` [PATCH v7 0/9] Add support for Wave6 video codec driver Frank Li
2026-09-11 6:58 ` Nas Chung
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=20260904070531.674551F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=nas.chung@chipsnmedia.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.