From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com [136.143.188.12]) (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 19C4A2C0269 for ; Thu, 27 Nov 2025 14:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.12 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764252736; cv=pass; b=Gq60b2rf6Zn4rmRKf5U7rFyIIR0JfUqg0xbLCr2YXY899+LApFz50ZfS53QK9J4EzHo94Sxaj/gS6tidY8EEofw30AR0wJuOP4SOv/G+CM0EacjbTlHfyhKkb8ypJcBOTSxNvheKx2g29FpyQMExMWtkvNTcryZKcsKqBOJPgkE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764252736; c=relaxed/simple; bh=kq3mUQ8mg+cILoAwYy9vaE9EpOvArtJqXnPQ74+z7hQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NB1c0+nIsIH9OsPyhn/uJ6Bbtop9+eIufFOD9sCO+et1tWatQ3e6pvey+UF18ntvIO7CWPZwFMgkXu5dYZ80zdJYZGRgyQM9Bpnz5Ei52LMi5JaM61WbQj1e/8w+yhMwq8XiKN3nif+kZLv3sGfCy5Y80LbrJ6msNPD0pmLrJZI= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=a4KBfNDr; arc=pass smtp.client-ip=136.143.188.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="a4KBfNDr" ARC-Seal: i=1; a=rsa-sha256; t=1764252723; cv=none; d=zohomail.com; s=zohoarc; b=nfEZjReh5X8itl6iSPJ8RS/xJ9JmedQY51QVSqB2YxMzPuZhLewzfdmxqzf4DM1PyOg+HiKkn+pYfKFoTIWYWE+lP96MD/6wahn2Al29b8+eWaWdke7Yq+c/3y0hYU5heqmwjtUBk+jkX1FXTKkDSJ6mnvVyyGJa9NQjlaVvGyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252723; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=KSstCQJPiWvJNcD06AhDEsuHKHfRbmwAK0Db6Ne2wX0=; b=P22b/dNrkwHo68KzRtpscaK6HygEN+ZL2iXj4tqnVNourIb+ha+IPgFzL89xGY/XxiMzgY/Qpuxpe6Z9q38wxLN04c04+TyzKXZfsRRR0P6USHReZ7g/quSfhYBDlvoj3E2jO0C0ZLS8qMASbGhkWBXGwhwcpZL5clL7EDOdGF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1764252723; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=KSstCQJPiWvJNcD06AhDEsuHKHfRbmwAK0Db6Ne2wX0=; b=a4KBfNDrWLOoSqiOJGWZof+AXqICKtGNkcwtDjwlIzW/1bbJw3NPZfumnJQU4kGz 9F7NwmgCwkmFy8QzSS+Oo4Wj9jg0dr2Z6A9Zee7kMd9+c8Zt+ROiisjYJA82s4T6BBX ahaM0oeuv1nYhUC5ksK3etmdVz3yGLG+O5djbKi8= Received: by mx.zohomail.com with SMTPS id 1764252720374847.4988330897667; Thu, 27 Nov 2025 06:12:00 -0800 (PST) From: Nicolas Frattaroli To: david laight , Linus Torvalds Cc: Rasmus Villemoes , "Yury Norov (NVIDIA)" , Linus Walleij , linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/21] lib: add alternatives for GENMASK() Date: Thu, 27 Nov 2025 15:11:56 +0100 Message-ID: <14092205.uLZWGnKmhe@workhorse> In-Reply-To: References: <20251025164023.308884-1-yury.norov@gmail.com> <20251126221718.6c595c57@pumpkin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" On Thursday, 27 November 2025 00:47:28 Central European Standard Time Linus Torvalds wrote: > On Wed, 26 Nov 2025 at 14:17, david laight wrote: > > > > Mark B. will accuse you of abusing ?: :-) > > Compared to '__is_constexpr()', this is child's play. Not *that* is > abusing the ternary op. > > > I've just looked at a .i file. > > GENMASK() currently expands to 855 chars plus four copies of each argument. > > Yeah, I don't love it. It's a horrid macro. But because of the odd > order of arguments, it needs all that crazy checking. > > That said, I do think it could be simplified. Particularly if we just > make the rule be that GENMASK _has_ to take just constant values. > > Right now, I think 99.9% of all users are constants, and we spend a > lot of effort on the 0.1% that isn't. > > Linus > As a datapoint from my hw_bitfield.h series, all but 3 drivers were trivial to convert to using constant bit masks, which is required by both variants of the FIELD_PREP_WM16* macro. One of the big outliers was the Rockchip clock driver, which needed non-const things all over the place, and wouldn't have been that easy to refactor. Another one worth calling out is phy-rockchip-inno-csidphy.c, where the non-constness of the mask was inherited from a pointer dereference of what is a const value, but the indirection makes it non-const, and I didn't want to have to deal with that 20 patches in without a good way to test it. Entirely possible I was a doofus and didn't try making the pointer itself const as well. Occasionally, masks in code are non-constant for frivolous reasons, like using function arguments as the mask because they're assumed to be always called with one of a set of known values, but that set is never made obvious unless you check all the call sites. The spicier variant of that is masks read from hardware registers or firmware, because at that point you have no view into the possibilities, but I've yet to come across this. I think enforcing GENMASK to take constant values is a good idea in light of that, because people who really need a non-const version should make this explicit so that reviewers can catch it as a potential code smell, in addition to the less horrid preprocessor output. Kind regards, Nicolas Frattaroli