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