Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753022AbcLFKfX (ORCPT ); Tue, 6 Dec 2016 05:35:23 -0500 Received: from smtpoutz300.laposte.net ([178.22.154.200]:36379 "EHLO smtp.laposte.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751335AbcLFKfV (ORCPT ); Tue, 6 Dec 2016 05:35:21 -0500 Subject: Re: [PATCH v2] add equivalent of BIT(x) for bitfields To: Linus Torvalds References: <93523b80-6033-bafa-c1ec-4bc2c3f9c53b@laposte.net> Cc: zijun_hu , Andrew Morton , Linux Kernel Mailing List , Mason , Harvey Harrison , Borislav Petkov From: Sebastian Frias Message-ID: <9d74aaf8-a328-a3a6-dcaa-9ade95538241@laposte.net> Date: Tue, 6 Dec 2016 11:10:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-VR-SrcIP: 92.154.11.170 X-VR-FullState: 0 X-VR-Score: -100 X-VR-Cause-1: gggruggvucftvghtrhhoucdtuddrfeelfedrhedtgddtvdcutefuodetggdotefrodftvfcurfhrohhf X-VR-Cause-2: ihhlvgemucfntefrqffuvffgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhs X-VR-Cause-3: ucdlqddutddtmdenucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpefu X-VR-Cause-4: vggsrghsthhirghnucfhrhhirghsuceoshhfkeegsehlrghpohhsthgvrdhnvghtqeenucfkphepledv X-VR-Cause-5: rdduheegrdduuddrudejtdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopegludej X-VR-Cause-6: vddrvdejrddtrddvudegngdpihhnvghtpeelvddrudehgedruddurddujedtpdhmrghilhhfrhhomhep X-VR-Cause-7: shhfkeegsehlrghpohhsthgvrdhnvghtpdhrtghpthhtohepthhorhhvrghlughssehlihhnuhigqdhf X-VR-Cause-8: ohhunhgurghtihhonhdrohhrgh X-VR-AvState: No X-VR-State: 0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 785 Lines: 27 On 05/12/16 19:23, Linus Torvalds wrote: > On Mon, Dec 5, 2016 at 9:49 AM, Sebastian Frias wrote: >> Introduce GENVALUE(msb, lsb, value) macro to ease dealing with >> continuous bitfields, just as BIT(x) does for single bits. > > Oh, and looking at the implementation, this is wrong. You use "lsb" > twice, so it mustn't have side effects. > > That's fine for all expected users (since you'd expect that the only > real use of this is with constant values for msb/lsb), Yes, that's what I thought. >but please add > actual checking. Sure! Thanks for the advice. > > You can use BUILD_BUG_ON_ZERO(!__builtin_constant_p(x)) or something. > That returns zero, so it's easy to use in expressions. Done. v3 of the patch is submitted. > > Linus >