From nobody Sun Dec 14 12:12:47 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