From: Petr Pavlu <petr.pavlu@suse.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH 3/5] module/dups: Use scoped guards for kmod_dup_mutex
Date: Mon, 20 Jul 2026 15:28:46 +0200 [thread overview]
Message-ID: <e4087c28-c79e-4261-8881-68034fada860@suse.com> (raw)
In-Reply-To: <20260720122533.1F9661F00A3A@smtp.kernel.org>
On 7/20/26 2:25 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] Mixing goto-based cleanup labels with scope-based cleanup (scoped_guard) in the same function.
> --
>
> --- Patch [3]: [PATCH 3/5] module/dups: Use scoped guards for kmod_dup_mutex ---
> commit 3299ca2ac8ae46392f412ae7c186f4907e7f8201
> Author: Petr Pavlu <petr.pavlu@suse.com>
>
> module/dups: Use scoped guards for kmod_dup_mutex
>
> This patch replaces explicit mutex_lock/unlock calls for kmod_dup_mutex
> with scoped_guard to shorten the code and clarify the lock's scope.
>
>> diff --git a/kernel/module/dups.c b/kernel/module/dups.c
>> index f0bdd7560d7e7..a62619ec057ed 100644
>> --- a/kernel/module/dups.c
>> +++ b/kernel/module/dups.c
>
> [ ... ]
>
>> @@ -122,10 +121,13 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret)
>> INIT_DELAYED_WORK(&new_kmod_req->delete_work, kmod_dup_request_delete);
>> init_completion(&new_kmod_req->first_req_done);
>>
>> - mutex_lock(&kmod_dup_mutex);
>> + scoped_guard(mutex, &kmod_dup_mutex) {
>> + kmod_req = kmod_dup_request_lookup(module_name);
>> + if (kmod_req) {
>> + get_kmod_req(kmod_req);
>> + goto dup_req;
>> + }
>>
>> - kmod_req = kmod_dup_request_lookup(module_name);
>> - if (!kmod_req) {
>
> [Severity: Low]
> Does this mix scope-based cleanup with goto-based cleanup in the same
> function?
>
> Looking further down in kmod_dup_request_exists_wait(), there are still
> several goto statements that jump to an out label for manual cleanup:
>
> if (!wait) {
> /* ... */
> *dup_ret = 0;
> goto out;
> }
>
> ret = wait_for_completion_state(&kmod_req->first_req_done,
> TASK_KILLABLE);
> if (ret) {
> *dup_ret = ret;
> goto out;
> }
>
> *dup_ret = kmod_req->dup_ret;
>
> out:
> put_kmod_req(kmod_req);
> return true;
>
> According to include/linux/cleanup.h, the expectation is that usage of
> "goto" and cleanup helpers is never mixed in the same function. All resources
> that need a "goto" cleanup should either be converted to scope-based cleanup,
> or none of them should.
>
> Should put_kmod_req() be converted to use scope-based cleanup as well, or
> should this function avoid using scoped_guard() to keep the cleanup pattern
> consistent?
>
Fair, I'll clean this up.
Sashiko also reported the same issue in a reply to patch #5.
-- Petr
next prev parent reply other threads:[~2026-07-20 13:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 12:15 [PATCH 0/5] module/dups: Fix a use-after-free and improve the code Petr Pavlu
2026-07-20 12:15 ` [PATCH 1/5] module/dups: Fix use-after-free in kmod_dup_req lifetime handling Petr Pavlu
2026-07-20 12:32 ` sashiko-bot
2026-07-20 13:28 ` Petr Pavlu
2026-07-20 12:15 ` [PATCH 2/5] module/dups: Inform duplicate requests about the result directly Petr Pavlu
2026-07-20 12:28 ` sashiko-bot
2026-07-20 12:15 ` [PATCH 3/5] module/dups: Use scoped guards for kmod_dup_mutex Petr Pavlu
2026-07-20 12:25 ` sashiko-bot
2026-07-20 13:28 ` Petr Pavlu [this message]
2026-07-20 12:15 ` [PATCH 4/5] module/dups: Use strcmp() to compare module names Petr Pavlu
2026-07-20 12:15 ` [PATCH 5/5] module/dups: Clean up includes Petr Pavlu
2026-07-20 12:32 ` 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=e4087c28-c79e-4261-8881-68034fada860@suse.com \
--to=petr.pavlu@suse.com \
--cc=linux-modules@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox