From nobody Sat Jul 25 18:53:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D467412BF1 for ; Tue, 14 Jul 2026 18:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053150; cv=none; b=XgJoZ7zly3+0mQbLwUg4UHfBu+oyqmUq7duu1zNfEO5grPO2iy5ZUjSSigeH0BNpTzdpjwstlRTVkvdoWwrX68uUZh5arStORnvQlZQ61pjx/485eWXmY1cudpgzxtf+lkJcan/sCYBiTC6RpwEcKGoLhGC1Yg8325sZYKfIYpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053150; c=relaxed/simple; bh=3nbJrS6vk429rHFDM4rtrdwYDhRr+UtI2moSoH5wKr4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HunfRhPnUtJulXG1JV+xxGcRK5UHZcLrYwhsW+WKTnSbOABlywTTjmRaeNnefUqXY0TN/fUm2p7Vgf0XvvWbHcyRxNKaWndMTyRKtHmfG2KPyYQUjKl+zfJYeJJNJMaIewdoR5KTfYPrYTAFBZGY1JwQhKEVWeWzeUXihf6hiAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xpupo4Yy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xpupo4Yy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22D11F00A3A; Tue, 14 Jul 2026 18:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784053149; bh=UJziocCdOR/0V6BNOwRnyb8Qu7YTGHUrYemlhp1W+tE=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Xpupo4YyLsdFNDKddnW3ZeAIXUcA1l/3u+UES6KCmPAOmuJ/z+ascISWio77xdO+m UuVjj6n+jPHyGF4+PSZF/ZpnJiMw0MbMTh38YCvKU6dYv5sopsUNe83CCWF6gHaKtA MNm/weVIrRG8p6kUsvOzVIf+RMaE6yGGW9Jz70ISu+I/nDDSLCuf/n/bDhbfl2KwK+ RlSJn9ZXvp3n/8oZqJLjA9ZqFZ23HdE0H/lA+Sdqv1POIxJyKGG2rQOSGw6e1TYPtS A4CcT6XtgMY29BM7vecTDUXA+52aOJrqYDa3r7EC8OQHLG+dHWFBTGiHSemDg52UpM OgSGvdWMnH6wA== From: Vincent Mailhol Date: Tue, 14 Jul 2026 20:18:01 +0200 Subject: [PATCH 1/3] container_of: apply typeof_member() to container_of() 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: quoted-printable Message-Id: <20260714-containerof_refactor-v1-1-b5c31164d2ad@kernel.org> References: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> In-Reply-To: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> To: Greg Kroah-Hartman , Andrew Morton Cc: Rasmus Villemoes , Sakari Ailus , Nick Desaulniers , Alexander Lobakin , Arnd Bergmann , David Sterba , Ivo van Doorn , Alexey Dobriyan , linux-kernel@vger.kernel.org, Vincent Mailhol X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1178; i=mailhol@kernel.org; h=from:subject:message-id; bh=3nbJrS6vk429rHFDM4rtrdwYDhRr+UtI2moSoH5wKr4=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFlhtVM1D2ulVt2c2JW2P/x5XJ6nlmVE7V/x3yG6TK8Zn DuN+Bs7JrIwiHExWIopsiwr5+RW6Cj0Djv01xJmDisTyBBpkQYGIGBh4MtNzCs10jHSM9U21DME MnSMGLg4BWCqJbsZGZZueSfw6AGj7JWCtf/uMJlxan8P3XM8d6Jekf8xplLz72YM/1Q4bIpOtnk wy3b8mL7E5Ayn5yveE8eVm16oVF6d+W8RCycA X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 container_of() uses the construct below: ((type *)0)->member to retrieve the type of the structure's member and then ensure that it matches the type of the given pointer. This construct being rather difficult to understand, the typeof_member() macro was created to encapsulate it and give it a descriptive name. Apply typeof_member() to container_of() to make it easier to read and understand what this macro does. Signed-off-by: Vincent Mailhol --- include/linux/container_of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/container_of.h b/include/linux/container_of.h index 1f6ebf27d962..28500a62ab7e 100644 --- a/include/linux/container_of.h +++ b/include/linux/container_of.h @@ -18,7 +18,7 @@ */ #define container_of(ptr, type, member) ({ \ void *__mptr =3D (void *)(ptr); \ - static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + static_assert(__same_type(*(ptr), typeof_member(type, member)) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) --=20 2.54.0 From nobody Sat Jul 25 18:53:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26860417BC4 for ; Tue, 14 Jul 2026 18:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053154; cv=none; b=c+GetTrsNIR6a0VYcA5p+SWIgX3kvkRxneIRhe6pDzJC3rNwRwreo29aY6ZV0FRvlp9upxkr3OR/cWbH/e4GxOMHCzqUcL2vVEy9Jb8UWsLMjEMaAWKCS/E+fwe3iYUQ/qa/xi+gGL4LKMCGO62azCxFqakBTiAaf+AZodopgAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053154; c=relaxed/simple; bh=86JrylRqF2Y0wu16+tADGbf7vhJCNXnUxFnJluBmvg8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E32jjp5GulptexBqk1sXl4Q9yqGO1o8NLsCHRO74ReBT8PUSz9jlN+ijvV55Fshj0fBaP7VBSengqo41gttq4q87F9x8viCojdSdqO2pLoBwQSFFnRLYMIqm6XWw8IzK6Kr4RED2izEMnez4WWAZ6sztFs7DX8ERe3n4hARJGsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qdd/3ySX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qdd/3ySX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A56731F000E9; Tue, 14 Jul 2026 18:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784053152; bh=qpcpNib6c8BR4jGpn6MIyZn6pdsDPlY6rVuiClUwtWQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Qdd/3ySXw2XMFw7BjV5Oh28maLkZaLQESS/xlA4J0+6jj75QHnqKRteRwMHRQqh2L j0SZvOcGo7WCLlqvN60pktcmHJO4pimiojcV0logm2+g6Zl0mSlaeLR8giwYcqbr1t ioJ5R1mv/6FIrv3B2VujakCwKRKCpR0YQncrW6psb8tfORCKa8R5axt4UIBOj8p3nn Auep/wLC1ZAbyr66tndUdB7BziJkznS1QZapehCi8AIDxeox+M+xwe7Eajlyc6E2kE FQuZHU7lF6/v74G2e1dZhMS8Kn9SPzNxMrrey7gNCcNJqudcm+ONYrZwGvGKp7GSlR THlFuDLJD0fqg== From: Vincent Mailhol Date: Tue, 14 Jul 2026 20:18:02 +0200 Subject: [PATCH 2/3] container_of: remove useless pair of parentheses 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: quoted-printable Message-Id: <20260714-containerof_refactor-v1-2-b5c31164d2ad@kernel.org> References: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> In-Reply-To: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> To: Greg Kroah-Hartman , Andrew Morton Cc: Rasmus Villemoes , Sakari Ailus , Nick Desaulniers , Alexander Lobakin , Arnd Bergmann , David Sterba , Ivo van Doorn , Alexey Dobriyan , linux-kernel@vger.kernel.org, Vincent Mailhol X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=817; i=mailhol@kernel.org; h=from:subject:message-id; bh=86JrylRqF2Y0wu16+tADGbf7vhJCNXnUxFnJluBmvg8=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFlhtVOvW2kpn33sFB8qabT2VP5C+YQTW7g/Vs1U2KN1W bI1c+HDjoksDGJcDJZiiizLyjm5FToKvcMO/bWEmcPKBDJEWqSBAQhYGPhyE/NKjXSM9Ey1DfUM gQwdIwYuTgGY6uzfjAxPtJ/ruSen7jbj2P8/4krVU51/n7n1fr02+qMpsa9vxtUKRoYlwsefztP +c6Zmg+7lm0rtl38+mGfVKHa/5f1xZRP7slOMAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 The last expression in container_of() doesn't need an extra pair of parenthesis. Remove it. Signed-off-by: Vincent Mailhol --- include/linux/container_of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/container_of.h b/include/linux/container_of.h index 28500a62ab7e..68153170db32 100644 --- a/include/linux/container_of.h +++ b/include/linux/container_of.h @@ -21,7 +21,7 @@ static_assert(__same_type(*(ptr), typeof_member(type, member)) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ - ((type *)(__mptr - offsetof(type, member))); }) + (type *)(__mptr - offsetof(type, member)); }) =20 /** * container_of_const - cast a member of a structure out to the containing --=20 2.54.0 From nobody Sat Jul 25 18:53:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B55063CEB8F for ; Tue, 14 Jul 2026 18:19:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053157; cv=none; b=r2Uq2s/6Rb0YINxFQVJhz09FjB3wzZM9hz/ati5O9gbb/TLI7D+EK0oEoYDY0ytX1nSQfQD2qhv5huSANgz8hAc5L8b7Uy1yU66H+qufJA6ThaSCjn8CAez+RFmZMQ2kj/RFObxbseUo3uUG5sEu9SWHRsvYhpDdacr9bybJ80I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784053157; c=relaxed/simple; bh=7NFj/emOgsY9GEv/OH9A4u2qBwoVeXtzkgjhw7O2l3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kiFJCBOIuuDom1jSvxtvlgMX9ypl9hVF1JulPfK89ygs4wNyT24P4JMgZ1WzejT2qMYGfpLgtGVrT+IVstz2a4hB8cUh7iklx4wfIVtj7EAO0RlIDLD1CTX84N4nCVapPnsZhUU24mtEH+ZII14y69HIgKOLJ6KQwGywUA8C7lU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=in9fYw6p; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="in9fYw6p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 591541F00A3A; Tue, 14 Jul 2026 18:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784053156; bh=gfmUBrKFDs66Cd7+EN9Qk8wgLF9gqj4Shou1+JcrIe8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=in9fYw6puhWRXS9eU5dtx4S/3JHKB6xtHA2jyJPv+FFWfjkQ3izRedFD/Jg7tUy29 vaK6jaR1HoxrnxaNHrKs2/VjxBVTs8i0+gGGyFAXlkHYQsCvQOyHlOr7U2rwAHz01P dfxxeLmP0zPdxLWGic4w7AmzIdQ4E6GmiUfCMu8cX8QjhED5LwoRHdMpCQUllXI94p 8P10/64kBZ2QgnsJIRte8av0h+mO9S9AM3iGiXqWzSeXCvzBY/yIa4fExTUvnFywQ7 2PWqZ94n6pfsNZVfYHOCWpLkOs5QD9hYRxbFoQ/MNICh/LKeG3H+JPvznbKCWspw/+ lh5mIQfy1q60g== From: Vincent Mailhol Date: Tue, 14 Jul 2026 20:18:03 +0200 Subject: [PATCH 3/3] container_of: remove local __mptr variable 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: quoted-printable Message-Id: <20260714-containerof_refactor-v1-3-b5c31164d2ad@kernel.org> References: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> In-Reply-To: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> To: Greg Kroah-Hartman , Andrew Morton Cc: Rasmus Villemoes , Sakari Ailus , Nick Desaulniers , Alexander Lobakin , Arnd Bergmann , David Sterba , Ivo van Doorn , Alexey Dobriyan , linux-kernel@vger.kernel.org, Vincent Mailhol X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2303; i=mailhol@kernel.org; h=from:subject:message-id; bh=7NFj/emOgsY9GEv/OH9A4u2qBwoVeXtzkgjhw7O2l3Q=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFlhtVNFGB7NPLtjdbeR+T3PFx3Vv2cKWpjdkm9X9FzL/ +SRx3+zjoksDGJcDJZiiizLyjm5FToKvcMO/bWEmcPKBDJEWqSBAQhYGPhyE/NKjXSM9Ey1DfUM gQwdIwYuTgGYaiVtRoYXW+ecNLqzeuP+Baw/sz0npuW4KWgw/uizMtViCvtuxS3D8N+BV2jeV9b lL+eXRM973qHQxb7BjV3m0J/pR/um5fldPs0EAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 container_of() can be called in a nested manner to retrieve the grand parent structure as illustrated below: struct foo { int a; }; struct bar { struct foo foo; }; #define to_foo(a_ptr) container_of(a_ptr, struct foo, a) #define to_bar(a_ptr) container_of(to_foo(a_ptr), struct bar, foo) The issue is that the above construct will cause __mptr, the local variable of container_of(), to shadow itself because of the nested call. This then triggers a warning in sparse and W=3D2 builds. While this warning is benign, it still causes some overhead as proven by below list of commits in which people made local workarounds: - commit 7eab14de73a8 ("mdio, phy: fix -Wshadow warnings triggered by nested container_of()") - commit 8d8c3131248d ("clk: define to_clk_regmap() as inline function") - commit bfb972c5e1cb ("IB/verbs: avoid nested container_of()") - commit 093adbcedf12 ("btrfs: switch helper macros to static inlines in sysfs.h") - commit c1d35dfa0f7d ("rt2x00: Fix sparse warning on nested container_of()") (the list is probably not exhaustive). As a matter of fact, the local variable __mptr is only used once in container_of(). As such, it is not strictly needed. Inline that local __mptr variable to remove once and for all the risk of variable shadowing when nesting container_of() and prevent people from writing further local fixes. Signed-off-by: Vincent Mailhol --- include/linux/container_of.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/container_of.h b/include/linux/container_of.h index 68153170db32..28db38e9ee3e 100644 --- a/include/linux/container_of.h +++ b/include/linux/container_of.h @@ -17,11 +17,10 @@ * Do not use container_of() in new code. */ #define container_of(ptr, type, member) ({ \ - void *__mptr =3D (void *)(ptr); \ static_assert(__same_type(*(ptr), typeof_member(type, member)) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ - (type *)(__mptr - offsetof(type, member)); }) + (type *)((void *)(ptr) - offsetof(type, member)); }) =20 /** * container_of_const - cast a member of a structure out to the containing --=20 2.54.0