[Deepin-Kernel-SIG] [linux 6.18.y] [FROMLIST] media: mtk-jpeg: only init/cancel work for multi-core variants#1802
Conversation
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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideGuard 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_releasesequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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, ...)inmtk_jpeg_openwithjpeg->variant->multi_core. - Guard
cancel_work_sync(&ctx->jpeg_work)inmtk_jpeg_releasewith the same check.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Since
jpeg->variant->multi_corenow gates bothINIT_WORK()andcancel_work_sync(), consider adding a small comment near the condition explaining that single-core variants never queuejpeg_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)whenmulti_coreis 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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: