Received: by 10.192.165.156 with SMTP id m28csp620012imm; Tue, 17 Apr 2018 16:37:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx49rh88D6cdfueesVekUJ7nFzzdHR2hkRWrzVccBF0bs1cJmtUW8vaAkkfhI0p+3GXlNSYUQ X-Received: by 2002:a17:902:b2c7:: with SMTP id x7-v6mr3845733plw.124.1524008257299; Tue, 17 Apr 2018 16:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524008257; cv=none; d=google.com; s=arc-20160816; b=xvCRaOi8K7Yiwr0VydpfrMg+DD3wjoKRx52E/KkarIqakEn8BpQwxy6lipDZl8LIaY AaJEH9HYdd6695ca6zpo1TYJ4z/pSZayMbwMz0rCTgfqKrgkYHFc05jbD6fwclKsl4ta /5K8oWB5S+kMLuYxNn0/4A9N+85Dha6vUH5DrVQafbbWFQphUI7A0VUIBZ7dgV650wsE o/zHYcT1YKkeomMxbJ77yd+IVC68xsFVXXe9rekZ0G4KpVRdmXYCoik2KhDJz7t0g6xC 5Ih/1Q2DSiO8uKsV8deu7uBZkjqNE3CFOkuHBS7YpQ0rNkf8nnT34sMT+I5CuY5EHgy4 ivlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=pZwnN3x0mjjE0vvcsa/715g+Zij6jkD7m2W0JNX+UJU=; b=SQx3M+kAxZywiR8ac+ZyNZ1s+d0LxjBzw8n7r5O4eI0SHiVKS0AlBNxHvFifHNF8+X OrXcVkMIGJVrMDNlL5dorWjKqtuKF35zv8b5RsNx5uBPV45aG3mkARdFDluiueiAwBg3 QPtU20+0P7OS2c2bHzmWE3h11JjrzWEjfBsf0X+3NCBdCkaKmMB1Zfcwo5HZPAngXayw oIuGFOevl05ktevqz9uZl61Oy9EWY1TpcewlbZydsMUMI1L0L3hXcHL91vJxMld4Fau1 MtFuSmc4UJx34uiiDk+ucEtyxhJ+7BiO3Zqyinj0sngP69+PdPkHkqLNhCmIUQiA0iV1 KAXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si10203956plp.532.2018.04.17.16.37.23; Tue, 17 Apr 2018 16:37:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753099AbeDQXfx (ORCPT + 99 others); Tue, 17 Apr 2018 19:35:53 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:41446 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752510AbeDQXfw (ORCPT ); Tue, 17 Apr 2018 19:35:52 -0400 Received: from apollon.suse.de.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Tue, 17 Apr 2018 17:35:38 -0600 From: Martin Wilck To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Hannes Reinecke , James Bottomley , Xose Vazquez Perez , Bart Van Assche , Linus Torvalds , Ard Biesheuvel , Thomas Gleixner , Jonathan Corbet , Randy Dunlap Subject: [PATCH v3 1/6] ilog2: create truly constant version for sparse Date: Wed, 18 Apr 2018 01:35:06 +0200 Message-Id: <20180417233511.6573-2-mwilck@suse.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180417233511.6573-1-mwilck@suse.com> References: <20180417233511.6573-1-mwilck@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sparse emits errors about ilog2() in array indices because of the use of __ilog2_32() and __ilog2_64(), rightly so (https://www.spinics.net/lists/linux-sparse/msg03471.html). Create a const_ilog2() variant that works with sparse for this scenario. (Note: checkpatch.pl complains about missing parentheses, but that appears to be a false positive. I can get rid of the warning simply by inserting whitespace, making checkpatch "see" the whole macro). Signed-off-by: Martin Wilck --- include/linux/log2.h | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/include/linux/log2.h b/include/linux/log2.h index 41a1ae0..2af7f778 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -72,16 +72,13 @@ unsigned long __rounddown_pow_of_two(unsigned long n) } /** - * ilog2 - log base 2 of 32-bit or a 64-bit unsigned value + * const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value * @n: parameter * - * constant-capable log of base 2 calculation - * - this can be used to initialise global variables from constant data, hence - * the massive ternary operator construction - * - * selects the appropriately-sized optimised version depending on sizeof(n) + * Use this where sparse expects a true constant expression, e.g. for array + * indices. */ -#define ilog2(n) \ +#define const_ilog2(n) \ ( \ __builtin_constant_p(n) ? ( \ (n) < 2 ? 0 : \ @@ -147,10 +144,26 @@ unsigned long __rounddown_pow_of_two(unsigned long n) (n) & (1ULL << 4) ? 4 : \ (n) & (1ULL << 3) ? 3 : \ (n) & (1ULL << 2) ? 2 : \ - 1 ) : \ - (sizeof(n) <= 4) ? \ - __ilog2_u32(n) : \ - __ilog2_u64(n) \ + 1) : \ + -1) + +/** + * ilog2 - log base 2 of 32-bit or a 64-bit unsigned value + * @n: parameter + * + * constant-capable log of base 2 calculation + * - this can be used to initialise global variables from constant data, hence + * the massive ternary operator construction + * + * selects the appropriately-sized optimised version depending on sizeof(n) + */ +#define ilog2(n) \ +( \ + __builtin_constant_p(n) ? \ + const_ilog2(n) : \ + (sizeof(n) <= 4) ? \ + __ilog2_u32(n) : \ + __ilog2_u64(n) \ ) /** -- 2.16.1