From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 7C11F13790B for ; Thu, 18 Dec 2025 00:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766016974; cv=none; b=UqFvFNI7uyZIvPrQI2QW0uObhpNkbCCLjA7kB1Q3vxwN1kizjG26pzT9+fQxbUt8nSi0H92naUMHgaHEPHyR7yKHUrTKNLXqVd7m7DAnw0yawfCFuxczD7C3yksi6YQ5cMVB8/wzbJintw2k6vTunFfvG38/vosbEbYxV+rGWO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766016974; c=relaxed/simple; bh=q1qmuBmza8VfaF3Afck0gRS869aOeEUoNVUKKya/bPI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oAWB2SKiYkqGlsrPsDNsxcszoWsjkwTiPY+xIlWjM5MeOZ1YY0rKCsdTyQWOU2obD+F0P2+dm3nYuoo5PiIKeS7C3c05BUTJ2b8qfe7swezpkT/TeBB8PHG85zWlz2BWxXRN/drBhbBxkTzbQ8aT5oGdTMP1V3Momf/4yYHek/w= 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=LHinvTbx; arc=none smtp.client-ip=209.85.128.178 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="LHinvTbx" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-78c33d0df85so431477b3.0 for ; Wed, 17 Dec 2025 16:16:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766016971; x=1766621771; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4wlE8EMvGYZyAfYwBWrqMm3bD5k/3jSk7d8mDOagPfI=; b=LHinvTbxnwVcoDOIbtWzGxpZlxOsmfwb+PhUXmGfIRhBxuxtMVxZcUR4GGL+hMaqQG uNkIG+DCd4rUIB5JgAJM4FQFAmF61ml3JA0E/amvqxN9bwDzlVN5A4fpdKRaMakQ2wpF jEoZBl1sAYyRZg8laPBpj06jCLLXy7Z1wL/b6I6JQ4mJA1WquovXJ6M3/FHY8CZK/x7L pPOF6uMlVbsb5LHLDkvQLBpxb+ao1cdEGrGCJV1xGAvRXG8fDPT4W3bUOnQkJ0jSFwy9 8qP3TbgjAPwwFjwzzNjdW3dN/+CNnzOJV9T+O8G3mX4zOzujZWYcYRX+2phof4ITj/MR ZEYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766016971; x=1766621771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4wlE8EMvGYZyAfYwBWrqMm3bD5k/3jSk7d8mDOagPfI=; b=V4VdSPOqh1Y94cksBKsievwVzQ/AlmlyseuKULmfwJK5Xp4eDmv3IxmfIM3TBgKy2z Dl+Wligc7bEC1L2BqmDcJ5j8IxLQjiOUwiq15GG30E6J6mqi0ojyS5V1H/yWs7cq6IUU M18PnsAJtt2LY15Xwmang9EZRKQDVYbJOd/+HwCk0P1paSYf2fAXu8wB0aonG4zNW8sK nxVsoy1VjA4fR/ZNmOuSlWnhtMVwb2vZdNgjGOtBrwRxrSY5HyVwx0vucLHGItUNch33 P9NoWuxpb2kEdF81VVNqXtj+W9UdOJzth8ZPcrSg6g47nXuT3vnVBOhYtzw883ZFQUgt tmBg== X-Forwarded-Encrypted: i=1; AJvYcCU4UAIocs+87QklNwkfRsoQrLLbCceY7kaSz6+BiH/tSlUU4jb7B/n46Gahjc7rs+5DklL/nLsnJB+16Ho=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6y2shZLxg71RETRkvvMjT5hjttT8VQ5Mf1GuJMVMPyYOMcoB/ wNOEVixTFfHkKXlbVAgUkyZHepeJ4L+4jgPkaDZr1YXy/x17O1ae2y+WySo14w== X-Gm-Gg: AY/fxX7h8A2X9HSEpnSN+02yosgHHA/CuM6YwG48stuIZUU2nyBz+ZsYgh5AZNAyQlt cAHK/ScSsdzorTEAJtiAIQuz6D/4Dg8e06WKBgJO0vK7HVnUpMeyy02Zp1yTu7mdM8IxiFoRxrq qScESjrd5Z/8OF1B7Ue5YN1mo8x8BD5y0/OIASdktuQhV/kR4kd7EV0TYZcanHMc3jyfxLMMmtY Ha2GT8yIY5Qvwn9Z0sKhFk5zH5s8ADew63AqivwggPtVKv8qjPi4SZp+lgGYaM+3Kr5ipxX/gCz BVbLq4VwBQtKrPBAJXFvAFwRob3oCeL22HQNhUswQMWFUkgHi9oiJ7nYr5psYV2seOoJ9MIAiWP oaS55q6ldWMV8aXFNvpLppJ74bjTytSDrPyK0Fc6qWn6orcsKo98P1KGORY1/UZt3Qbiz6pLORi 5PWKSGfpc= X-Google-Smtp-Source: AGHT+IHqImXHRFrZT3XyJarbiuJdBni3A40c6SKiUdO+XjAYNcXK5lXxWE1jISl+My5MBXmoC4N2uA== X-Received: by 2002:a05:690c:6004:b0:786:5c6f:d242 with SMTP id 00721157ae682-78e66eaaba2mr159494997b3.69.1766016971272; Wed, 17 Dec 2025 16:16:11 -0800 (PST) Received: from localhost ([2601:346:0:79bd:52c0:aec0:bf15:a891]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78fa72aa1casm2473007b3.48.2025.12.17.16.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 16:16:10 -0800 (PST) Date: Wed, 17 Dec 2025 19:16:10 -0500 From: Yury Norov To: Nicolas Frattaroli Cc: 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 , david.laight.linux@gmail.com Subject: Re: [PATCH v2 03/16] bitmap: Use FIELD_PREP() in expansion of FIELD_PREP_WM16() Message-ID: References: <20251212193721.740055-1-david.laight.linux@gmail.com> <20251212193721.740055-4-david.laight.linux@gmail.com> <5257288.LvFx2qVVIh@workhorse> 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=us-ascii Content-Disposition: inline In-Reply-To: <5257288.LvFx2qVVIh@workhorse> On Wed, Dec 17, 2025 at 02:22:32PM +0100, Nicolas Frattaroli wrote: > On Friday, 12 December 2025 20:37:08 Central European Standard Time david.laight.linux@gmail.com wrote: > > 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 @@ > > > > /** > > * 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 = _val; \ > > - typeof(_mask) __mask = _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 = mask; \ > > + u32 _wm16_val = FIELD_PREP(_wm16_mask, val); \ > > + BUILD_BUG_ON_MSG(_wm16_mask > 0xffffu, \ > > + "FIELD_PREP_WM16: mask too large"); \ > > + _wm16_val | (_wm16_mask << 16); \ > > +}) > > > > /** > > * FIELD_PREP_WM16_CONST() - prepare a constant bitfield element with a mask in > > > > Tested-by: Nicolas Frattaroli > > Compiled it with my usual config and booted it on a board that uses > drivers that make use of these macros, and checked that things are > working. Nicolas, thanks for testing! Would you also want to add an explicit ack or review tag? David, I'm OK with this change. Please add bloat-o-meter and code generation examples, and minimize the diff as I asked in v1, before I can merge it. Thanks, Yury