From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CB93409131 for ; Mon, 20 Jul 2026 12:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784549810; cv=none; b=RVsk7PRhGWEY+dhRuV/BoY5w2051nHNux48TzdFOZti7Z8hFjGrmguWlBk+ANjG7XPkCaqoNfHbZBGgB5zou+5oK6zhEaSdXVFxpJ7EFSOXKsuPkbYzX5WEUqJ8bRGGUP5I32R9eL9gJ4FKm9EtnweG2SdfD4vl2N+5EOEY79UQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784549810; c=relaxed/simple; bh=y7QvP9K6quV4Gyq9GwqoIKBapnIuTBwzwL8TWMBSwdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ohDVb5hzLHhUsG27N7OkN7AvmwW0Wgl7Yis9Fld3Lxp49/8P/CEhdNltHwvxVGk0kTv3Bs6j+IhsXGje+VHwUsvnuIs3lkeiQ0RJ5hgmHRXdGHjdJglc+zgrxX1Bi+6vr59a6cxYnpitPKf6Gc2IWX648DWG0LC1tj7cutf2Ejw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=F3ad+SXI; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="F3ad+SXI" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-49557167508so15467405e9.1 for ; Mon, 20 Jul 2026 05:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784549803; x=1785154603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FP9BawSk4EnMBpCTI/eZ7+cvzr/uqbM9j4RMitQlXio=; b=F3ad+SXIHcfhbwT1po3Bti0ZvyAcCegBxB9IewnQNPi9QJ1C0iLK9ile7drvuJWjMz nwtDiynEUMuAx0/Nwc131QSmTs4hysdqHkozJN7wPW19c/CdvOt3jsGUVwkQzRHeYj1C YSsHDIsVdzK1cbzOzXW3xhp7+ATjwlQOMCBXEZZhs6D9FwC4XGeEcgfVjb+Tku05yCMY lI33xcvDN+XEtexz5NMG/gZtobX1wEsP84WuYiQov2OI+j1vo9lBvbLHH/J8nKr5sUX1 n2OqwhhDE7KGZbftTZ4/QJFZNXdnLlYsaBxm9VjCe2s1LETco1V3Rkjzk5dMVC4Wdu4Q RzDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784549803; x=1785154603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FP9BawSk4EnMBpCTI/eZ7+cvzr/uqbM9j4RMitQlXio=; b=PYSKsm0MRMDYw2PW8vHRmfipI2U9KNgzqzb7qSUvhy3LAmryqmxDRsZxN4kcUi2796 01wCfZKerBego5BqLk64aFs4e13uggioNjYSfOAQua42654DpGnWzKZ02btmlkUHVzto MhMZ9KesbQZnl//Rf0vdz+wPWX82Q7C52B0MqN7ICiyosbkhhzGLrfpF+9SGQm6/ab7p 0HDVHu7LqqTLwtaPDzsI1ugbgXSEpTWFF7Y2ZFf3z+M8MN3hTqGoc9/2jpQO69YQk5GT kjddB7OZPYwjdAMU/SA9ybLOZviZ+B5RvLX2LnOsyatNDy9CQqVFJfZuuEBUzI4j1p3v +xmQ== X-Forwarded-Encrypted: i=1; AHgh+RpvSnvEQ16RYKlXLPHGxBhKt616j2HWZ7M7BWDawKAREjT26jGyNqK3SnRvg21RLZHShlj5c//r1UOBu6s=@vger.kernel.org X-Gm-Message-State: AOJu0YzKKGh2oTdwlc5qvIHSIdSXE+9sTgCaH/2kypFb+qlMFuK58mn1 ohWttZW5SVtqtcPMI+N2jUmJFdLr0nGkw0rZCNxj1H8NmW+mMKOIs6k2JF7msxgEcpkI37iIjme 6bghFiUs= X-Gm-Gg: AfdE7cnpmoUVNUsLr56WUOHLlWKOMldpW0n2NH6+bviryNCG2c2DEckewKEuOkGt1rM VmPeS7hKhfTbjdGK/+dXAHuK2+eQNXAb/2uY6k5uXy9AS4szrr8nv/fmBtfyK0qBqTwHmpqTTTG WQROTSVFfkUE2I4ThaveZaNfFpyDZWf2nA4fWMkcQS7WbrqcruPkdUJQBeY9UWSt1aRp9OiilEt HSgQZ0KhKwa36HuD/9tf1KsQH4g7LHdbhWCmWUvoe+Y/TLEtpiCWbedbcXFMHsV5KpjfX46yV9C 8i87eSKOjduGamRWO0fyNWh9GEMZd2L1VsLo9bli7dS+cJeKC7qxDu13Q/sBJkAWn5uCp3eoh0Q NaaTBHySdT+4PoafAkGtQY+3fuMKvvgPkTBnKpSPP7XUw6zX/sD5eABvlXNX92om+EoSUwXXB7M yH+zYO9hTJ X-Received: by 2002:a05:600c:6298:b0:493:c182:6b08 with SMTP id 5b1f17b1804b1-4954a5125a0mr159730355e9.36.1784549802964; Mon, 20 Jul 2026 05:16:42 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f63ed1911sm31424338f8f.22.2026.07.20.05.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 05:16:42 -0700 (PDT) From: Petr Pavlu To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] module/dups: Use scoped guards for kmod_dup_mutex Date: Mon, 20 Jul 2026 14:15:28 +0200 Message-ID: <20260720121621.750661-4-petr.pavlu@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260720121621.750661-1-petr.pavlu@suse.com> References: <20260720121621.750661-1-petr.pavlu@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Using scoped guards for kmod_dup_mutex shortens the code and clarifies where the lock is taken in kmod_dup_request_exists_wait(). Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index f0bdd7560d7e..a62619ec057e 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -97,9 +97,8 @@ static void kmod_dup_request_delete(struct work_struct *work) * kmod. The inneficies there are a call to modprobe and modprobe * just returning 0. */ - mutex_lock(&kmod_dup_mutex); - list_del(&kmod_req->list); - mutex_unlock(&kmod_dup_mutex); + scoped_guard(mutex, &kmod_dup_mutex) + list_del(&kmod_req->list); put_kmod_req(kmod_req); } @@ -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) { /* * If the first request that came through for a module * was with request_module_nowait() we cannot wait for it @@ -140,7 +142,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) if (!wait) { kfree(new_kmod_req); pr_debug("New request_module_nowait() for %s -- cannot track duplicates for this request\n", module_name); - mutex_unlock(&kmod_dup_mutex); return false; } @@ -150,13 +151,10 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) */ pr_debug("New request_module() for %s\n", module_name); list_add(&new_kmod_req->list, &dup_kmod_reqs); - mutex_unlock(&kmod_dup_mutex); return false; } - get_kmod_req(kmod_req); - mutex_unlock(&kmod_dup_mutex); - +dup_req: /* We are dealing with a duplicate request now */ kfree(new_kmod_req); @@ -214,14 +212,12 @@ void kmod_dup_request_announce(char *module_name, int ret) { struct kmod_dup_req *kmod_req; - mutex_lock(&kmod_dup_mutex); - /* * Find the entry previously added in kmod_dup_request_exists_wait() * that is owned by the current task. */ - kmod_req = kmod_dup_request_lookup(module_name); - mutex_unlock(&kmod_dup_mutex); + scoped_guard(mutex, &kmod_dup_mutex) + kmod_req = kmod_dup_request_lookup(module_name); if (!kmod_req) return; -- 2.54.0