From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 219012C9D for ; Wed, 29 Jan 2025 14:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159622; cv=none; b=FQXkqvsaqRYoPrqzOK1Kl+D75m0x+/l/8KczPQSDCRaC3vMJqurKRnRPUmHuiKhafKhtRsr6/8GaLYs7c+WvqrsvuSg/YO9vqd6PO/YXGICWtlI3E2ksi6AhyMCYIddd3z2F8hKhBcJxzGLcxucKQQZNEjJF3ku9HpQrOz15Hy8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738159622; c=relaxed/simple; bh=0oqbYSqMzR5BC2SYSdU2hgzMX3TTGyHmwAOHuZJrCHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GdJaEpMUOIuvBrGHAAUnss2Qv0iwg+ust7/g2rWeq7PvKoyhEQnB2lMo+IrQMbeCDKrF1zuA+RB6cS1MmcULPm36G7NyCMacc1Bs2sldcmg2+w3jj77ViuXN38stPOuuOAVRvTiC+Z1EWCj66tFV+uVd/Q6TmEj8xIZlU0oBW+M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=X2ovEZGB; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="X2ovEZGB" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4361b6f9faeso5371275e9.1 for ; Wed, 29 Jan 2025 06:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738159618; x=1738764418; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=bG50zjaH0VQq5duenMAZ/yyFRhpZ3VsB6Mcg50lZ728=; b=X2ovEZGBxWqKYgHJvg5lIoIrWBmhHwlB9UaOZHFs2YY3nZrWzLdTM23o5BTE26PkWJ 7UjNa8XSL8XttfU0ptrKQauKvg0HKf3ewx3Ge6ij7C9Fwb59EMTK/XyXaadmd8wa4I2T 5fGwq25FzB50xKETTBuluQwIAz9rWQUgUwMyVBsDZcD6aS6iwhA1lsScpy5SWoXP7O01 Pj8uX58Nrn26d/DunrzCziF+/KxrfCYYGWoEP58H/cjWuUty6ToJSimtdrCszpdRGlsu 1tTqRPp0rlpRMPVK4AOJVhmK7ZpouIVSP7wwyUuZlDAkYTVsKs2y9Fae4J/Q/7Z/43ai incw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738159618; x=1738764418; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bG50zjaH0VQq5duenMAZ/yyFRhpZ3VsB6Mcg50lZ728=; b=iAAv2PKuA+uZlezuHCWUKC1zoWXICvKF9a20U/D4NPgc5M7xmG+/xhemZvG4bYmr8K WE1X7TbL6QuoOTmLk4RdammdyJyGf+Dl5qSF7/yGtQAaOvjqMZnGd45WFS+BCaY+4oNI GFP1ueiW63DLWb5JQs6wXyutcjbrJSpId5RzDNLsMAO3SCGooB4WI5HaZlVERhSpS0UI O3jQC6QutFVUT1GtZfl3By7bprvYR8jw4oGkY7+oTmfpXoAQN76+B5Msmg2E1c+FFhb1 wsjYPSCCc8R+plHUvOKrvffZTp6bTzALyFtrKLsqiBd4Rxo+9s/Px+DwmAfjFVpYC0DT fmRA== X-Forwarded-Encrypted: i=1; AJvYcCX7crK4nNPlac7MfVzfSXZz52lG1TAMXIvR1Rz963xPWN/N2uju6ToKdHgp9Nwma2LfMqBymwZ3ZTfcB0s=@vger.kernel.org X-Gm-Message-State: AOJu0YyIlnXrUyGKnX9x3Lkm7ILphRVOCUYq+ZuwhFx+ejk4v3DuEBJn 9APMB3+NQCKf2yvO97b8prmbGcWsscst/ttQ9ajtpPiwiC3qn87prndK04rXuTs= X-Gm-Gg: ASbGnctVRhwGHfV0aTMkyXiQVk3c4QMHWoKFm6r5TJth4X6pSyoyrMqANx9YlJCEHaZ NaO84ZJ/BkQ+r3r2umL85glK1FeCh6IHwh27whOqI8uOOQZ28bodcFwBIJji6tGt4374t40h2cD f+u6YlgJ2eLmT3dYd8UwR+iiWIlgic72TgDskLBxbybnHqtVrYuqfMFz4n6tnYQo3n2fGEm62Dx 1rLjr17kTjVvkaSzC7cBAAyMnEXJbii58EczGgDp+pRnBsVYp9hBRIGF91bkk2hzfizcT7YGS8O aM/jjejPfYCfClubmWNN X-Google-Smtp-Source: AGHT+IGppIz3FFFulk6wi89F9D24oagBc4AxX7sUQG+q/0EOoPmy6Sgd7sFPca8nukKltW3E9MQ4Fw== X-Received: by 2002:a05:600c:4f0f:b0:438:a313:cda9 with SMTP id 5b1f17b1804b1-438d599b9a0mr65389755e9.10.1738159618142; Wed, 29 Jan 2025 06:06:58 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438dcc13151sm24152535e9.1.2025.01.29.06.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 06:06:57 -0800 (PST) Date: Wed, 29 Jan 2025 17:06:54 +0300 From: Dan Carpenter To: Greg KH Cc: "Gustavo A. R. Silva" , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2][next] container_of: add container_first() macro Message-ID: <3979f87d-b7d7-48bb-b6ab-cd8165dbc3cc@stanley.mountain> References: <2025012955-hypnotic-patronize-8931@gregkh> <2025012921-dense-unplanted-952b@gregkh> <06aa1194-a7aa-4a5a-adb8-f6cd447d35d9@stanley.mountain> <2025012951-plenty-clang-1e2b@gregkh> 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=us-ascii Content-Disposition: inline In-Reply-To: <2025012951-plenty-clang-1e2b@gregkh> On Wed, Jan 29, 2025 at 02:14:14PM +0100, Greg KH wrote: > On Wed, Jan 29, 2025 at 01:39:27PM +0300, Dan Carpenter wrote: > > On Wed, Jan 29, 2025 at 09:34:07AM +0100, Greg KH wrote: > > > On Wed, Jan 29, 2025 at 06:35:18PM +1030, Gustavo A. R. Silva wrote: > > > > > > > > > > > > On 29/01/25 16:24, Greg KH wrote: > > > > > On Wed, Jan 29, 2025 at 03:56:01PM +1030, Gustavo A. R. Silva wrote: > > > > > > This is like container_of_const() but it contains an assert to > > > > > > ensure that it's using the first member in the structure. > > > > > > > > > > But why? If you "know" it's the first member, just do a normal cast. > > > > > If you don't, then you probably shouldn't be caring about this anyway, > > > > > right? > > > > > > > > This is more about the cases where the member _must_ be first in the > > > > structure. See below for an example related to -Wflex-array-member-not-at-end > > > > > > That's fine, but that's a build-time issue, you should enforce that in > > > the structure itself, why are you forcing people to remember to use this > > > macro when you want to use the field? There's nothing preventing anyone > > > from using container_of() instead here, and nothing will catch that from > > > what I can tell. > > > > The new definition has a static_assert() in it so it's enforced about > > build time. > > Yes, but that forces you to "know" to do that in the .c file. How do > you know to use this, and if you remove it or change it to > container_of(), it works just fine again. > I guess my use case is different from Gustavo's. For him, using container_of() is fine. We probably don't even need an assert because once you see a struct_group_tagged() then you know the order is important. For me, it's code like I mentioned which does: p = container_of(); if (IS_ERR(p)) ... And I did see you suggest that people re-write that kind of code, but no one is going to do that. :P People know that container_of() is just a cast in that case. It works fine. It's just a bit ugly. regards, dan carpenter