From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (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 E158E27FB34 for ; Sat, 13 Dec 2025 22:14:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.68 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765664066; cv=none; b=ATx3Nw0syRquVNtvakMG6oyUAfgss9dbtOcwjWSHNKf+goSquVrNuV2rdy3Ou7A3r57sr3YvQs57meEPwCELBfGgSy2Hop4isxDSXLP5yNbAwcRvpruFSzLjgzXwKjQrBjLBo+0sLJHF45jJQtxCu9nOGpKnIrYPlbOiiWAR2cE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765664066; c=relaxed/simple; bh=IrulDzi57n/yaskwyEHjfwEfdSp5VnPWem36VPxkOOU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cF8FVI2V27JUaICRD5gAE9ZnsIWl43bQWH+C5CpozNmcu6AKtJH5VSbk3fxowNI7niSPNLHc9hH30N9+t73l6ICSs8/i8SLwB8mh0ofQOVl4My2/fYgXmT+sajUgUJYcNDivD55JVRmWe70HJSuo4EVri516t02dBOFRI7QmcvY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VhK7UJtS; arc=none smtp.client-ip=209.85.128.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VhK7UJtS" Received: by mail-wm1-f68.google.com with SMTP id 5b1f17b1804b1-477563e28a3so17231285e9.1 for ; Sat, 13 Dec 2025 14:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765664063; x=1766268863; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=giGcT3Fgg+GDU3z63heonDhCKMawwzdbyDK3O3Qf/K8=; b=VhK7UJtSjFAhyFSRMxcleel1EWzAxSqHYp0edvhxGLRT3+8qBSx253kGaoUCJ4ZS2D I7/i72c+BVPSxlx517Brx09xZgu6rrwrCfue4A2VLAy6GY9B/8Oo5wb5IqzLDzVlwzxh W9CwXgaB3NVlP7jG9zny+Re5DtY03U8ZKhT/kAU9qLiuJcvfZAAQjJaZ96tXTGVXwySl u+HarJSO1DFMhyM3SFSY3EYkH8nKJDKTBQn4TGddPPUn70ijH45B915g3fGvuzCuiCwO eb/XItKm5+vWUfGV7p6xtqowfNwqTeba9tGubdkVgsH45JIJL3WeQSOkzZ6buy/XF6vA GuEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765664063; x=1766268863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=giGcT3Fgg+GDU3z63heonDhCKMawwzdbyDK3O3Qf/K8=; b=Ld4Iqi2/io6zBmP8qltyOqcUpQP4NLq2CU3Pa5m2su87UZDyx8vMrewVIhfQ5FKyXq ndooAbZcJAIL7UJBI5r+G6Y3xrgt6SezavRDaSVIRKdjzj59IDawPT7MEHh8IOQANKna QDgco6Q4F7csEbjmQks59c6CJgZEbi9ai8rzwp+ih11yeYXX8UohCwPn1NSgL3iykuTa fsEL6U/wSpuQwJ6Vr1eneFLWTEjp1MWSJl1MD+3LGyDx6Qxm+Nx2a/E+f8PeQpCq5AFj BlBQQNb2IX7LrmEB9QvDITVR05SbFL0k5yYVXLXBOuK1CUtqNDjXl4mgspmicq/fgWuR zhbg== X-Forwarded-Encrypted: i=1; AJvYcCXHN2eBE0vWtVibHChzPsjLD8yTEBYthvRdeukG4ZNfgVQY20z1WP6q6n6iSl2JmNogE7f0wcZXqsak5GM=@vger.kernel.org X-Gm-Message-State: AOJu0YxCra+lwIVS7qlfMbHrVzNVTba2iAUM/ms+TwU3e4WhWzA7WKIf bnnoeg+gMu7KDkqzo6oTZXrH6vMTsbL7YTPFqqTfLfWL4mrxU2SfF2mr X-Gm-Gg: AY/fxX5HKD+pNw7aTPm/dGWdLBZ9g+w2Wh8yub88bhPPs+goIBhc4QClK6DXgYo6uBz Haj6BXtDk5dmgcQ4eYiz4WiLKuld06P2Jkhqk8oPSbAbr2//Obr/J4W7NXLVSmWIlj7qGHoUxBf lrBhzkv0erBqTkVs2rkwhdjuDTuLlse9fYJCRUXK3xGmrsLi17S6Jdf9uqkAKK+JudS9Qny3bqb 3EeSmzfnA96pSCuzqddDP/nSjdNiMdLRUR04ZCzOXS8bqHraubQVda9QQvtW+80fO8RZ9TByvZl IJ1PpVN1flZyesVRqXMd3TFz8TSLwIu94PvEjKkq7rUyvp0dpXekv8m6oOQViWArEClih7BdBlH QclQZf0BiMBurSBb2WO5d8hauRwC1nVEd+9I9waXk+eU9ii00ro5+jJhmVI7hJxPz0wWrFVFh52 bT/MCEdM6XOk11oFgLHsT22j+xAGv21I39au0bmoh1PunFKHC5MYtkA5EAoOmdELk= X-Google-Smtp-Source: AGHT+IGlrJtrpuVRtNu5xu7PjaZA4tl0Mfc0rjvZxILWh7EkMUMhN8Y0w5oS1WFrdUcu1OL6FpZg3w== X-Received: by 2002:a05:600c:c101:b0:477:7588:c8cc with SMTP id 5b1f17b1804b1-47a89da461emr86627115e9.7.1765664062970; Sat, 13 Dec 2025 14:14:22 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f6f13bbsm38091375e9.10.2025.12.13.14.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Dec 2025 14:14:22 -0800 (PST) Date: Sat, 13 Dec 2025 22:14:20 +0000 From: David Laight To: Yury Norov Cc: Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Geert Uytterhoeven , Alexandre Belloni , Jonathan Cameron , Crt Mori , Richard Genoud , Andy Shevchenko , Luo Jie , Peter Zijlstra , Jakub Kicinski , netdev@vger.kernel.org, "David S . Miller" , Mika Westerberg , Andreas Noever , Yehezkel Bernat , Nicolas Frattaroli Subject: Re: [PATCH v2 02/16] thunderbolt: Don't pass a bitfield to FIELD_GET Message-ID: <20251213221420.10901610@pumpkin> In-Reply-To: <20251213100136.3d83a236@pumpkin> References: <20251212193721.740055-1-david.laight.linux@gmail.com> <20251212193721.740055-3-david.laight.linux@gmail.com> <20251213100136.3d83a236@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Sat, 13 Dec 2025 10:01:36 +0000 David Laight wrote: > On Fri, 12 Dec 2025 21:28:31 -0500 > Yury Norov wrote: > > > On Fri, Dec 12, 2025 at 07:37:07PM +0000, david.laight.linux@gmail.com wrote: > > > From: David Laight > > > > > > None of sizeof(), typeof() or __auto_type can be used with bitfields > > > which makes it difficult to assign a #define parameter to a local > > > without promoting char and short to int. > > > > > > Change: > > > u32 thunderbolt_version:8; > > > to the equivalent: > > > u8 thunderbolt_version; > > > (and the other three bytes of 'DWORD 4' to match). > > > > > > This is necessary so that FIELD_GET can use sizeof() to verify 'reg'. > > > > > > Signed-off-by: David Laight > > > --- > > > > > > Changes for v2: > > > - Change structure definition instead of call to FIELD_GET(). > > > > > > FIELD_GET currently uses _Generic() which behaves differently for > > > gcc and clang (I suspect both are wrong!). > > > gcc treats 'u32 foo:8' as 'u8', but will take the 'default' for other > > > widths (which will generate an error in FIED_GET(). > > > clang treats 'u32 foo:n' as 'u32'. > > > > FIELD_GET() works just well with bitfields, and whatever you do breaks > > it. I pointed that in v1, but instead of fixing it, you do really well > > hiding the problem. > > It doesn't, pass 'u32 foo:6' when using gcc. I've been trying to look up how _Generic() should behave for bitfields. Basically it doesn't seem to be specified in the C standard. Pretty much all you can do is force an integer promotion - and that only works if the size is <= 32. (I really hope there aren't any bigger bitfields lurking...) But FIELD_GET() wants to check that 'reg' is 'big enough' to hold 'mask'. An integer promotion breaks that for char/short. I did try erroring on statically_true(mask > reg), but that throws up a lot of false positives (even for non-constant 'reg'). It really is amazing that you get FIELD_GET(GENMASK(7, 0), val) instead of 'val & 0xff' (and I don't mean code that want the low 8 bits of some device register that is made up of lots of fields). FIELD_PREP() does support bitfields (for 'val'), they get an integer promotion applied. There seems to be exactly one instance of 'reg' being a bitfield, bloating all the other expansions for a trivially changeable line of code is just stupid. David > > David > > > > > I see no reasons to hack a random victim because of your rework. So > > NAK for this. > > > > In v3, please add an explicit test to make sure that bitfields are not > > broken with new implementation. > > > > Thanks, > > Yury >