Skip to content

[Deepin-Kernel-SIG] [linux 6.18.y] [FROMLIST] media: mtk-jpeg: only init/cancel work for multi-core variants#1802

Merged
opsiff merged 1 commit into
deepin-community:linux-6.18.yfrom
Avenger-285714:mtk-jpeg-6.18
Jun 3, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.18.y] [FROMLIST] media: mtk-jpeg: only init/cancel work for multi-core variants#1802
opsiff merged 1 commit into
deepin-community:linux-6.18.yfrom
Avenger-285714:mtk-jpeg-6.18

Conversation

@Avenger-285714
Copy link
Copy Markdown
Member

@Avenger-285714 Avenger-285714 commented Jun 2, 2026

Single-core variants of this hardware do not use the work at all, and the worker function is set to NULL, which leads to warnings when cancelling the work in release callback.

Skip the work init/cancel code when the JPEG hardware isn't multi-core.

Cc: stable@vger.kernel.org
Fixes: 34c519feef3e ("media: mtk-jpeg: fix use-after-free in release path due to uncancelled work")
Fixes: d40e952 ("media: mtk-jpeg: reconstructs the initialization mode of worker")

Link: https://lore.kernel.org/all/20260601073218.1281840-1-zhengxingda@iscas.ac.cn/

Summary by Sourcery

Bug Fixes:

  • Avoid warnings and potential misuse by skipping work initialization and cancellation on single-core Mediatek JPEG hardware that does not use the worker.

Single-core variants of this hardware do not use the work at all, and
the worker function is set to NULL, which leads to warnings when
cancelling the work in release callback.

Skip the work init/cancel code when the JPEG hardware isn't multi-core.

Cc: stable@vger.kernel.org
Fixes: 34c519feef3e ("media: mtk-jpeg: fix use-after-free in release path due to uncancelled work")
Fixes: d40e952 ("media: mtk-jpeg: reconstructs the initialization mode of worker")
Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
Link: https://lore.kernel.org/all/20260601073218.1281840-1-zhengxingda@iscas.ac.cn/
Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
@Avenger-285714 Avenger-285714 requested review from Copilot and opsiff June 2, 2026 12:58
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Guard workqueue initialization and cancellation in the MediaTek JPEG driver so that work items are only set up and torn down for multi-core hardware variants, avoiding warnings and potential issues on single-core variants where the worker callback is NULL.

Sequence diagram for guarded workqueue init/cancel in mtk_jpeg_open/mtk_jpeg_release

sequenceDiagram
    actor User
    participant File
    participant mtk_jpeg_core
    participant Workqueue

    User->>File: open
    File->>mtk_jpeg_core: mtk_jpeg_open
    mtk_jpeg_core->>mtk_jpeg_core: check jpeg_variant_multi_core
    alt [jpeg->variant->multi_core]
        mtk_jpeg_core->>Workqueue: INIT_WORK(ctx_jpeg_work, jpeg_worker)
    else [single core]
        mtk_jpeg_core-->>Workqueue: (no INIT_WORK)
    end

    User->>File: release
    File->>mtk_jpeg_core: mtk_jpeg_release
    mtk_jpeg_core->>mtk_jpeg_core: check jpeg_variant_multi_core
    alt [jpeg->variant->multi_core]
        mtk_jpeg_core->>Workqueue: cancel_work_sync(ctx_jpeg_work)
    else [single core]
        mtk_jpeg_core-->>Workqueue: (no cancel_work_sync)
    end
Loading

File-Level Changes

Change Details Files
Guard work initialization and cancellation with the multi_core variant flag to avoid operating on unused work for single-core JPEG hardware.
  • Wrap INIT_WORK for ctx->jpeg_work in a check for jpeg->variant->multi_core within mtk_jpeg_open() so work is only initialized on multi-core variants
  • Wrap cancel_work_sync(&ctx->jpeg_work) in a check for jpeg->variant->multi_core within mtk_jpeg_release() so work is only cancelled when it was initialized
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backport of an upstream fix for the Mediatek JPEG driver: single-core variants do not assign a jpeg_worker and never use ctx->jpeg_work, so calling INIT_WORK with a NULL function and cancel_work_sync on an uninitialized work item triggers warnings. The fix gates both calls on variant->multi_core.

Changes:

  • Guard INIT_WORK(&ctx->jpeg_work, ...) in mtk_jpeg_open with jpeg->variant->multi_core.
  • Guard cancel_work_sync(&ctx->jpeg_work) in mtk_jpeg_release with the same check.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Since jpeg->variant->multi_core now gates both INIT_WORK() and cancel_work_sync(), consider adding a small comment near the condition explaining that single-core variants never queue jpeg_work, to make the rationale clear for future maintainers adding new variants.
  • If feasible within this driver’s patterns, you might add a sanity check (e.g. WARN_ON(!jpeg->variant->jpeg_worker) when multi_core is true) to catch misconfigured variants that declare multi-core support but do not provide a worker callback.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `jpeg->variant->multi_core` now gates both `INIT_WORK()` and `cancel_work_sync()`, consider adding a small comment near the condition explaining that single-core variants never queue `jpeg_work`, to make the rationale clear for future maintainers adding new variants.
- If feasible within this driver’s patterns, you might add a sanity check (e.g. `WARN_ON(!jpeg->variant->jpeg_worker)` when `multi_core` is true) to catch misconfigured variants that declare multi-core support but do not provide a worker callback.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@opsiff opsiff merged commit 83c8511 into deepin-community:linux-6.18.y Jun 3, 2026
5 of 12 checks passed
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: opsiff

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants