From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 406EB3A3E72 for ; Fri, 10 Apr 2026 09:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775812177; cv=none; b=ta6zPxNaKN4XKsw/UveSsi9IBg6RDoGvSCMYFanl/iS8M9NGL+cfKGWnn7QzMdhW/JXWy6xbL/uh51+bRIDFv9UT5bUM+UCI5uVwZGZM5hw1WABZBsKIT5eb1DD8lR4VLKJK/yTrxvA2oKCyHRhlX8Ndp6rKMs7hRUCdz3LuA80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775812177; c=relaxed/simple; bh=CeDIQlPSVyRY6RLCMum06ivIGvPGixQbl6EDKPplQf0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=qOTnQzjoHxP2wW54bip0EUSAEqTZeAUoyV4bf6Hgq8wI8sLGVz1dLs1afM0YS1j4rK6TwhxmFgSI4Mrx8HDfBSURQm/B6vQdnofsbgLOnK35GkwUV0EwL4KjITXjexNPtFpCH8JFdcCsRYke4vmSXj8lckBn2ezgW0s92E+M7fY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OwxpKe9S; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OwxpKe9S" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4887f49ec5aso22015725e9.1 for ; Fri, 10 Apr 2026 02:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775812174; x=1776416974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LXQ0Z7DNBzr8sko6cvPNQJuT+4Wl7pILRRIErcDDHUg=; b=OwxpKe9S16V64Fwez0ERwj7EM8DuCnV8LZQykT5jauIP0kCjofyqilwYswJYSGD8Td Zb5RVcjKePKLG1sYoiWc0Ba5CodivH6THQw+qR7ecgBtzKwjBeeizVvTIw0I7hkouSNl XqehQONlvTxwYBTGkOkiamOvblf/636t1vpjJWoOUHQ3AtaVZUJhvDlfwaXVco3YOGZ4 s4E1PWEiKIg9QmL5nE+YhjaucUeGIEJwe9JPo/dcq0+gqBY5v35k/S6DsZD36Ca4vMeD yOHjO5qSWX9QN8JvtrDOsdcmMBhHujQZWPc8l1xk7yOUdlAcu9zVL3lWDeWYr5the5LP HglA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775812174; x=1776416974; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LXQ0Z7DNBzr8sko6cvPNQJuT+4Wl7pILRRIErcDDHUg=; b=gmhFt6LXTu2zu/SmbEE0aIy4w5E/QYtPrE0w+e2cxwRiUqwjtP7gIL+ff3JMAFNVPN ERbA7nKDvr5WExVjcJbFBQKJlStUJV8tv7Zxp20kejLG32G9Upo6bKu1y9paYOQUuEP6 WgD04V/pa1IX97ZkBqS/3PXgEwBGNaszOvzAouPwWdtTZ2Jh7cWI9DA6W4XvGwp0arBV TkJMezCoU/zh90n6IGUa2JxsnFS/uh5IxYf/QieGHW8jKcXQSsc78mlm3VP7q4ijOfHY j3R/S+QMPBbzpKTSVR+4amHnc2CAVMBJIz+8hlAuog2wKwkZTOBUQERTMpMGwl4TQiP2 S7+Q== X-Forwarded-Encrypted: i=1; AJvYcCUZgZRlynWwNXwI3Y9dRNF5mwfZ7v8ybICBbWhTI+lyaNvhTT3CYfBSb6xmxeQF4Biz6qhIbxYz4aOHVek=@vger.kernel.org X-Gm-Message-State: AOJu0YyVsp54wf4q7qSI3gLkwh8D3P5b6kwmkd3n251AOP3EcmFByFfg 0cy5q9IVbtP444xnlQH1VZ3oxB3IdwMjyVdbnFLrs8BAO2vPFXOmEMfi X-Gm-Gg: AeBDies21ElRq+qNyq4qNWk3uVd6QgQo/OOSpuImZ8tMUpJFZBjmLO7kM8aZd9AbeV7 4R0BrLRsEuWfPhmOVsRZ6MWlBzRQ0v/WixQuPmSxI7T8fxflzdLUM5HaTUHFSJdoAKYqoAIFcRO ts7R15q6ARzNnH62mWyUSM2Rj7ZdlBPJr4/Wb9Y68kifn8iRTHQNxGCZa3bw4uIAsZjfQFp7Vam 4HipxLErRCMaIDAPdVtJxbEnf3J04KOctpOsk/GaXg0RPLXqq4sxRcWWhKE43CEXfnhpjPQmtaR w0x+ph5VNnMkdgc11RdFm4giw5KKgBqeiAqTQJ76va2Z5e5oFEL5piZO0E+OXYAqHi3EXeIBSf0 QiCuYJE+yNx375h+zZiC+OWP7gUeUWfnF4FBLLprrjh1fEejOij+oOy2YFkOtlKqQCCLvf6mSKm +JsephwTPim3lU086xioZKI21I2E6Xaiwbz23ZCQg/B+GMyHhZhQOFCmXaGeaLU8Jq+vpc59FUv bdcE8Doj1hG X-Received: by 2002:a05:600c:4f95:b0:488:be58:bb5b with SMTP id 5b1f17b1804b1-488d686c443mr29364025e9.24.1775812174234; Fri, 10 Apr 2026 02:09:34 -0700 (PDT) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e50015sm6395471f8f.27.2026.04.10.02.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 02:09:33 -0700 (PDT) From: david.laight.linux@gmail.com To: Geert Uytterhoeven , Alexandre Belloni , Jonathan Cameron , Crt Mori , =?UTF-8?q?Nuno=20S=C3=A1?= , Richard Genoud , Andy Shevchenko , Yury Norov , Rasmus Villemoes , linux-kernel@vger.kernel.org (open list) Cc: David Laight Subject: [PATCH 1/1] bitfield.h: Ensure FIELD_PREP_CONST() is constant Date: Fri, 10 Apr 2026 10:09:27 +0100 Message-Id: <20260410090927.60484-1-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: David Laight Some versions of gcc report that some expressions involving __builtin_ffsll(1ull << 63) are not integer constant expressions. Rework FIELD_PREP_CONST() to avoid the issue. Signed-off-by: David Laight --- Note that when 'val' is a variable 'val << constant' is likely to execute faster than 'val * (1 << constant)'. So the normal FIELD_PREP() is best left alone. include/linux/bitfield.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 54aeeef1f0ec..f21765851d5c 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -45,6 +45,7 @@ */ #define __bf_shf(x) (__builtin_ffsll(x) - 1) +#define __bf_low_bit(mask) ((mask) & (~(mask) + 1)) #define __scalar_type_to_unsigned_cases(type) \ unsigned type: (unsigned type)0, \ @@ -138,8 +139,6 @@ __FIELD_PREP(_mask, _val, "FIELD_PREP: "); \ }) -#define __BF_CHECK_POW2(n) BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) != 0) - /** * FIELD_PREP_CONST() - prepare a constant bitfield element * @_mask: shifted mask defining the field's length and position @@ -157,11 +156,11 @@ /* mask must be non-zero */ \ BUILD_BUG_ON_ZERO((_mask) == 0) + \ /* check if value fits */ \ - BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \ + BUILD_BUG_ON_ZERO(~((_mask) / __bf_low_bit(_mask)) & (_val)) + \ /* check if mask is contiguous */ \ - __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) + \ + BUILD_BUG_ON_ZERO((_mask) & ((_mask) + __bf_low_bit(_mask))) + \ /* and create the value */ \ - (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)) \ + (((_val) * __bf_low_bit(_mask)) & (_mask)) \ ) /** -- 2.39.5