Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752357AbcLESXH (ORCPT ); Mon, 5 Dec 2016 13:23:07 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:34097 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751592AbcLESXF (ORCPT ); Mon, 5 Dec 2016 13:23:05 -0500 MIME-Version: 1.0 In-Reply-To: <93523b80-6033-bafa-c1ec-4bc2c3f9c53b@laposte.net> References: <93523b80-6033-bafa-c1ec-4bc2c3f9c53b@laposte.net> From: Linus Torvalds Date: Mon, 5 Dec 2016 10:23:04 -0800 X-Google-Sender-Auth: gyk9L6BItWKdN0EIeYBRh7dEU1I Message-ID: Subject: Re: [PATCH v2] add equivalent of BIT(x) for bitfields To: Sebastian Frias Cc: zijun_hu , Andrew Morton , Linux Kernel Mailing List , Mason , Harvey Harrison , Borislav Petkov Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 612 Lines: 15 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), but please add actual checking. You can use BUILD_BUG_ON_ZERO(!__builtin_constant_p(x)) or something. That returns zero, so it's easy to use in expressions. Linus