From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 7D36B30E0DF; Fri, 12 Dec 2025 19:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568302; cv=none; b=JItok7ikyTD5rHStzqOsjNIbtvdKEDem7m00elxxhnBEGSacgoaXCIc89k7dhMUp1BpqZxNLqgJQfETt/XIe29YnhiyJx6qt8qeSfPcUhxdnwDt48svLl4cllaBs+Gh1AlI22nZdvI74lDdA1SOY28x3opJMyQV3uOxZFyQeCug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568302; c=relaxed/simple; bh=eSanA0nLIBnaxYkOxEDR3V3ZjDGcD9zNpqK4QeXpRW0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uP7W9K/V3iGs1w6BJeRMyZo4aD7YV1binykddWrRqU9glx47CP1P7HLgII8v+XVBj8gjg41Ls4FuKfTMvr6U0s7bbRy3rKupULhVO21yyAMebLq/Q4oom9icmrWIX8d9AZMX0/ER570SyuyBwp2qR0XV55t4WoX3Ukg2Vd38fPE= 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=GbCAZmdY; arc=none smtp.client-ip=185.226.149.37 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="GbCAZmdY" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xw-0087cj-9E; Fri, 12 Dec 2025 20:38:12 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=E/tgkX0LFHmCKon+QMYZwmLD5pzvPWhgIG9AyUVS/4A=; b=GbCAZmdYgLDD6BsKEv/7nB5GEj SCi0M5uT3FlqXbwhSGRdAsoIZBKDw+DNz4YP/Tuxphx8LFDUFyOLUVMxTu2wlxOgYzzSZVndai3Z2 tqGbsp45aznudJRQappgJddb+Wq47yHv0KZjbWnRhHzzJjH6O9jFNADB45lpo8ojMIu4jiZTyjIUS /57sbdSiOiyloDKXVoKJFp9zvI0B83/CSL1UDxkYo60A+uhtUWicciSeD+3lCLFPv2DCRoR1vlNcj TG5fF8kdwhwFl/+Asg0G4/XgPcihZIZCi28PCzl2Dp/c7GzqCbjf1e6oRGYkXq01hVq7d6BZ3UsPM qKHF3g7g==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xv-0003A9-SF; Fri, 12 Dec 2025 20:38:12 +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 1vU8xZ-0030pR-Ho; Fri, 12 Dec 2025 20:37:49 +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 01/16] nfp: Call FIELD_PREP() in NFP_ETH_SET_BIT_CONFIG() wrapper Date: Fri, 12 Dec 2025 19:37:06 +0000 Message-Id: <20251212193721.740055-2-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Rather than use a define that should be internal to the implementation of FIELD_PREP(), pass the shifted 'val' to nfp_eth_set_bit_config() and change the test for 'value unchanged' to match. This is a simpler change than the one used to avoid calling both FIELD_GET() and FIELD_PREP() with non-constant mask values. Signed-off-by: David Laight --- Unchanged for v2. .../ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c b/dri= vers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c index 5cfddc9a5d87..4a71ff47fbef 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c @@ -509,8 +509,7 @@ int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigne= d int idx, bool configed) =20 static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const u64 mask, const unsigned int shift, - u64 val, const u64 ctrl_bit) + const u64 mask, u64 shifted_val, const u64 ctrl_bit) { union eth_table_entry *entries =3D nfp_nsp_config_entries(nsp); unsigned int idx =3D nfp_nsp_config_idx(nsp); @@ -527,11 +526,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned = int raw_idx, =20 /* Check if we are already in requested state */ reg =3D le64_to_cpu(entries[idx].raw[raw_idx]); - if (val =3D=3D (reg & mask) >> shift) + if (shifted_val =3D=3D (reg & mask)) return 0; =20 reg &=3D ~mask; - reg |=3D (val << shift) & mask; + reg |=3D shifted_val; entries[idx].raw[raw_idx] =3D cpu_to_le64(reg); =20 entries[idx].control |=3D cpu_to_le64(ctrl_bit); @@ -571,12 +570,9 @@ int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned i= nt idx, bool state) return nfp_eth_config_commit_end(nsp); } =20 -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - ({ \ - __BF_FIELD_CHECK(mask, 0ULL, val, "NFP_ETH_SET_BIT_CONFIG: "); \ - nfp_eth_set_bit_config(nsp, raw_idx, mask, __bf_shf(mask), \ - val, ctrl_bit); \ - }) +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + nfp_eth_set_bit_config(nsp, raw_idx, mask, FIELD_PREP(mask, val), \ + ctrl_bit) =20 /** * __nfp_eth_set_aneg() - set PHY autonegotiation control bit --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 74C292F83DC; Fri, 12 Dec 2025 19:38:15 +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=1765568297; cv=none; b=FITsWjn/ElxfH4AXQWZ/L7gYqkV/LtiEM+/mD/sXJXoPnJnhJDxleE2ZEYsgyFRg7TcGGZEqUlkuqH7GnFkXlGFRs6ADMf5tVYQVmm2GWWKWpKxBmzs+YVksXWeKvCLzh3J1jUCTZBxr7yiAqcsNxCBQ1ybLLeriqEDhvzRRmKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568297; c=relaxed/simple; bh=zAilw6c1cTSLXleqFwparWwFnbwn1cLEm5G/XlL7Ptg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HLtAbEEjdu+cwRdUm4hVWBHZodzMK65wPzGBVKgF1r8ODTSLRlWhLpJNdlfMU9akWGvE9ruZGhm7LvL7dRa8t4JshdOCphGbNSi6qKORRjuTiRi8wvEgRIgGPVWvTJE3TUEKSqlI5eG9Hq+DOSkjPjN7qtc+me/arEprMR56LLo= 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=pagUMnJu; 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="pagUMnJu" Received: from mailtransmit02.runbox ([10.9.9.162] 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 1vU8xu-007Tao-Tr; Fri, 12 Dec 2025 20:38:10 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=gClv2ms3a8GLsRYy6HjqpYNYZFcf9BvN9jrm2mdq1WA=; b=pagUMnJuCRnozopuHaivaccyLT r2pGb7PaZDYxLpM6osM7m7vz8KS09ge9xR/l0xhNbNcZow/5z5y66+dlsJgz15f+r7pCjFKDxZWYq gI5jLfMAl7+AQk6/Mk7f6N7C4vX+vNA8/LWkMi0okplFi333u8tX8/KZ6NdNK+6EvYQ1ZKmG5CLf7 3hIvLwfScFl3TqOw5jGZ99gP8G0Y/eATz7rtY/9geL6+kFc9DV5EAn+C5Z8HqG/a2+f3FTWhigRjq /97QXdh7j4Fem4VgmPj7yWl5DWNc/YXK7jXffW7tftTH3K0CSuLvHlu/icnlzX8tPSnL68+QZK++0 HoiCd0/w==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xu-0006uh-Ig; Fri, 12 Dec 2025 20:38:10 +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 1vU8xa-0030pR-JL; Fri, 12 Dec 2025 20:37:50 +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 02/16] thunderbolt: Don't pass a bitfield to FIELD_GET Date: Fri, 12 Dec 2025 19:37:07 +0000 Message-Id: <20251212193721.740055-3-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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'. drivers/thunderbolt/tb_regs.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h index c0bf136236e6..f35f062beb34 100644 --- a/drivers/thunderbolt/tb_regs.h +++ b/drivers/thunderbolt/tb_regs.h @@ -180,14 +180,14 @@ struct tb_regs_switch_header { u32 route_hi:31; bool enabled:1; /* DWORD 4 */ - u32 plug_events_delay:8; /* - * RW, pause between plug events in - * milliseconds. Writing 0x00 is interpreted - * as 255ms. - */ - u32 cmuv:8; - u32 __unknown4:8; - u32 thunderbolt_version:8; + u8 plug_events_delay; /* + * RW, pause between plug events in + * milliseconds. Writing 0x00 is interpreted + * as 255ms. + */ + u8 cmuv; + u8 __unknown4; + u8 thunderbolt_version; } __packed; =20 /* Used with the router thunderbolt_version */ --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 2E6F930C63B for ; Fri, 12 Dec 2025 19:38:18 +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=1765568300; cv=none; b=nf0btJdtNZUjps7xiwQbI6tFjrcIwsRrUOquzYntB0SO6uAOBM19j+cvr8Nhrk0gxKqyLMZTcT86q3k9t6FRrdy2CRW8joIGsQD2S2BCB+99CuzM9IvCNjxNHqQFl2zyAJ3ZQL5qJ1KYafI9ySomZpaRRtslwhNke7SrCU0UdP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568300; c=relaxed/simple; bh=6xLPwuKCmyiv7sNodFTlJg7EJpoafX0uNY4awsxdL/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZVsdifPTShKKGV70INiNHhaw2Zo47AT9bFXOg7HngMti5nc+nYuwi0STNU1iyur2wYDan9kgDCuM+WQHBJ0YUdmyhCMY9TY6/HlGsjG3/i/waaUm2puUvOeRVCSz+QyW00wh06/VvPbQfjITpcJ5t6exPkvSUr8rninf1tUFY4E= 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=DpNsL337; 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="DpNsL337" 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 1vU8xz-007TcY-Ck; Fri, 12 Dec 2025 20:38:15 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=E7Grad49ePF15z6adZbwiVMT+Xs15fuNWU87DPOvLXg=; b=DpNsL337rQB0wyWs99J0dgkPR3 7jlIvmFa55BFvmBMGaRY9DdyilTfooTtMMnUgK9NjdAoKyXUpmLKTXe3FOkSl+WIR1ATELCWotoXJ O9sOUBxv8zYmXpIPzyPAxNsqrO75HJrV6z7izv5DBffDnJBHwxrHkX5WM9TkpCADJl//Ylyhhozhl DphIR9dNxvu68eaV+UIfLQGLku7DdZiixpiqflCoueSWJbno4r9X+67cZpsJ7akSR+pziNW1+ChNC IUniIw0Hf6P5uwbtP4R0Tn2K5HWUYInYfaM74gARjC7ryjUvix+BgXoKB/DLGWqg6Pd9FQSe5pzXy 8JRMdV3g==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xz-0003Ai-24; Fri, 12 Dec 2025 20:38:15 +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 1vU8xb-0030pR-Kt; Fri, 12 Dec 2025 20:37:51 +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 03/16] bitmap: Use FIELD_PREP() in expansion of FIELD_PREP_WM16() Date: Fri, 12 Dec 2025 19:37:08 +0000 Message-Id: <20251212193721.740055-4-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Instead of directly expanding __BF_FIELD_CHECK() (which really ought not be used outside bitfield) and open-coding the generation of the masked value, just call FIELD_PREP() and add an extra check for the mask being at most 16 bits. The extra check is added after calling FIELD_PREP() to get a sane error message if 'mask' isn't constant. Remove the leading _ from the formal parameter names. Prefix the local variables with _wm16_ to hopefully make them unique. Signed-off-by: David Laight --- Changes for v2: - Update kerneldoc to match changed formal parameter names. - Change local variables to not collide with those in FIELD_PREP(). Most of the examples are constants and get optimised away. include/linux/hw_bitfield.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/include/linux/hw_bitfield.h b/include/linux/hw_bitfield.h index df202e167ce4..0bd1040a5f93 100644 --- a/include/linux/hw_bitfield.h +++ b/include/linux/hw_bitfield.h @@ -12,8 +12,8 @@ =20 /** * FIELD_PREP_WM16() - prepare a bitfield element with a mask in the upper= half - * @_mask: shifted mask defining the field's length and position - * @_val: value to put in the field + * @mask: shifted mask defining the field's length and position + * @val: value to put in the field * * FIELD_PREP_WM16() masks and shifts up the value, as well as bitwise ORs= the * result with the mask shifted up by 16. @@ -23,15 +23,14 @@ * register, a bit in the lower half is only updated if the corresponding = bit * in the upper half is high. */ -#define FIELD_PREP_WM16(_mask, _val) \ - ({ \ - typeof(_val) __val =3D _val; \ - typeof(_mask) __mask =3D _mask; \ - __BF_FIELD_CHECK(__mask, ((u16)0U), __val, \ - "HWORD_UPDATE: "); \ - (((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) | \ - ((__mask) << 16); \ - }) +#define FIELD_PREP_WM16(mask, val) \ +({ \ + __auto_type _wm16_mask =3D mask; \ + u32 _wm16_val =3D FIELD_PREP(_wm16_mask, val); \ + BUILD_BUG_ON_MSG(_wm16_mask > 0xffffu, \ + "FIELD_PREP_WM16: mask too large"); \ + _wm16_val | (_wm16_mask << 16); \ +}) =20 /** * FIELD_PREP_WM16_CONST() - prepare a constant bitfield element with a ma= sk in --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 E819530BB83 for ; Fri, 12 Dec 2025 19:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568298; cv=none; b=C+7tJj0109ClG7vkAt3EJJ7NE6bwdxQSf6qrFC9ZZYATeEwI0Ju46dRui1ytM6ZKYJqbQlLdfKVFqyM0EgaQaY01aB55Jxs8jPzDPwQ/xa4OpQrphiH9P4zYgdjITSbUDPnBkXixxCdeFNmpO4aiStz4jmEwbE9vJO7DhVZmCj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568298; c=relaxed/simple; bh=sTX7hhMNXYX8IeOtAcpdooALbpE0W1i7Hg2nYaiqdfE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a6UGwrKDVKJucKm+xrhYEGtzbk8AjYfrWntYhbDVyDgtNRExWGrO1Ic+i15WhvegWPS+Mi67QCtpNGoEo+J8HqoKcbchFGzqT2c9r7Ut8/Pz9T+skC6RIgWGM9roocmbnBE0VDZD5nBGjVP/+bDLHkWpaI6piljvlI4DuYHnbXY= 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=hCMdKtXY; arc=none smtp.client-ip=185.226.149.37 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="hCMdKtXY" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xx-0087fa-Mo; Fri, 12 Dec 2025 20:38:13 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=FIpjYJfctt+TZ2YlO2ye1wdnb5GL7Nb/xCC/LOcVI7s=; b=hCMdKtXYW1Q79tiHOUteeVtWBN AS/aVRLklJFhSlCBTAmV8gMKXbz/14zqPqeMlTMqkDPFT9ZDnmX8elzlhxfxva/GDZgMiGx1gZMHT ghUVUuaS0w2Tx9S/UW1NLcP0Kjm5jJIfCJxorvs3tqA8sBL1jcRrvTYRR4UA9LtbDl4G96IoZ6XR4 kOJ8ViPg5hTrV3PTbfMhYt7o10WPJ15LOXmd1s3ma4opnFVkCW0bJMJGuxPgEX8Ff0EEET1mB5hfg 3dhau67k1okv0H/KsDuM8X/tI7mwR5WPIwj1ADW4xU4wKudDTN/TDEZx5VxDCB6H8kIW6NPiLXfu1 wfqeiKBg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xx-0003AQ-Aq; Fri, 12 Dec 2025 20:38:13 +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 1vU8xc-0030pR-Nf; Fri, 12 Dec 2025 20:37:52 +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 04/16] bitfield: Copy #define parameters to locals Date: Fri, 12 Dec 2025 19:37:09 +0000 Message-Id: <20251212193721.740055-5-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Use __auto_type to take copies of parameters to both ensure they are evaluated only once and to avoid bloating the pre-processor output. In particular 'mask' is likely to be GENMASK() and the expension of FIELD_GET() is then about 18KB. The 'val' parameter is sometimes a bitfield (so _auto_type cannot be used), the type of _val also needs to be large enough to hold the shifted value, using '__auto_type _val =3D 1 ? (val) : _mask;' solves both problems. Update kerneldoc to match the renamed (no leading _) formal parameters. Signed-off-by: David Laight --- include/linux/bitfield.h | 52 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 126dc5b380af..3800744281c7 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -99,40 +99,45 @@ =20 /** * FIELD_MAX() - produce the maximum value representable by a field - * @_mask: shifted mask defining the field's length and position + * @mask: shifted mask defining the field's length and position * * FIELD_MAX() returns the maximum value that can be held in the field - * specified by @_mask. + * specified by @mask. */ -#define FIELD_MAX(_mask) \ +#define FIELD_MAX(mask) \ ({ \ + __auto_type _mask =3D mask; \ __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ }) =20 /** * FIELD_FIT() - check if value fits in the field - * @_mask: shifted mask defining the field's length and position - * @_val: value to test against the field + * @mask: shifted mask defining the field's length and position + * @val: value to test against the field * - * Return: true if @_val can fit inside @_mask, false if @_val is too big. + * Return: true if @val can fit inside @mask, false if @val is too big. */ -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(mask, val) \ ({ \ + __auto_type _mask =3D mask; \ + __auto_type _val =3D 1 ? (val) : _mask; \ __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ }) =20 /** * FIELD_PREP() - prepare a bitfield element - * @_mask: shifted mask defining the field's length and position - * @_val: value to put in the field + * @mask: shifted mask defining the field's length and position + * @val: value to put in the field * * FIELD_PREP() masks and shifts up the value. The result should * be combined with other fields of the bitfield using logical OR. */ -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(mask, val) \ ({ \ + __auto_type _mask =3D mask; \ + __auto_type _val =3D 1 ? (val) : _mask; \ __BF_FIELD_CHECK_REG(_mask, 0ULL, "FIELD_PREP: "); \ __FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ }) @@ -165,29 +170,34 @@ =20 /** * FIELD_GET() - extract a bitfield element - * @_mask: shifted mask defining the field's length and position - * @_reg: value of entire bitfield + * @mask: shifted mask defining the field's length and position + * @reg: value of entire bitfield * - * FIELD_GET() extracts the field specified by @_mask from the - * bitfield passed in as @_reg by masking and shifting it down. + * FIELD_GET() extracts the field specified by @mask from the + * bitfield passed in as @reg by masking and shifting it down. */ -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(mask, reg) \ ({ \ + __auto_type _mask =3D mask; \ + __auto_type _reg =3D reg; \ __BF_FIELD_CHECK_REG(_mask, _reg, "FIELD_GET: "); \ __FIELD_GET(_mask, _reg, "FIELD_GET: "); \ }) =20 /** * FIELD_MODIFY() - modify a bitfield element - * @_mask: shifted mask defining the field's length and position - * @_reg_p: pointer to the memory that should be updated - * @_val: value to store in the bitfield + * @mask: shifted mask defining the field's length and position + * @reg_p: pointer to the memory that should be updated + * @val: value to store in the bitfield * - * FIELD_MODIFY() modifies the set of bits in @_reg_p specified by @_mask, - * by replacing them with the bitfield value passed in as @_val. + * FIELD_MODIFY() modifies the set of bits in @reg_p specified by @mask, + * by replacing them with the bitfield value passed in as @val. */ -#define FIELD_MODIFY(_mask, _reg_p, _val) \ +#define FIELD_MODIFY(mask, reg_p, val) \ ({ \ + __auto_type _mask =3D mask; \ + __auto_type _reg_p =3D reg_p; \ + __auto_type _val =3D 1 ? (val) : _mask; \ typecheck_pointer(_reg_p); \ __BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: "); \ *(_reg_p) &=3D ~(_mask); \ --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 5D64730BBB7; Fri, 12 Dec 2025 19:38:16 +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=1765568300; cv=none; b=Eoz2TXgav1zNSF5QMTqSOy123vOT5GeKX4BPm7XA7TshfZHOJTLvCD6Fod7thUhU3C9RIvgkFYL2Wk9CF2jCQ2pnsTzkZWxtb3fwCBrZbOi2S6ncr1SiPoukbH6V51GBmdpJ5HG9aMj05aZRwvU+VM5avVTn7kPjrRKw5/5j78k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568300; c=relaxed/simple; bh=mdnK2kiWxTdEx/+91SA8fwSY8LOjWRmnEoBNvu4GgTo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IDxw4t2zdHPIsl6OyblldzBwwchwuJJU4uDZmIFkKKGWVP1B+9BitGtuvmpalepayZ8/aOtcMYwMPD0hBOlrj0noOXcamfZINzeLgVC7BVyQrbaHCHFPUJGL3H4zhvdpvLkpH/kKXr0lGZMprbPKGqh7nyktpIuJ7X9rZbUwIiY= 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=QplppzQp; 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="QplppzQp" 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 1vU8xy-007TcA-2F; Fri, 12 Dec 2025 20:38:14 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=EpuO6aktcY35Crl1/oH5q0fVnrQzqVc0Xwk2TPe0MdA=; b=QplppzQpA8/Dxc7Uq6VAJ/ILsl 3yaEZTvZmj+KOmEU79gZ1jjhPdXH7ySjnjbkltgHhR/LVwislitHw3/29Wap7FSEU/FaoTwfdrtbD SUh484Q1LnHqXXAz3i/IYKf4ccA7j8yJEaNYkfmRWGBYcSe72xarh/TRjiOGUIG09rYqNmXUNnqrl 7B2XIgWDVD/jZ53Zjwjw6TWhkkdUrcIjKmMv77t9IYoj4ojVDEXr//wySm2gvKkqsHq0y+b4br8CB f8cJB2Ljl5ctXZhCyp/UM0mhUGbRl5ElZ+YyKwXAReEg77cXtGMCIeNaU79f6VTLMOotWhWCFPtls Bojl+3/w==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xx-0003AW-Oq; Fri, 12 Dec 2025 20:38:13 +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 1vU8xd-0030pR-Pb; Fri, 12 Dec 2025 20:37:53 +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 05/16] bitfield: Merge __field_prep/get() into field_prep/get() Date: Fri, 12 Dec 2025 19:37:10 +0000 Message-Id: <20251212193721.740055-6-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight field_prep() calls __FIELD_PREP() which really wants the parameters copied to 'locals' - but this is done later in __field_prep(). Move the 'auto_type' lines to the outer function. This only leaves the shift calculation and final expression inside __field_prep(), move the shift calculation to a new define __BF_SHIFT() and just inline the final expression into field_prep(). Use a common #define for the shift expression. Do the same for field_get(). Signed-off-by: David Laight --- include/linux/bitfield.h | 42 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 3800744281c7..c30120535680 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -251,23 +251,9 @@ __MAKE_OP(64) #undef __MAKE_OP #undef ____MAKE_OP =20 -#define __field_prep(mask, val) \ - ({ \ - __auto_type __mask =3D (mask); \ - typeof(__mask) __val =3D (val); \ - unsigned int __shift =3D BITS_PER_TYPE(__mask) <=3D 32 ? \ - __ffs(__mask) : __ffs64(__mask); \ - (__val << __shift) & __mask; \ - }) - -#define __field_get(mask, reg) \ - ({ \ - __auto_type __mask =3D (mask); \ - typeof(__mask) __reg =3D (reg); \ - unsigned int __shift =3D BITS_PER_TYPE(__mask) <=3D 32 ? \ - __ffs(__mask) : __ffs64(__mask); \ - (__reg & __mask) >> __shift; \ - }) +/* As __bf_shf() but for non-zero variables */ +#define __BF_SHIFT(mask) \ + (BITS_PER_TYPE(mask) <=3D 32 ? __ffs(mask) : __ffs64(mask)) =20 /** * field_prep() - prepare a bitfield element @@ -285,9 +271,14 @@ __MAKE_OP(64) * If you want to ensure that @mask is a compile-time constant, please use * FIELD_PREP() directly instead. */ -#define field_prep(mask, val) \ - (__builtin_constant_p(mask) ? __FIELD_PREP(mask, val, "field_prep: ") \ - : __field_prep(mask, val)) +#define field_prep(mask, val) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _val =3D 1 ? (val) : _mask; \ + __builtin_constant_p(_mask) ? \ + __FIELD_PREP(_mask, _val, "field_prep: ") : \ + (_val << __BF_SHIFT(_mask)) & _mask; \ +}) =20 /** * field_get() - extract a bitfield element @@ -305,8 +296,13 @@ __MAKE_OP(64) * If you want to ensure that @mask is a compile-time constant, please use * FIELD_GET() directly instead. */ -#define field_get(mask, reg) \ - (__builtin_constant_p(mask) ? __FIELD_GET(mask, reg, "field_get: ") \ - : __field_get(mask, reg)) +#define field_get(mask, reg) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _reg =3D reg; \ + __builtin_constant_p(_mask) ? \ + __FIELD_GET(_mask, _reg, "field_get: ") : \ + (_reg & _mask) >> __BF_SHIFT(_mask); \ +}) =20 #endif --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 68CE428151C; Fri, 12 Dec 2025 19:38:12 +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=1765568295; cv=none; b=tJ+1oWZE+iRvN1t3qrs0eS291GSOSfkPGaLbtO/+i/UV9KQJW7Ij5yz1WudHeOVh+Wh1Chu3q4d8leuhTzXMqIuVXci7AQFI4djIqyD6sSnVOB3QVCisBuTho78BBlxGzoxKhiaIP0DZ9ZSlbO+fQtHp7jBqlPi9PLR4VPVxD9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568295; c=relaxed/simple; bh=4DhYdBQ8yGIeD+NXQinvRz/pDWYNEBhrFO/YnPCkfe4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UY+B4tSuXic55ZqNg148JwW3WzONNRaiKVjt1uAQDnaNWHXwLPaiQv7wR9ckUt5lRmInh9lSnlYPRixXMcx5gOJyt6OOy9FARelp0q3vQXqeggwl/6+4d6LWhyudC5xS4bPE0SG87LpBq5aFgmLRdZxo+2+jB3G7Jg5dObWPPTg= 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=hDKaCwM2; 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="hDKaCwM2" 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 1vU8xu-007Tac-26; Fri, 12 Dec 2025 20:38:10 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=LTG3TP4CYSEEXpFm2SzMNXKADoomq1D1zd91C1jNRlI=; b=hDKaCwM2e1S9f6NaM6UQaKwZ3W P4K4x6XuLm2PNvX0Iu9yIGFzxhLxYBSpnI556EyO1izvFbhpG96TiApCwb7zeBhEeFB5W+8KTLeM8 toNuMg89W8hT2OoIqw5aOkvpCetLUYMGiHNTAWiTsSF7dqtR3t9qW38LKzHVMmxnqS86trxsflEIg qbRg5ZDVBlVAmQnltM1U88gzERaK6MF3XQxU1AZGb1gFaAFn+1hWDaSG7bTpwtqBb+hRDAM/PhWME j++vmTVx8StMjK1pJosHas9aHh0GMsU/Miiht7Nsx/7ltdHpWlxMD3jutcLg/8GMM56cJTi54qGpl iOEbZ/ow==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xt-00039r-Lp; Fri, 12 Dec 2025 20:38:09 +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 1vU8xe-0030pR-RE; Fri, 12 Dec 2025 20:37:54 +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 06/16] bitfield: Remove some pointless casts Date: Fri, 12 Dec 2025 19:37:11 +0000 Message-Id: <20251212193721.740055-7-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Now that _val is always large enough to hold _mask there is no need to cast it before the shift left. This also corrects the incorrect parenthesis in FIELD_FIT(), unlikely to be a real problem. For FIELD_GET() and FIELD_MAX() there is no point casting the result of the shift to the type of mask. Even if mask were char/short the value will immediately be promoted to 'signed int' as soon as it is used. All that is likely to happen is an extra and with 0xff. Remove the associated extra (...) around __auto_type variable. Signed-off-by: David Laight --- include/linux/bitfield.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index c30120535680..f1859e28df5d 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -88,13 +88,13 @@ #define __FIELD_PREP(mask, val, pfx) \ ({ \ __BF_FIELD_CHECK_MASK(mask, val, pfx); \ - ((typeof(mask))(val) << __bf_shf(mask)) & (mask); \ + ((val) << __bf_shf(mask)) & (mask); \ }) =20 #define __FIELD_GET(mask, reg, pfx) \ ({ \ __BF_FIELD_CHECK_MASK(mask, 0U, pfx); \ - (typeof(mask))(((reg) & (mask)) >> __bf_shf(mask)); \ + ((reg) & (mask)) >> __bf_shf(mask); \ }) =20 /** @@ -108,7 +108,7 @@ ({ \ __auto_type _mask =3D mask; \ __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ - (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ + (_mask >> __bf_shf(_mask)); \ }) =20 /** @@ -123,7 +123,7 @@ __auto_type _mask =3D mask; \ __auto_type _val =3D 1 ? (val) : _mask; \ __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ - !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ + !((_val << __bf_shf(_mask)) & ~_mask); \ }) =20 /** @@ -201,7 +201,7 @@ typecheck_pointer(_reg_p); \ __BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: "); \ *(_reg_p) &=3D ~(_mask); \ - *(_reg_p) |=3D (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)); \ + *(_reg_p) |=3D (_val << __bf_shf(_mask)) & _mask; \ }) =20 extern void __compiletime_error("value doesn't fit into mask") --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 9CDA93126D8; Fri, 12 Dec 2025 19:38:21 +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=1765568304; cv=none; b=ht0RzKRmzOJF5RhBdafrz30JzkJrgx/TuP6xjxz9Lfr5TjW8zd5wdpIZTMdEH6sQtJrxF85Mcftnxr0EAaZt3xjRgZRdy02ieJjpWsMhCH31yIdc8A7kw62YIZ6xEb+UWqsROH2XZkOr7IzaUGZzqxc+2JXZ7eZX3Bu+fumyREU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568304; c=relaxed/simple; bh=qGRxQF8GFDnNcaSRGguN86dTeYa8fKIIpe8exdR+8yE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s8tSaU9sYziGc2JBBH994lRhUnq2D+0doTF+jg5cRUXxQzmCiKOQNcrPvOEe0cpfao3iSl9Nl4/4PiyGLT4sTjz79BfVVSGy+ebtGOnP4ZvsMUjxGGlvhSMVoH5kEYu8lV2kmq0CczK4WiGrSqpB95Echs4243QFgqbsqUpsrvE= 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=rcVDa5YA; 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="rcVDa5YA" Received: from mailtransmit02.runbox ([10.9.9.162] 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 1vU8xy-007TcT-UY; Fri, 12 Dec 2025 20:38:14 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=Gz2PF6SRur9iX1hthbk/yf6ubztCbT5FrnIggMPjKuA=; b=rcVDa5YAtioXHHVFgViVLZVf/H UsgytYd98oJzotmL6Uz1rLYrBDtNcBajZ6A0uKmzGLd6NpSRstQJ+R62nDgaQvkGegAka3G3QCC11 X0oMvTj3XNCvh7LHxM9gCaw4VG6znltNOkSCEL8Osrl/CSMSLXep+vIyNMu5wTYD611YLaBQqE9Y5 SKFTjQMeCLSCd39S9LIx/MxqJuXOCJl0/hHzQ/NZFGosKhJN7blvUmwhCw5VoZM89WTrngWC5uMSE Txbo9nWxITLP9PrisAfEmcWMW8D8kbeXnTHh4zcjEJJ+2FNShrHaW3HuPInJ0hJYPO0Z7iYdkHslp hLdlVHPA==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xy-0006uz-KF; Fri, 12 Dec 2025 20:38:14 +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 1vU8xf-0030pR-Ru; Fri, 12 Dec 2025 20:37:55 +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 07/16] bitfield: FIELD_MODIFY: Only do a single read/write on the target Date: Fri, 12 Dec 2025 19:37:12 +0000 Message-Id: <20251212193721.740055-8-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Replace the: *reg &=3D ~mask; *reg |=3D new_value; with a single assignment. While the compiler will usually optimise the extra access away it isn't guaranteed. Signed-off-by: David Laight --- include/linux/bitfield.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index f1859e28df5d..c354ca2ef1a0 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -200,8 +200,7 @@ __auto_type _val =3D 1 ? (val) : _mask; \ typecheck_pointer(_reg_p); \ __BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: "); \ - *(_reg_p) &=3D ~(_mask); \ - *(_reg_p) |=3D (_val << __bf_shf(_mask)) & _mask; \ + *_reg_p =3D (*_reg_p & ~_mask) | ((_val << __bf_shf(_mask)) & _mask); \ }) =20 extern void __compiletime_error("value doesn't fit into mask") --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 DBD8530B53F; Fri, 12 Dec 2025 19:38:15 +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=1765568297; cv=none; b=ti7KhAwOqMWksPHcuy0KOzV10U656tN6BYDRUnc1ONbr5LM/7ZH1Z9c9EboxPcwsTvElsqGhfa3+/OE60Nip/jek3TCVfXcaOKVfWg3ZXwQrfXuGnvf+9SaW3LBHjObz7+2+6LzUQescwQVt++fJFpWnaLdYKlUEDvvI2vRLjZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568297; c=relaxed/simple; bh=3MgYeGV5f97OocFYM35DoH9AT3refnY61WAO4MPnPfk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nWv6tMrXzLd2nyIlTO96CoFtm8PQAuDiJ0uKN7xeQel6FVWaAXh5T70O9ywuS01Osuy7UcCNgAtZ/igqhImNZUpdw7Y5o2z8WeCWrxHz7djLAHq5HevrTHUvFAwRu6YLCM9s0JHyuCylh4qhgbkE0DcnJmvix9zJr71Obb5yJgE= 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=EPcmFEeZ; 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="EPcmFEeZ" 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 1vU8xv-007Tb4-O6; Fri, 12 Dec 2025 20:38:11 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=16a1w0ZjBufiGEzex6si94JfgFJX4Q/C1ixMUo2n3VE=; b=EPcmFEeZdJ091CaHHWYsMa3rTi CJcIBlGZo88idPArXWZT/oJ5ytgGwaQgus8fKqyzTmmXQYCzwXNfA5RcPMUBnlLx/0RTQAtqNhLY/ dlcxMHeVwoTkRKDxj32yHtB6fmmg16PQVgsrhgbSwYgeNFCk2FKrqy031lAt50TqEIm06cvMiA5Pd 6WHARMCcyjonLUlhgBVzZGzwBQRyMOW7qYi/mF2GdIIT4rIOPIxnzwinXVTud/zC7H8d5cokKbNT3 sqt5+p7qr57TRZB3858RYCUjMIxAo/bnkfhROtKMXUqqnSTLuNZI5yzBKwlEiBQIwNYV3WTO0eSTH 8QX588OA==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xv-0003A3-EZ; Fri, 12 Dec 2025 20:38:11 +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 1vU8xg-0030pR-TF; Fri, 12 Dec 2025 20:37:57 +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 08/16] bitfield: Simplify __BF_FIELD_CHECK_REG() Date: Fri, 12 Dec 2025 19:37:13 +0000 Message-Id: <20251212193721.740055-9-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Simplify the check for 'reg' being large enough to hold 'mask' using sizeof (reg) rather than a convoluted scheme to generate an unsigned type the same size as 'reg'. Signed-off-by: David Laight --- include/linux/bitfield.h | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index c354ca2ef1a0..7160b762c979 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -45,22 +45,6 @@ =20 #define __bf_shf(x) (__builtin_ffsll(x) - 1) =20 -#define __scalar_type_to_unsigned_cases(type) \ - unsigned type: (unsigned type)0, \ - signed type: (unsigned type)0 - -#define __unsigned_scalar_typeof(x) typeof( \ - _Generic((x), \ - char: (unsigned char)0, \ - __scalar_type_to_unsigned_cases(char), \ - __scalar_type_to_unsigned_cases(short), \ - __scalar_type_to_unsigned_cases(int), \ - __scalar_type_to_unsigned_cases(long), \ - __scalar_type_to_unsigned_cases(long long), \ - default: (x))) - -#define __bf_cast_unsigned(type, x) ((__unsigned_scalar_typeof(type))(x)) - #define __BF_FIELD_CHECK_MASK(_mask, _val, _pfx) \ ({ \ BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ @@ -75,8 +59,8 @@ }) =20 #define __BF_FIELD_CHECK_REG(mask, reg, pfx) \ - BUILD_BUG_ON_MSG(__bf_cast_unsigned(mask, mask) > \ - __bf_cast_unsigned(reg, ~0ull), \ + BUILD_BUG_ON_MSG((mask) + 0U + 0UL + 0ULL > \ + ~0ULL >> (64 - 8 * sizeof (reg)), \ pfx "type of reg too small for mask") =20 #define __BF_FIELD_CHECK(mask, reg, val, pfx) \ --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 D8E642459FD; Fri, 12 Dec 2025 19:38:14 +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=1765568296; cv=none; b=EuenBDvG3nxQnbI22l6dUnEGAhXhesE9l95T6brCT/5ZcWe4uWC+KH4V2d1Gk1SX7zZuIx0bxDi+pprdfaidnsX7Vifd+X+a6GF7Ns/oV8ZVQAYLXvjRBug28XoZ+5ykm+74DBMj6cApcGU0YNLui07YsRj1Ss20/EnE/ig9PvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568296; c=relaxed/simple; bh=oKG5kkA4svUiPNmHEZ04vDi9a5SjU596V5IWn8CvoxI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ChNwWz9dgYDmo2I5zCe3un2sdhoQpvwZIuMN5jho0NmNl08fFHqqFnQSdNNB2Rd+P19AA+0gSEwSNJ7fGT7zLL1uhHms4zYe3K+byXQu4zLt06fxx0iClAz7AobmYGd/8Dd5UoyptphkJADsUE+BuL2Dvf4hER3yFFcZGtzj3B4= 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=ZoPdvWPv; 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="ZoPdvWPv" Received: from mailtransmit02.runbox ([10.9.9.162] 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 1vU8xt-007TaV-5S; Fri, 12 Dec 2025 20:38:09 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=bBARxlsMunaL3yEx7etxlOGIwGGWqNaium90kicufJs=; b=ZoPdvWPv489Cyxqx0Ipj61gmb5 Xdqiq5q/Gjn3jYudEJUzUnzm0kjBG66DpVUIcP/SGgEzb3JwhuD0SloYDm3h4/09FIA2cev24xlSL 5tgwTR8TeJkbKU8vKHYMvQYz0Im62AXVCyb44JA03nToi9v6JdTL4rmUiRqVkO5jihn9dL3qGL8gk H0u3NK0N4+6ju/XYakmWkiCy5+LUT1qBxoj/PUxm3KsASES/8Htuk2pzYvD/luLosJth9eQwEGgJ8 gkynwuoM+ZOeG48voTOulmbESKACYndFa2TPlK5oWvCYYFa9FITg7iJ4xOVDvHjKLTy3DxntuLOtE zHDPk8mg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xs-0006uY-Mv; Fri, 12 Dec 2025 20:38:08 +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 1vU8xh-0030pR-Uh; Fri, 12 Dec 2025 20:37:58 +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 09/16] bitfield: Rename __FIELD_PREP/GET() to __BF_FIELD_PREP/GET() Date: Fri, 12 Dec 2025 19:37:14 +0000 Message-Id: <20251212193721.740055-10-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight This makes the names consistent with the other internal defines that shouldn't be used outside tis file. Signed-off-by: David Laight --- include/linux/bitfield.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 7160b762c979..ed5735c13a64 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -69,13 +69,13 @@ __BF_FIELD_CHECK_REG(mask, reg, pfx); \ }) =20 -#define __FIELD_PREP(mask, val, pfx) \ +#define __BF_FIELD_PREP(mask, val, pfx) \ ({ \ __BF_FIELD_CHECK_MASK(mask, val, pfx); \ ((val) << __bf_shf(mask)) & (mask); \ }) =20 -#define __FIELD_GET(mask, reg, pfx) \ +#define __BF_FIELD_GET(mask, reg, pfx) \ ({ \ __BF_FIELD_CHECK_MASK(mask, 0U, pfx); \ ((reg) & (mask)) >> __bf_shf(mask); \ @@ -123,7 +123,7 @@ __auto_type _mask =3D mask; \ __auto_type _val =3D 1 ? (val) : _mask; \ __BF_FIELD_CHECK_REG(_mask, 0ULL, "FIELD_PREP: "); \ - __FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ + __BF_FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ }) =20 #define __BF_CHECK_POW2(n) BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) !=3D 0) @@ -165,7 +165,7 @@ __auto_type _mask =3D mask; \ __auto_type _reg =3D reg; \ __BF_FIELD_CHECK_REG(_mask, _reg, "FIELD_GET: "); \ - __FIELD_GET(_mask, _reg, "FIELD_GET: "); \ + __BF_FIELD_GET(_mask, _reg, "FIELD_GET: "); \ }) =20 /** @@ -259,7 +259,7 @@ __MAKE_OP(64) __auto_type _mask =3D mask; \ __auto_type _val =3D 1 ? (val) : _mask; \ __builtin_constant_p(_mask) ? \ - __FIELD_PREP(_mask, _val, "field_prep: ") : \ + __BF_FIELD_PREP(_mask, _val, "field_prep: ") : \ (_val << __BF_SHIFT(_mask)) & _mask; \ }) =20 @@ -284,7 +284,7 @@ __MAKE_OP(64) __auto_type _mask =3D mask; \ __auto_type _reg =3D reg; \ __builtin_constant_p(_mask) ? \ - __FIELD_GET(_mask, _reg, "field_get: ") : \ + __BF_FIELD_GET(_mask, _reg, "field_get: ") : \ (_reg & _mask) >> __BF_SHIFT(_mask); \ }) =20 --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 13F7D2DC33D; Fri, 12 Dec 2025 19:38:10 +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=1765568295; cv=none; b=uaBtFOyAu5nHSp0wSrMkjNK5cy3ALvtj/RTpMkxFjbMFcmD/JquIDB3GrT8p9ij2HjAYecJq+OiNQxcutUSTnXh/71J+MDghfZLtOESWmCSlowqQx5JAOWPmxdlElhAECFmDne0GGwhuTY6vVBgqKB0vz4z8g0TyHKJWYpCCTsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568295; c=relaxed/simple; bh=28J+8dq1JwHHdPRLjgx9Ss18YMj9ZMQlOdRW9yK1NrU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kho8ezIlpEjde+9XWHM0YwymOvUI5FBP4f6V7POPyj2EyTbJ8whQ7ffy8VPrQTSpzs+vkqPbTLWyu1Eh1cI2p/T3YaxJA8dJU2uWuFbf3GaqMHIjxkrLGDfCC8iDPxIu7zvc5ocfr9WylZe659sa7059QQrK4YYgU0nltE00Dmc= 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=ecTP+qUr; 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="ecTP+qUr" 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 1vU8xs-007TaO-JL; Fri, 12 Dec 2025 20:38:08 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=6U3T9tjd/hVxKlBQ0Q6ToH9Df4rvaTpY6G/EvE5x9HY=; b=ecTP+qUrIFB7nUlZrQifCzIq+n UKiolkrWT5d3gGeSpYi/PeVGFMp0uTGd3Bmmt5ic+m6Pyutg3SOfNJJFWZkwD2T/oTasjzwVEpf/B v7Onb8w/CEmif23SAVNc/T5so81RbyAM58ORTSFcIJIK7QQACPH2BVzT3mplgqxMng3gDpcgHEzyQ 5O2njuu5uNBsjmZGteluX0uhTMdgXKqA8C64uC57gsm1ux771BkGZ/uC0QeyM/Gk932w+fA1zbyyc cHab4Xb959FgaleyYwDNUo1vuCfACcBsHXLiedmguLJiAG8/6XUl6g7ps59u+Sk+oo3cHjha+Huib bUPbL6xQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xs-00039g-8N; Fri, 12 Dec 2025 20:38:08 +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 1vU8xj-0030pR-0B; Fri, 12 Dec 2025 20:37:59 +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 10/16] bitfield: Split the 'val' check out of __BF_FIELD_CHECK_MASK() Date: Fri, 12 Dec 2025 19:37:15 +0000 Message-Id: <20251212193721.740055-11-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Three of the five calls to __BF_FIELD_CHECK_MASK() don't have a 'value' to check, separate out as was done to __BF_FIELD_CHECK_REG(). Since __BF_FIELD_CHECK_MASK() doesn't return a value, use do { ... } while (0) rather than ({ ... }). There is no point checking a 'val' of zero or a 'reg' of 0ULL (both are placeholders) - remove/change the calls. There should be a check of __BF_FIELD_CHECK_REG() when __BF_FIELD_GET() is called from field_get(). Move the check from FIELD_GET() into __BF_FIELD_GET(). Delete the now-unused __BF_FIELD_CHECK(). Signed-off-by: David Laight --- include/linux/bitfield.h | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index ed5735c13a64..138f4c14786d 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -45,39 +45,36 @@ =20 #define __bf_shf(x) (__builtin_ffsll(x) - 1) =20 -#define __BF_FIELD_CHECK_MASK(_mask, _val, _pfx) \ - ({ \ +#define __BF_FIELD_CHECK_MASK(_mask, _pfx) \ + do { \ BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ _pfx "mask is not constant"); \ BUILD_BUG_ON_MSG((_mask) =3D=3D 0, _pfx "mask is zero"); \ - BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ - ~((_mask) >> __bf_shf(_mask)) & \ - (0 + (_val)) : 0, \ - _pfx "value too large for the field"); \ __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ (1ULL << __bf_shf(_mask))); \ - }) + } while (0) + +#define __BF_FIELD_CHECK_VAL(mask, val, pfx) \ + BUILD_BUG_ON_MSG(__builtin_constant_p(val) && \ + ~((mask) >> __bf_shf(mask)) & (val), \ + pfx "value too large for the field") =20 #define __BF_FIELD_CHECK_REG(mask, reg, pfx) \ BUILD_BUG_ON_MSG((mask) + 0U + 0UL + 0ULL > \ ~0ULL >> (64 - 8 * sizeof (reg)), \ pfx "type of reg too small for mask") =20 -#define __BF_FIELD_CHECK(mask, reg, val, pfx) \ - ({ \ - __BF_FIELD_CHECK_MASK(mask, val, pfx); \ - __BF_FIELD_CHECK_REG(mask, reg, pfx); \ - }) - #define __BF_FIELD_PREP(mask, val, pfx) \ ({ \ - __BF_FIELD_CHECK_MASK(mask, val, pfx); \ + __BF_FIELD_CHECK_MASK(mask, pfx); \ + __BF_FIELD_CHECK_VAL(mask, val, pfx); \ ((val) << __bf_shf(mask)) & (mask); \ }) =20 #define __BF_FIELD_GET(mask, reg, pfx) \ ({ \ - __BF_FIELD_CHECK_MASK(mask, 0U, pfx); \ + __BF_FIELD_CHECK_MASK(mask, pfx); \ + __BF_FIELD_CHECK_REG(mask, reg, pfx); \ ((reg) & (mask)) >> __bf_shf(mask); \ }) =20 @@ -91,7 +88,7 @@ #define FIELD_MAX(mask) \ ({ \ __auto_type _mask =3D mask; \ - __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_MAX: "); \ (_mask >> __bf_shf(_mask)); \ }) =20 @@ -106,7 +103,7 @@ ({ \ __auto_type _mask =3D mask; \ __auto_type _val =3D 1 ? (val) : _mask; \ - __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_FIT: "); \ !((_val << __bf_shf(_mask)) & ~_mask); \ }) =20 @@ -122,7 +119,6 @@ ({ \ __auto_type _mask =3D mask; \ __auto_type _val =3D 1 ? (val) : _mask; \ - __BF_FIELD_CHECK_REG(_mask, 0ULL, "FIELD_PREP: "); \ __BF_FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ }) =20 @@ -164,7 +160,6 @@ ({ \ __auto_type _mask =3D mask; \ __auto_type _reg =3D reg; \ - __BF_FIELD_CHECK_REG(_mask, _reg, "FIELD_GET: "); \ __BF_FIELD_GET(_mask, _reg, "FIELD_GET: "); \ }) =20 @@ -182,8 +177,9 @@ __auto_type _mask =3D mask; \ __auto_type _reg_p =3D reg_p; \ __auto_type _val =3D 1 ? (val) : _mask; \ - typecheck_pointer(_reg_p); \ - __BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: "); \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_MODIFY: "); \ + __BF_FIELD_CHECK_VAL(_mask, _val, "FIELD_MODIFY: "); \ + __BF_FIELD_CHECK_REG(_mask, *_reg_p, "FIELD_MODIFY: "); \ *_reg_p =3D (*_reg_p & ~_mask) | ((_val << __bf_shf(_mask)) & _mask); \ }) =20 --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 B732E30FF3A for ; Fri, 12 Dec 2025 20:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765570528; cv=none; b=i12knvR6OCXr9AkKiA/VvzmMMTEe3K4jR14G/tMPfbQQTFXzI+y7kNvz73GwFSiGEXkGMefbpjHzCZQv9YxO1d0sAz0bPs1KjQiUGFi6hecmd8SRTfkdC3vXoGWn+3806SVqeMYVuKktTVi/mr/ogmKNaWCnn3WfaacpYlZOApk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765570528; c=relaxed/simple; bh=Ccr1EarAMFaJl6TVejUdtnp6jxA9i93IxK5KG/WKPVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s9UUKwPuEEZdNty4AqWr763QSvWoStBkUSv4xpUR0ODKhHeC61Fhknh7C0QoNzmfULwAUNY7jB53INC21Iip1xzJTDtgilo34pqB2SeMebsSCqnehdotFabahj6gQIksG8p8F/rJDhUnu6cell67QuBpGuwN7x4oX6liup+diVA= 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=qzp4HEFr; arc=none smtp.client-ip=185.226.149.37 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="qzp4HEFr" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xv-0087bv-Ca; Fri, 12 Dec 2025 20:38:11 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=6+sXrUr5LvBqW8hHD2oULe/kxjAvnPiwR/5Jz/SJlSY=; b=qzp4HEFrE9mNFqiaaneQOvR2Bh mIGWY/Vbrpdzq8LWo5aPKldFXJ5VE5en4WQybR+PgzmrXFipuNHFCDItilEJ74OvVA5lfEwtl/Wht mXgRil8IKGcf/tvxRwwekGJswfmJVq6dG6ZBr1we6n0oinQPkaErGd/VIPVklOgL35wxEMeclCtnG vamzhonZWS7+29s3CvoddOh2Y5ZYVJAg24efZxAm4lsYsAifVS3WtPnyX9nc8yLK9g+umVOeNu4pt v23EHn44cACRuiy47aWRme6OPpz2YHyBE3vlom4/QJ5fHIC5kv+ggi6zXP/2Q8GHUJR8ObepWnRN+ viGskkcA==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xv-0006un-0k; Fri, 12 Dec 2025 20:38:11 +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 1vU8xk-0030pR-1q; Fri, 12 Dec 2025 20:38:00 +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 11/16] bitfield: Common up validation of the mask parameter Date: Fri, 12 Dec 2025 19:37:16 +0000 Message-Id: <20251212193721.740055-12-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight There are three places where the mask is checked for being non-zero and contiguous. Add a simple expression that checks it and use in all three places. Signed-off-by: David Laight --- include/linux/bitfield.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 138f4c14786d..6f454ef43d24 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -45,13 +45,15 @@ =20 #define __bf_shf(x) (__builtin_ffsll(x) - 1) =20 +#define __BF_VALIDATE_MASK(mask) \ + (!(mask) || ((mask) & ((mask) + ((mask) & -(mask))))) + #define __BF_FIELD_CHECK_MASK(_mask, _pfx) \ do { \ BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ _pfx "mask is not constant"); \ - BUILD_BUG_ON_MSG((_mask) =3D=3D 0, _pfx "mask is zero"); \ - __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ - (1ULL << __bf_shf(_mask))); \ + BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(_mask), \ + _pfx "mask is zero or not contiguous"); \ } while (0) =20 #define __BF_FIELD_CHECK_VAL(mask, val, pfx) \ @@ -122,8 +124,6 @@ __BF_FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ }) =20 -#define __BF_CHECK_POW2(n) BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) !=3D 0) - /** * FIELD_PREP_CONST() - prepare a constant bitfield element * @_mask: shifted mask defining the field's length and position @@ -138,12 +138,10 @@ */ #define FIELD_PREP_CONST(_mask, _val) \ ( \ - /* mask must be non-zero */ \ - BUILD_BUG_ON_ZERO((_mask) =3D=3D 0) + \ + /* mask must be non-zero and contiguous */ \ + BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(_mask)) + \ /* check if value fits */ \ BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \ - /* check if mask is contiguous */ \ - __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) + \ /* and create the value */ \ (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)) \ ) @@ -189,7 +187,7 @@ extern void __compiletime_error("bad bitfield mask") __bad_mask(void); static __always_inline u64 field_multiplier(u64 field) { - if ((field | (field - 1)) & ((field | (field - 1)) + 1)) + if (__BF_VALIDATE_MASK(field)) __bad_mask(); return field & -field; } --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 C7DC12F6184; Fri, 12 Dec 2025 19:38:12 +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=1765568295; cv=none; b=pIYgTIiEsxHjcXon9YO4MvGmjOkjyC5/D0PCO+XFgRoWuiIw3lMaueD/I88obYd2S3L/s35oKAPPhldU+Og/+8B4kf0SK98Z0r9l55ZQfL4LBa4TCCt0vF00tbXL51yNj6P5x5lhH38nEQRma8tVsCH9K3N6+B9WDGOge6TQxuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568295; c=relaxed/simple; bh=CSJsxa9xyu7aDhk6yxlncz4abHbJ8KPOGVhQs3YLKhg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AL9Qd6eH8SwPvIxwh1PoPzEukd5JxQVAVlq/ihih3eAy7Y2F3l9VBtwJMK5mrPvWdohZY+/wVA7IHFEYVo5o17UY+4CLM2t5SQLmI7MoJ2idk8y3O3+URYpuaEMGI+klNkbCNWveDlfm9QWpwLe/C5RFH21RcJf91eQ/aFawhVY= 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=BFFCouyy; 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="BFFCouyy" 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 1vU8xu-007Taj-EW; Fri, 12 Dec 2025 20:38:10 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=6aqv+V5GEVFjOVOl0hKZO1gtT1BRvvjcLF837XqfAaE=; b=BFFCouyyaTIes4oFGBd+WEFrmd B9AuCUlRMZtZuBdy0f0RHN5KOA2O43c7D8uV74I8jpNC2PJ5Dd0GKr7Oe0ipnYK1NHajfEu7ALt+I WvgIZ9v/cnhuptTmRIykKv9ODiSw8G1eNzXO5IAHxSyCiYWLuIMhqa/O27JMIbYEd3Mu/LcSbnFU7 Lk79jjsaexlTPu2vmYiRzjx2SZSBnGF0U/lixe4pvAU2zboG8h4NqjrOZB3S6WnQheZdlRpTj/OVT CsHjZI4VvclE/6BS+6JrEHS/AxZZCi/jRfDui6RgmaZ5siMbQHdZikUKDCyJ4UL95gew5Gzg9c7nb G5mi7idw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xu-00039x-5D; Fri, 12 Dec 2025 20:38:10 +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 1vU8xl-0030pR-3T; Fri, 12 Dec 2025 20:38:01 +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 12/16] bitfield: Remove leading _ from #define formal parameter names Date: Fri, 12 Dec 2025 19:37:17 +0000 Message-Id: <20251212193721.740055-13-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight There is no need to 'protect' formal parameter names from anything outside the #define body itself. Signed-off-by: David Laight --- include/linux/bitfield.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 6f454ef43d24..753032285754 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -48,12 +48,12 @@ #define __BF_VALIDATE_MASK(mask) \ (!(mask) || ((mask) & ((mask) + ((mask) & -(mask))))) =20 -#define __BF_FIELD_CHECK_MASK(_mask, _pfx) \ +#define __BF_FIELD_CHECK_MASK(mask, pfx) \ do { \ - BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ - _pfx "mask is not constant"); \ - BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(_mask), \ - _pfx "mask is zero or not contiguous"); \ + BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), \ + pfx "mask is not constant"); \ + BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(mask), \ + pfx "mask is zero or not contiguous"); \ } while (0) =20 #define __BF_FIELD_CHECK_VAL(mask, val, pfx) \ @@ -126,8 +126,8 @@ =20 /** * FIELD_PREP_CONST() - prepare a constant bitfield element - * @_mask: shifted mask defining the field's length and position - * @_val: value to put in the field + * @mask: shifted mask defining the field's length and position + * @val: value to put in the field * * FIELD_PREP_CONST() masks and shifts up the value. The result should * be combined with other fields of the bitfield using logical OR. @@ -136,14 +136,14 @@ * be used in initializers. Error checking is less comfortable for this * version, and non-constant masks cannot be used. */ -#define FIELD_PREP_CONST(_mask, _val) \ +#define FIELD_PREP_CONST(mask, val) \ ( \ /* mask must be non-zero and contiguous */ \ - BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(_mask)) + \ + BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(mask)) + \ /* check if value fits */ \ - BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \ + BUILD_BUG_ON_ZERO(~((mask) >> __bf_shf(mask)) & (val)) + \ /* and create the value */ \ - (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)) \ + (((typeof(mask))(val) << __bf_shf(mask)) & (mask)) \ ) =20 /** --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 C289330C61B; Fri, 12 Dec 2025 19:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568300; cv=none; b=lpU27T6ruuda58wKwuV2lI6qdtWqiROIU0QIio6hMt7wEX0tduail72BdiHz8kOm/6m8lsd/dNxrbWJ+cNDyxQl2j9RtX5GYcbr0+2WiptffSOjfcWJW7vtQmKIiOx6sB/O8W6dCUmnISErASg9mUc3S449xkYqSspYVqPIuFl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568300; c=relaxed/simple; bh=FZebAVupBpD/5BuzxHllVuuoIS9XAJ2zQRcrN3s/9NQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lcv3jrSBGx7Gjs2CwyITnVs+aD4RbL4wQqUFHX9GRhfulEjfhqf3KCF1ccaEpydIChTgEB3gHYFw7g3mShCdCLpEI+Igf0qlI1LmoCI20SlNPSTaySoiYCcmmJkN/XW4NP9+ZS3lPUrG0wRkkhSk1My4mIsqaCpLe9mSBT5QDeY= 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=rCVdhptU; arc=none smtp.client-ip=185.226.149.37 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="rCVdhptU" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xz-0087hl-QJ; Fri, 12 Dec 2025 20:38:15 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=kX4bnsd3udp5BS7zIV0q6a9VDxCuUN3XKJfyVxOblBg=; b=rCVdhptUM4cS4HcxnO7lZV6yAl skVofjcUjdkmL7VhLq1foraqmdg4Y6ZXxmM94fZB2Ta5zcMos5+G0nJTkkrNaab4h7we4i/E2cakH TgS8splwe9MigMtivJ9dDnfyAjiD7jzFmrP9Q9yz+Gw6JHSCLdq4wMApOrcXMFle66MqtiCT6htiD Rluf4mot3H2ap+Jeq7QZFHgm+xeNgj8DHlJOPhv05tMBPLK8zzgL6Pl3/E4pDHYtUbDS6AFbXkx3J zGCLXTIvnMo2pY+e0ZyDYJkSyeunyjtgNjcgmjoK9UiSfuGCL9sm9WJEnAsJtEMwuiidaKO837r9s HcEUfVwg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xz-0003Ao-Fc; Fri, 12 Dec 2025 20:38:15 +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 1vU8xm-0030pR-3h; Fri, 12 Dec 2025 20:38:02 +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 13/16] bitfield: Reduce indentation Date: Fri, 12 Dec 2025 19:37:18 +0000 Message-Id: <20251212193721.740055-14-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight There is no need to double indent the body of #defines. Leave the opening ( and closing ) on their own lines. Remove extra tabs before line continuations. Signed-off-by: David Laight --- include/linux/bitfield.h | 132 +++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 753032285754..03206be4ab54 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -48,37 +48,37 @@ #define __BF_VALIDATE_MASK(mask) \ (!(mask) || ((mask) & ((mask) + ((mask) & -(mask))))) =20 -#define __BF_FIELD_CHECK_MASK(mask, pfx) \ - do { \ - BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), \ - pfx "mask is not constant"); \ - BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(mask), \ - pfx "mask is zero or not contiguous"); \ - } while (0) +#define __BF_FIELD_CHECK_MASK(mask, pfx) \ +do { \ + BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), \ + pfx "mask is not constant"); \ + BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(mask), \ + pfx "mask is zero or not contiguous"); \ +} while (0) =20 #define __BF_FIELD_CHECK_VAL(mask, val, pfx) \ BUILD_BUG_ON_MSG(__builtin_constant_p(val) && \ ~((mask) >> __bf_shf(mask)) & (val), \ pfx "value too large for the field") =20 -#define __BF_FIELD_CHECK_REG(mask, reg, pfx) \ - BUILD_BUG_ON_MSG((mask) + 0U + 0UL + 0ULL > \ - ~0ULL >> (64 - 8 * sizeof (reg)), \ +#define __BF_FIELD_CHECK_REG(mask, reg, pfx) \ + BUILD_BUG_ON_MSG((mask) + 0U + 0UL + 0ULL > \ + ~0ULL >> (64 - 8 * sizeof (reg)), \ pfx "type of reg too small for mask") =20 -#define __BF_FIELD_PREP(mask, val, pfx) \ - ({ \ - __BF_FIELD_CHECK_MASK(mask, pfx); \ - __BF_FIELD_CHECK_VAL(mask, val, pfx); \ - ((val) << __bf_shf(mask)) & (mask); \ - }) +#define __BF_FIELD_PREP(mask, val, pfx) \ +({ \ + __BF_FIELD_CHECK_MASK(mask, pfx); \ + __BF_FIELD_CHECK_VAL(mask, val, pfx); \ + ((val) << __bf_shf(mask)) & (mask); \ +}) =20 -#define __BF_FIELD_GET(mask, reg, pfx) \ - ({ \ - __BF_FIELD_CHECK_MASK(mask, pfx); \ - __BF_FIELD_CHECK_REG(mask, reg, pfx); \ - ((reg) & (mask)) >> __bf_shf(mask); \ - }) +#define __BF_FIELD_GET(mask, reg, pfx) \ +({ \ + __BF_FIELD_CHECK_MASK(mask, pfx); \ + __BF_FIELD_CHECK_REG(mask, reg, pfx); \ + ((reg) & (mask)) >> __bf_shf(mask); \ +}) =20 /** * FIELD_MAX() - produce the maximum value representable by a field @@ -87,12 +87,12 @@ * FIELD_MAX() returns the maximum value that can be held in the field * specified by @mask. */ -#define FIELD_MAX(mask) \ - ({ \ - __auto_type _mask =3D mask; \ - __BF_FIELD_CHECK_MASK(_mask, "FIELD_MAX: "); \ - (_mask >> __bf_shf(_mask)); \ - }) +#define FIELD_MAX(mask) \ +({ \ + __auto_type _mask =3D mask; \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_MAX: "); \ + (_mask >> __bf_shf(_mask)); \ +}) =20 /** * FIELD_FIT() - check if value fits in the field @@ -101,13 +101,13 @@ * * Return: true if @val can fit inside @mask, false if @val is too big. */ -#define FIELD_FIT(mask, val) \ - ({ \ - __auto_type _mask =3D mask; \ - __auto_type _val =3D 1 ? (val) : _mask; \ - __BF_FIELD_CHECK_MASK(_mask, "FIELD_FIT: "); \ - !((_val << __bf_shf(_mask)) & ~_mask); \ - }) +#define FIELD_FIT(mask, val) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _val =3D 1 ? (val) : _mask; \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_FIT: "); \ + !((_val << __bf_shf(_mask)) & ~_mask); \ +}) =20 /** * FIELD_PREP() - prepare a bitfield element @@ -117,12 +117,12 @@ * FIELD_PREP() masks and shifts up the value. The result should * be combined with other fields of the bitfield using logical OR. */ -#define FIELD_PREP(mask, val) \ - ({ \ - __auto_type _mask =3D mask; \ - __auto_type _val =3D 1 ? (val) : _mask; \ - __BF_FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ - }) +#define FIELD_PREP(mask, val) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _val =3D 1 ? (val) : _mask; \ + __BF_FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ +}) =20 /** * FIELD_PREP_CONST() - prepare a constant bitfield element @@ -136,15 +136,15 @@ * be used in initializers. Error checking is less comfortable for this * version, and non-constant masks cannot be used. */ -#define FIELD_PREP_CONST(mask, val) \ - ( \ - /* mask must be non-zero and contiguous */ \ - BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(mask)) + \ - /* check if value fits */ \ - BUILD_BUG_ON_ZERO(~((mask) >> __bf_shf(mask)) & (val)) + \ - /* and create the value */ \ - (((typeof(mask))(val) << __bf_shf(mask)) & (mask)) \ - ) +#define FIELD_PREP_CONST(mask, val) \ +( \ + /* mask must be non-zero and contiguous */ \ + BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(mask)) + \ + /* check if value fits */ \ + BUILD_BUG_ON_ZERO(~((mask) >> __bf_shf(mask)) & (val)) + \ + /* and create the value */ \ + (((typeof(mask))(val) << __bf_shf(mask)) & (mask)) \ +) =20 /** * FIELD_GET() - extract a bitfield element @@ -154,12 +154,12 @@ * FIELD_GET() extracts the field specified by @mask from the * bitfield passed in as @reg by masking and shifting it down. */ -#define FIELD_GET(mask, reg) \ - ({ \ - __auto_type _mask =3D mask; \ - __auto_type _reg =3D reg; \ - __BF_FIELD_GET(_mask, _reg, "FIELD_GET: "); \ - }) +#define FIELD_GET(mask, reg) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _reg =3D reg; \ + __BF_FIELD_GET(_mask, _reg, "FIELD_GET: "); \ +}) =20 /** * FIELD_MODIFY() - modify a bitfield element @@ -170,16 +170,16 @@ * FIELD_MODIFY() modifies the set of bits in @reg_p specified by @mask, * by replacing them with the bitfield value passed in as @val. */ -#define FIELD_MODIFY(mask, reg_p, val) \ - ({ \ - __auto_type _mask =3D mask; \ - __auto_type _reg_p =3D reg_p; \ - __auto_type _val =3D 1 ? (val) : _mask; \ - __BF_FIELD_CHECK_MASK(_mask, "FIELD_MODIFY: "); \ - __BF_FIELD_CHECK_VAL(_mask, _val, "FIELD_MODIFY: "); \ - __BF_FIELD_CHECK_REG(_mask, *_reg_p, "FIELD_MODIFY: "); \ - *_reg_p =3D (*_reg_p & ~_mask) | ((_val << __bf_shf(_mask)) & _mask); \ - }) +#define FIELD_MODIFY(mask, reg_p, val) \ +({ \ + __auto_type _mask =3D mask; \ + __auto_type _reg_p =3D reg_p; \ + __auto_type _val =3D 1 ? (val) : _mask; \ + __BF_FIELD_CHECK_MASK(_mask, "FIELD_MODIFY: "); \ + __BF_FIELD_CHECK_VAL(_mask, _val, "FIELD_MODIFY: "); \ + __BF_FIELD_CHECK_REG(_mask, *_reg_p, "FIELD_MODIFY: "); \ + *_reg_p =3D (*_reg_p & ~_mask) | ((_val << __bf_shf(_mask)) & _mask); \ +}) =20 extern void __compiletime_error("value doesn't fit into mask") __field_overflow(void); --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 C13A530BF6E for ; Fri, 12 Dec 2025 19:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568299; cv=none; b=mqTsxjAt2tnbbBkx5yTNzrMEzkFqGjVvTsYcBy3DRWFhxVqvzeEiAm0XBAjNZfk2UUKMoAbdQTQxIP9fyOOfb6MmsncwZhRXc23kUT1zOhS/nr/be0rrIAeFSJoh9nFSBZzVK6YmgaD7/KOcihFJWa9KTUFu7fD+FRN/vcTsjtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568299; c=relaxed/simple; bh=iX4bCRJMjNTc89J6Hb3IJZ8DlWuZIDZYYAn/N65O7DQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bE/VU0690fHR3mjNIeJVQNkd83n5zdp4vwZSLP0FHOKkxlR28pTtdJsmPnRsZPcyT1dgsv/DCi8dw/ZsjtNcRT2kJdRtfSnZGT94Gw5LX+ohDji5/oliX66lnrq4UYXCyKyhKiWyfoF7iUyt37HeRGl45facnsg6NVCEBkKi6pA= 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=Wpdx0hNl; arc=none smtp.client-ip=185.226.149.37 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="Wpdx0hNl" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xy-0087gq-OP; Fri, 12 Dec 2025 20:38:14 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=XGNNIc7IKcGdjBNdCWUpuNKT8BFgCw2QYiU5srDt8fQ=; b=Wpdx0hNlbtmydznicg6yGTxTE9 i+/7jgy7Yx8lPlzp4IottmUUrwCU1IO7VJPIaV+S9mAKgvv5A8OZ3sRJBJbMw5RvKwBcsmpFlxc+I gzPgX7iZw8yehHsqpHvCxT3blsWtG/ALesGkD3NxDxHZ7cGFURST/OO+qataDwXcEFCiS1JupodY9 +MJJYHxeE0swVBQr14URnBmXccDVKX1SEBxCHqXTuUhlNvgRbkAF8ct2aAHTv/o27QYRLND27O5qf E0srSaYNv34Z1fdRPpFGr6JG0/YHKacRjGcdcEooNVFmtY8cK7xF4PZt3+zWC5XbwGzqjSppGv8FK GvGn8jWQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xy-0003Ac-6G; Fri, 12 Dec 2025 20:38:14 +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 1vU8xn-0030pR-5E; Fri, 12 Dec 2025 20:38:03 +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 14/16] bitfield: Add comment block for the host/fixed endian functions Date: Fri, 12 Dec 2025 19:37:19 +0000 Message-Id: <20251212193721.740055-15-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Copied almost verbatim from the commit message that added the functions. Signed-off-by: David Laight --- include/linux/bitfield.h | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 03206be4ab54..3bf82121a282 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -181,6 +181,49 @@ do { \ *_reg_p =3D (*_reg_p & ~_mask) | ((_val << __bf_shf(_mask)) & _mask); \ }) =20 +/* + * Primitives for manipulating bitfields both in host- and fixed-endian. + * + * * u32 le32_get_bits(__le32 val, u32 field) extracts the contents of the + * bitfield specified by @field in little-endian 32bit object @val and + * converts it to host-endian. + * + * * void le32p_replace_bits(__le32 *p, u32 v, u32 field) replaces + * the contents of the bitfield specified by @field in little-endian + * 32bit object pointed to by @p with the value of @v. New value is + * given in host-endian and stored as little-endian. + * + * * __le32 le32_replace_bits(__le32 old, u32 v, u32 field) is equivalent = to + * ({__le32 tmp =3D old; le32p_replace_bits(&tmp, v, field); tmp;}) + * In other words, instead of modifying an object in memory, it takes + * the initial value and returns the modified one. + * + * * __le32 le32_encode_bits(u32 v, u32 field) is equivalent to + * le32_replace_bits(0, v, field). In other words, it returns a little-= endian + * 32bit object with the bitfield specified by @field containing the + * value of @v and all bits outside that bitfield being zero. + * + * Such set of helpers is defined for each of little-, big- and host-endian + * types; e.g. u64_get_bits(val, field) will return the contents of the bi= tfield + * specified by @field in host-endian 64bit object @val, etc. Of course, = for + * host-endian no conversion is involved. + * + * Fields to access are specified as GENMASK() values - an N-bit field + * starting at bit #M is encoded as GENMASK(M + N - 1, M). Note that + * bit numbers refer to endianness of the object we are working with - + * e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower + * 4 bits of the first byte. In __le16 it would refer to the first byte + * and the lower 4 bits of the second byte, etc. + * + * Field specification must be a constant; __builtin_constant_p() doesn't + * have to be true for it, but compiler must be able to evaluate it at + * build time. If it cannot or if the value does not encode any bitfield, + * the build will fail. + * + * If the value being stored in a bitfield is a constant that does not fit + * into that bitfield, a warning will be generated at compile time. + */ + extern void __compiletime_error("value doesn't fit into mask") __field_overflow(void); extern void __compiletime_error("bad bitfield mask") --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 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 361D32EFDA2; Fri, 12 Dec 2025 19:38:14 +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=1765568297; cv=none; b=X7WnQoW8hK78LMtKA6UysoiPPaAatBAx2hD66hzisSPjvgG4cAUXfUfXaVbf4CFWtjHdhkP30fVj2ixUaNWjqephto7ZkmjSV5sPgYZAgJoy+NXGJSewAkwlCiuUWuQEe8TEd/ZOKLC5VAPlVgFsfzK2lENsjAB4L5P+hy/Po80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765568297; c=relaxed/simple; bh=0LivVI6n2Hn6n9OC7XzMKkHYvEuxGTxy2TCbVRFLvp8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o/Lm1zp8oKfphbsMyy6dpo4jPWaeA+EHFTeivEYSLdCdcfgJFinuc/q+macSFSY7MGNdJWBnot1HpAStXi5oMhmzuv4UpEn1mjtQiVSslVJM9n4Ne/paQTA1pdBOK0Nf+DIIjIHf0UIZ5lGirKf95FxQJTHkKVNZ+uVOWI8uNaU= 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=bu2KWORW; 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="bu2KWORW" Received: from mailtransmit02.runbox ([10.9.9.162] 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 1vU8xx-007Tbj-7L; Fri, 12 Dec 2025 20:38:13 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=K3GjdOlpY6miMHRcMr+AALWLshNL5czI7BOpgFx6os0=; b=bu2KWORW3Adja9xUa9PQSPIHCd m7v/JlPBqaiVxiddGomf5+e//NGcMrmdU14xBevFL7J9CiEQC8gXKX1oG8cMXugLfttp1D24e1Rrp 32n3ZR7jQi696/px2IfrAXnxAiPR00U/OdtqSpGLzrcrwDqGbBBvJcndNkokLTOTWdkMWE5F7HwjI 2ewng04+DRmokPV05S8vtly1MV5DhE33mBZSoRQGkWPtD7OJz6Iaeif06EszmPEMy/molKwrYSwoG kFycIHX6QmkOtdej9rG0HrlVe1vd7qs/GOgrA0Zx8XY68hKOplySl03QqGgCHzZRG8eV4u99hOXSC o8+W3Sgg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xw-0006ut-TP; Fri, 12 Dec 2025 20:38:13 +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 1vU8xo-0030pR-77; Fri, 12 Dec 2025 20:38:04 +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 15/16] bitfield: Update comments for le/be functions Date: Fri, 12 Dec 2025 19:37:20 +0000 Message-Id: <20251212193721.740055-16-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight Make it clear the the values are converted to host order before being acted on. Order the explantions with the simple functions first. These still need converting to kerneldoc format. Signed-off-by: David Laight --- include/linux/bitfield.h | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 3bf82121a282..3f43683ebe96 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -184,24 +184,24 @@ do { \ /* * Primitives for manipulating bitfields both in host- and fixed-endian. * - * * u32 le32_get_bits(__le32 val, u32 field) extracts the contents of the - * bitfield specified by @field in little-endian 32bit object @val and - * converts it to host-endian. * - * * void le32p_replace_bits(__le32 *p, u32 v, u32 field) replaces - * the contents of the bitfield specified by @field in little-endian - * 32bit object pointed to by @p with the value of @v. New value is - * given in host-endian and stored as little-endian. + * * u32 le32_get_bits(__le32 val, u32 field) converts the little-endian 3= 2bit + * object @val to host-endian then extracts the contents of the bitfield + * specified by @field. + * + * * __le32 le32_encode_bits(u32 v, u32 field) encodes the value of @v into + * the bitfield specified by @field then converts the value to little-en= dian. + * All the bits outside that bitfield being zero. * - * * __le32 le32_replace_bits(__le32 old, u32 v, u32 field) is equivalent = to - * ({__le32 tmp =3D old; le32p_replace_bits(&tmp, v, field); tmp;}) - * In other words, instead of modifying an object in memory, it takes - * the initial value and returns the modified one. + * * __le32 le32_replace_bits(__le32 old, u32 v, u32 field) converts the + * little-endian 32bit object @old to host order, replaces the contents + * of the bitfield specified by @field with @v, then returns the value + * converted back to little-endian. * - * * __le32 le32_encode_bits(u32 v, u32 field) is equivalent to - * le32_replace_bits(0, v, field). In other words, it returns a little-= endian - * 32bit object with the bitfield specified by @field containing the - * value of @v and all bits outside that bitfield being zero. + * * void le32p_replace_bits(__le32 *p, u32 v, u32 field) replaces + * the contents of the bitfield specified by @field in little-endian + * 32bit object pointed to by @p with the value of @v. + * Equivalent to *p =3D le32_replace_bits(*p, v, field). * * Such set of helpers is defined for each of little-, big- and host-endian * types; e.g. u64_get_bits(val, field) will return the contents of the bi= tfield @@ -210,15 +210,13 @@ do { \ * * Fields to access are specified as GENMASK() values - an N-bit field * starting at bit #M is encoded as GENMASK(M + N - 1, M). Note that - * bit numbers refer to endianness of the object we are working with - + * bit numbers refer to the value after being converted to host order - * e.g. GENMASK(11, 0) in __be16 refers to the second byte and the lower * 4 bits of the first byte. In __le16 it would refer to the first byte * and the lower 4 bits of the second byte, etc. * - * Field specification must be a constant; __builtin_constant_p() doesn't - * have to be true for it, but compiler must be able to evaluate it at - * build time. If it cannot or if the value does not encode any bitfield, - * the build will fail. + * Field specification must be a non-zero constant, otherwise the build + * will fail. * * If the value being stored in a bitfield is a constant that does not fit * into that bitfield, a warning will be generated at compile time. --=20 2.39.5 From nobody Sun Dec 14 06:42:25 2025 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 CC4BF2848A4; Fri, 12 Dec 2025 20:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765570471; cv=none; b=lV/I6etjjoKTUe9Py0O5YMef9DFsucqhz2VJcVqL7H09NO4ToC2Onis/O0Njg94zEZEpUWnJUWqt4SrfM17NyJMvVsaYHr3r7HYba0jBeEo9i24wknm2iR+aso81hPvp3quvJN0OCCABffAbNEPw0Ut+6zXZotEbKyz1YT8scYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765570471; c=relaxed/simple; bh=rrMpiY2/32uiPUxnNhqmlvJHbOrcOpzblK5lbAIbRbk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jl0D+TTw47iFRjzdYwe51sCOfnYulbONwj2R4zsJzO7uwPgY5+cdfDxzkK0VFgU83kuzsmsf036uhMvoSYc/X7Lm7SRV/LcBtQe2FTPz/6kB/JD93hRQAObzbDP3ANcA6fQzU8UQz+RsEtmvkusmH1AmJ3h6iBu8X/WLaqSoUJo= 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=V44ODLQ+; arc=none smtp.client-ip=185.226.149.37 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="V44ODLQ+" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vU8xw-0087f1-Vk; Fri, 12 Dec 2025 20:38:12 +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:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=XcOghhLB9x/wa6Uum/aSGpecagme4zwlntT5IjlJr3M=; b=V44ODLQ+lRgGqyb8F3/YQo74rb evsoP15xN7rXIKPmlxe6TPFmmNoTy0ucJiW/coe/xJioVH6J+3GLLYV0mlu31L9GinwvaZfuCuVeX eptBv1kmqug6H38uY8TrSlyKntc39s8JIhc1PqaapytK6DcJkNtWxwFRVXIJiroGzIPlcFRCca8gq AYJGhqpSDAI2OmK8GJ7Un+N40YS7siSvOuCZiYDfz3ceRVWC3OPcdWxMu/r9RNFjTAaI9ZTPQxcO/ /0wM/LFGBDVNssoa3EZf56Fy99Yow1efbWRPXx94LyABiruiviFiPwKCebYdl3FSmHK6vJUlXykC/ Wg6AMe+A==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vU8xw-0003AG-BA; Fri, 12 Dec 2025 20:38:12 +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 1vU8xp-0030pR-93; Fri, 12 Dec 2025 20:38:05 +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 16/16] build_bug.h; Remove __BUILD_BUG_ON_NOT_POWER_OF_2() Date: Fri, 12 Dec 2025 19:37:21 +0000 Message-Id: <20251212193721.740055-17-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251212193721.740055-1-david.laight.linux@gmail.com> References: <20251212193721.740055-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight It was added for, and only used by, bitfield.h. That not longer uses it so it can be removed. It should have been called BUILD_BUG_ON_NOT_ZERO_OR_POWER_OF_2() but there is no real need for such a specialised function. Signed-off-by: David Laight --- include/linux/build_bug.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h index 2cfbb4c65c78..0ca6cb79f704 100644 --- a/include/linux/build_bug.h +++ b/include/linux/build_bug.h @@ -17,8 +17,6 @@ __BUILD_BUG_ON_ZERO_MSG(e, ##__VA_ARGS__, #e " is true") =20 /* Force a compilation error if a constant expression is not a power of 2 = */ -#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON(((n) & ((n) - 1)) !=3D 0) #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ BUILD_BUG_ON((n) =3D=3D 0 || (((n) & ((n) - 1)) !=3D 0)) =20 --=20 2.39.5