From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 3A62F3EEAC3 for ; Thu, 23 Jul 2026 08:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795214; cv=none; b=mTWHjLPYg4eYOJ2YgpIFuP/Z5/pke2AcGKWnxPg0VYYsl4i2yUFpLbuZXrVV0Q9aSrGP88Y3jXQIXJsOnQzWNh2nKaYko03qwg58oyXxlHJ0Jj2ueY09uRp4w9y1FBMqp4olgNSSUzbg6BL1KO9eljK8KR7kvmByR3Qykj6r9ic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784795214; c=relaxed/simple; bh=M3w/NX8EtAs4Vp3CPWjzqrrqNViRwAZKhFJyEdDma0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tnNZKDXkpM7XyVMI1I1x+LW2+ud25uBvHYvm7IFnS0giGKulB8LZ4jnRGc2PKRiy3tRV5COiCnl+jH9NH7yEKB9+BZ+YW3BBlCE69VA+8x60WGE6e3/oruEe1gcwNZgmLb2jdCXoB2lWCQ/sa4yaoAZshLII6tFFOcn8/n7q2G8= 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=AZQ9kxEF; arc=none smtp.client-ip=209.85.128.45 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="AZQ9kxEF" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4954dff6536so3005715e9.0 for ; Thu, 23 Jul 2026 01:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784795203; x=1785400003; darn=vger.kernel.org; h=content-transfer-encoding:content-type: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=8CrImD1PV1oAhd0eWI5Z44JgRoeHcEfNsqmH16WcFSY=; b=AZQ9kxEFUchQYlt+brTREg1eZVH20Bjyb3LL0QxyL6XyEOMonuC6MBmI2sztmuxM/U wixwjN3A7/d6UwesdF5F6ZJ9CFZXzQdjVpV9ajV0R/2QrZetNOm2wmmJTW/I+UZ/Czbu jBArDZblt3ic382vyDmxTP96k5G/8s3Wra0ETo89GvSAF5YWcyin81mgmJz4H8KzalYf eNw3HZgXfEq+RGfXyVBXWGvZnA9hf8dHbl2Ox2lnG03WCZullM1EmkYS0nT19Vz/u4yg PuK6DTghZjBK9jID2H4tMlXQIbiHd6iwlxzsi6E0zvhAgR/76jKyq+eQbBJShLSpm7qX 7zyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784795203; x=1785400003; h=content-transfer-encoding:content-type: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=8CrImD1PV1oAhd0eWI5Z44JgRoeHcEfNsqmH16WcFSY=; b=axhd4PKkuG2U3LHGqddYIM74gOoED8wEIjkGdZhkTZGB+fTl/pNuYH4fElwrOiFyVU ZXkEq0qGS3wsECgrWVA4wbXNQ4RoDbycVxej1+ySa0MjefpAp4YwdakecxbkctkYk8X4 O5LvCMl9DiMXWu+mmSh3ti9heB7PozMnh9PAQJ5vFlF3GhWDxmS2zjkdisQqVk4Sufdc b45rIa+RvF8fDKGbj3N0+uozl+zZt6RCxIrqhv5E6Jz742su2pxYxECUZFzmKucm6Ys6 Evwp9dkWlz+CKvrSeXFnHJnXna60iLnCdGd1mt2fOT4fjckb8+nYfslQ0yWfqugV4zdn DVqA== X-Forwarded-Encrypted: i=1; AHgh+RrizkBtaZ5xf46u0nQ7oHfoWDVmil5pmrIO7cmqh/URqZkqrQczmEk/Q7xckRhL+gA/w3vZrEOh9iFFF04=@vger.kernel.org X-Gm-Message-State: AOJu0YwnBifbbttDNlQbuczoSYRojz2F8dQcTF11dYYScZDC5h11dY/5 6MckOBaU2osnd2/8CMOQN4OQs8yOHEFSXGsFW9B8XIIj9rT2UPe0WLT+A9IC4QbxjFI= X-Gm-Gg: AR+sD12tuRaIyjX7qzeyAR5jZWf80y8pLHWklt9qyYiDbILIi/6hXOJeVt50O6slswj m4d0ulQR32f8A7B2pKcUaA3u+D6fvrDdOe9Olkrq6r0uyvgLHO8+jIiIC1AD72TJBvBrHmZ5qJb lAmQ9r3ri+WnpoJERJMVTZnaq1tqT84QPgbvA67ki7wE3yZ7XDH0dnpE4CivHVtWNBe9Tk2pDGX 9PQgW5Zn8hr9CHiWspsuFTd86Xkp/lhm4OgFtpbl1xNW9OcS4QcJcnbKCd04r4HvBuAHhMriqG/ 5vP/NFjMZhKD/Z8rZSY4j8rY/tl5xl88x7Xdqx/GZDExL1cUceYZlhFZZ1j5kbi1oFHGzIZ+lGR UJm+UiPmv5XPtDgXMzo8jC8MBuYESWvLhqzwfxU+/cVWYRRwq+3n24eRO8s2tkSmX48FwrDiyHQ == X-Received: by 2002:a05:600c:548a:b0:493:eb71:5cc6 with SMTP id 5b1f17b1804b1-49573d0eac1mr21539715e9.27.1784795203484; Thu, 23 Jul 2026 01:26:43 -0700 (PDT) Received: from zovi.suse.cz ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4956a4f9a1csm124831645e9.5.2026.07.23.01.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 01:26:43 -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 v2 4/6] module/dups: Use scope-based cleanup helpers Date: Thu, 23 Jul 2026 10:25:54 +0200 Message-ID: <20260723-module-stats-rcu-v2-4-bd582261fae3@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> References: <20260723-module-stats-rcu-v2-0-bd582261fae3@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Use scope-based cleanup helpers for kmod_dup_mutex and kmod_req to shorten the code and to clarify where the lock is taken in kmod_dup_request_exists_wait(). Signed-off-by: Petr Pavlu --- kernel/module/dups.c | 56 +++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/kernel/module/dups.c b/kernel/module/dups.c index 0f6bb05b2d81..56d659f049c5 100644 --- a/kernel/module/dups.c +++ b/kernel/module/dups.c @@ -63,6 +63,8 @@ static void put_kmod_req(struct kmod_dup_req *kmod_req) kfree(kmod_req); } +DEFINE_FREE(put_kmod_req, struct kmod_dup_req *, if (_T) put_kmod_req(_T)) + static struct kmod_dup_req *kmod_dup_request_lookup(char *module_name) { struct kmod_dup_req *kmod_req; @@ -97,9 +99,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); } @@ -120,15 +121,18 @@ static struct kmod_dup_req *alloc_kmod_req(const char *module_name) bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) { - struct kmod_dup_req *kmod_req; + struct kmod_dup_req *kmod_req __free(put_kmod_req) = NULL; int ret; - mutex_lock(&kmod_dup_mutex); - - kmod_req = kmod_dup_request_lookup(module_name); - if (!kmod_req) { + scoped_guard(mutex, &kmod_dup_mutex) { struct kmod_dup_req *new_kmod_req; + kmod_req = kmod_dup_request_lookup(module_name); + if (kmod_req) { + get_kmod_req(kmod_req); + break; + } + /* * If the first request that came through for a module * was with request_module_nowait() we cannot wait for it @@ -142,7 +146,6 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) */ if (!wait) { pr_debug("New request_module_nowait() for %s -- cannot track duplicates for this request\n", module_name); - mutex_unlock(&kmod_dup_mutex); return false; } @@ -152,18 +155,12 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) */ pr_debug("New request_module() for %s\n", module_name); new_kmod_req = alloc_kmod_req(module_name); - if (!new_kmod_req) { - mutex_unlock(&kmod_dup_mutex); + if (!new_kmod_req) return false; - } 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); - /* We are dealing with a duplicate request now */ /* @@ -190,7 +187,7 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) * calls bail out right away. */ *dup_ret = 0; - goto out; + return true; } /* @@ -205,14 +202,11 @@ bool kmod_dup_request_exists_wait(char *module_name, bool wait, int *dup_ret) TASK_KILLABLE); if (ret) { *dup_ret = ret; - goto out; + return true; } /* Now the duplicate request has the same exact return value as the first request */ *dup_ret = kmod_req->dup_ret; - -out: - put_kmod_req(kmod_req); return true; } @@ -220,26 +214,22 @@ void kmod_dup_request_announce(char *module_name, int ret) { struct kmod_dup_req *kmod_req; - mutex_lock(&kmod_dup_mutex); - /* * Look for a kmod_dup_req previously added in * kmod_dup_request_exists_wait(). Note that a request_module_nowait() * without its own kmod_dup_req entry can announce a result of * a concurrent request_module() call. */ - kmod_req = kmod_dup_request_lookup(module_name); - if (!kmod_req || completion_done(&kmod_req->first_req_done)) { - mutex_unlock(&kmod_dup_mutex); - return; - } - - kmod_req->dup_ret = ret; + scoped_guard(mutex, &kmod_dup_mutex) { + kmod_req = kmod_dup_request_lookup(module_name); + if (!kmod_req || completion_done(&kmod_req->first_req_done)) + return; - /* Inform all duplicate waiters to check the return value. */ - complete_all(&kmod_req->first_req_done); + kmod_req->dup_ret = ret; - mutex_unlock(&kmod_dup_mutex); + /* Inform all duplicate waiters to check the return value. */ + complete_all(&kmod_req->first_req_done); + } /* * Now that we have allowed prior request_module() calls to go on -- 2.54.0