From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 AC75329617D for ; Fri, 12 Dec 2025 20:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765569898; cv=none; b=O5UB+3xp7ZzXuo5fUpLXvZB7LmgN7VoeHmsHxwtRAc90iblS+Sn0SVaGNHC4df7CrdN909Rtfvq8Iq1ELlnVt5pCSJEKGfyBLoZ99AeF61uQm8Uw90sfom66WODy1NgZYRoYo7MxET/Gc6JiyacKO5VykJVAj69iKJff9wVj6FQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765569898; c=relaxed/simple; bh=v4FUhHFdi5ZXqVqGPGRtWuk27Ggt9EW1AEDL4D/CxK4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Gvz2m4KIpiPxk7smZMxF8orU/3k4jGCcUiUmvH1jNJ75tTvn3yXPzutaHylNiIYqIc5d6uiT5cpj9uVahIy7EDc7xqojzwkFErhxCAEyQaO55oZAZKsncLunr/WaEtE25PN/Tv2FMYAoOF4zL4aVc8lIl7aWN+GyzP1Wc+nHk4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=rcQrJ1Uq; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="rcQrJ1Uq" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xb-007TZN-7i; Fri, 12 Dec 2025 20:37:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=4XbSLZvBmYJ9LzNNMyiNSXY8ll6ZHX2gvyxQipHU0mg=; b=rcQrJ1 UqegrICDo4fAnkhXKRRqrV0O8Ls326sDv/JcKcAk6Al2todKLnhlDNHsWwE3AK6hL1vZSqmtNyNVE 1OroZmCdGG07T7I6ydVzd/0k9mznWFvrss5MbAQmlkY6gfYbY6wdrXKKJTBvudku0zcOZrcX7kXs6 MCA+d2s5ZzuEFiEIdof9pZd6Ezoxs68O7fatVUKHjvMLYTxCWcRixnBFSnf/aJwm0C9NJCGdMjTq5 udguTWojDliIij6K8xW7LDs1g/RP381FYb0iKSH4SOcYfKKVbtxo46b/ul2fQTf3YFHb7+4Uta+sI pOo4poy5yN6CaWpipJVUCkx0WELQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xZ-00039D-A3; Fri, 12 Dec 2025 20:37:49 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vU8xY-0030pR-Gm; Fri, 12 Dec 2025 20:37:48 +0100 From: david.laight.linux@gmail.com To: Yury Norov , 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 Cc: David Laight Subject: [PATCH v2 0/16] bitfield: tidy up bitfield.h Date: Fri, 12 Dec 2025 19:37:05 +0000 Message-Id: <20251212193721.740055-1-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight I noticed some very long (18KB) error messages from the compiler. Turned out they were errors on lines that passed GENMASK() to FIELD_PREP(). Since most of the #defines are already statement functions the values can be copied to locals so the actual parameters only get expanded once. The 'bloat' is reduced further by using a simple test to ensure 'reg' is large enough, slightly simplifying the test for constant 'val' and only checking 'reg' and 'val' when the parameters are present. The first two patches are slightly problematic. drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c manages to use a #define that should be an internal to bitfield.h, the changed file is actually more similar to the previous version. drivers/thunderbolt/tb.h passes a bifield to FIELD_GET(), these can't be used with sizeof, typeof or __auto_type. The existing FIELD_GET() uses _Generic(); gcc treats 'u32 foo:8' as 'unsigned char' and clang treats 'u32 foo:n' as 'unsigned int'. So the code currentyly compiles 'by accident', pass 'u32 foo:6' and gcc will error the attempt to use typeof with a bitfield. For v2 fixed by changing the structure definition to use u8 for the relevant field. Both changes may need to to through the same tree as the header file changes. The changes are based on 'next' and contain the addition of field_prep() and field_get() for non-constant values. I also know it is the merge window. I expect to be generating a v3 in the new year (someone always has a comment). Changes for v2: - Change thunderbolt header (see above). - Fix variable name re-use in FIELD_PREP_WM16() - Use 'mask' (not _mask) in __BF_SHIFT(). The changes to bitfield.h have been split into multiple patches, but the actual final file only has whitespace differences. David Laight (16): nfp: Call FIELD_PREP() in NFP_ETH_SET_BIT_CONFIG() wrapper thunderbolt: Don't pass a bitfield to FIELD_GET bitmap: Use FIELD_PREP() in expansion of FIELD_PREP_WM16() bitfield: Copy #define parameters to locals bitfield: Merge __field_prep/get() into field_prep/get() bitfield: Remove some pointless casts bitfield: FIELD_MODIFY: Only do a single read/write on the target bitfield: Simplify __BF_FIELD_CHECK_REG() bitfield: Rename __FIELD_PREP/GET() to __BF_FIELD_PREP/GET() bitfield: Split the 'val' check out of __BF_FIELD_CHECK_MASK() bitfield: Common up validation of the mask parameter bitfield: Remove leading _ from #define formal parameter names bitfield: Reduce indentation bitfield: Add comment block for the host/fixed endian functions bitfield: Update comments for le/be functions build_bug.h; Remove __BUILD_BUG_ON_NOT_POWER_OF_2() .../netronome/nfp/nfpcore/nfp_nsp_eth.c | 16 +- drivers/thunderbolt/tb_regs.h | 16 +- include/linux/bitfield.h | 278 ++++++++++-------- include/linux/build_bug.h | 2 - include/linux/hw_bitfield.h | 21 +- 5 files changed, 175 insertions(+), 158 deletions(-) -- 2.39.5