From mboxrd@z Thu Jan 1 00:00:00 1970 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: 7bit 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 = (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))); }) -- 2.54.0