Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4290662ybg; Mon, 8 Jun 2020 04:14:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNv85ZAEiXzAls3m66+UDKCyUBo6N3U2XULf99ml2zL+1kF/vsg7SKasPuQdYFpitnMX38 X-Received: by 2002:a05:6402:6c6:: with SMTP id n6mr20741040edy.277.1591614882537; Mon, 08 Jun 2020 04:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591614882; cv=none; d=google.com; s=arc-20160816; b=qszMbNjX2FURtMg+iMfLRJPsy3i5tKwmzEx/fdSQ+ZS6fL+Ij6TIoptAzVFaSIaMG/ Pbuc6/YcQiZz4W3dPaLHpMiVcvicYtyxvzKTDTsoPmF8rlrjcwJ2AUx5ZArE244IWmjW mIqj1/zSjhGM+7QzMGDPz9qDlX9qLaYKBcslOY6Pn3IhPwbPEMX7muh9CacVzzwkWZun +WHvR2eV4i3wfeZKjc+VTfm1kpIJWgHgkmfYVjQAi5nSGHMp6h9wowCnaeqsEI60wg2D 75nJdGSRg3GsZZkh4XXIUgpHbaQS8eVwRs56GPPuccxOEqI3X18JJE+fSv0v1dGa2bGs FNtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IadYXFhkE9TxetqZC3/Mn8ce5vAmGMwA3+vZQoNchRc=; b=qpN/ru2TCqOeyNU4IJH4G9d+NOCQEtphqq7RbMrReHuRhev/QBIkMkN1dMZGv4vrAw 7yZBl2A9rLEjv5Wa1zfOkVGduN/+FjLNLeyf+E2TcHnQ+pXwctQlg3GMgqejjAUVcHut Cb3WHL3jbcm1kSSWFZxTEjSi18flOfi6tXdzRZEFIXCiOJtvqo8eCr4Dheft3eRLzF5V DVzyvLqsQrlJb3qNXegX88ll8jADF5ap/nteIssancja3ECyMyQxO+tb778NSw5AbM/B oFL7Ghe04TUeixXv7fbzXZzPY286LddB4yaom2xZiwYy5Lnk+t9U9jQt/WkN3tK/tNn/ 2A6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ucj+OEpk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z10si8299093ejb.517.2020.06.08.04.14.20; Mon, 08 Jun 2020 04:14:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ucj+OEpk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729535AbgFHLJz (ORCPT + 99 others); Mon, 8 Jun 2020 07:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729310AbgFHLJx (ORCPT ); Mon, 8 Jun 2020 07:09:53 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0378C08C5C2; Mon, 8 Jun 2020 04:09:52 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id w20so8590322pga.6; Mon, 08 Jun 2020 04:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IadYXFhkE9TxetqZC3/Mn8ce5vAmGMwA3+vZQoNchRc=; b=Ucj+OEpk8pKpWezw+2PhPDIuqj0cQXwJt4VGig+J+TqeCvIe5l6jFi5TGu3PvJeAUe xZKoHvXL3GuFEceB6AcxWRg8y8EUFSZAyOXanxcuebOXosLO6s+yHv63o54sTnj2ILak zs7gO57Fkh7WWfyrAWfBr+nyQvIvV8er5LZJ1J2POMtvBWpfAWS1EDwFG270nhaH7fmc YE+xau657m6clbHxg0uOD7mXWb4SM9detXVNlb+/jPMGAXcvfVdqpe2owqvU3JmpCBFZ uAX7e+ub+fQ2CDaKVLXSgGBuheLIJnlu7v/ima9sZdo5SzEsiyIa/bWwI6k/Cavy/52k BecQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IadYXFhkE9TxetqZC3/Mn8ce5vAmGMwA3+vZQoNchRc=; b=kGvRtTkz9vHu99sfRss7Nf1k6OIwsYqbvUtIlfej7LBgxVCW2fOZ4s+nrOrQMsVdl0 OEjb1jn1alVoU1CzLGq7jA6DAgmCKYjhAN8o4XfsDN8SIMOljW4Hn7nUOo4IrA3gECWJ d24Z+goE4ux2JX3fdZn92Qlu30kcMv8tvSPh+QQ0evTg6iyk1Q0yym7TQdeZrDau5h90 TGw11+2tgc47OsvtP2nCUH74gr5MQa8bH1gM4x7/GbRDNGgi0948gK9PMaTxCh8mX51N FkvruKqa3kZmH/QTjfc9cJzS3BHqxEsRQn25VLHj4wyf62Fd4vlMpYFB77yC6cxw7LsE PhXg== X-Gm-Message-State: AOAM530Ql0Qxql/YfZZtb5m50x9K75KsQNeZnJUFjTguLISU/gLWLAPA XO0Al2S1TEORVkagk9CEKiRyTvVGuvaeMAqy/BA= X-Received: by 2002:a63:305:: with SMTP id 5mr19164999pgd.74.1591614592065; Mon, 08 Jun 2020 04:09:52 -0700 (PDT) MIME-Version: 1.0 References: <20200604233003.GA102768@rikard> <20200607203411.70913-1-rikard.falkeborn@gmail.com> In-Reply-To: <20200607203411.70913-1-rikard.falkeborn@gmail.com> From: Andy Shevchenko Date: Mon, 8 Jun 2020 14:09:40 +0300 Message-ID: Subject: Re: [PATCH v2 1/2] linux/bits.h: fix unsigned less than zero warnings To: Rikard Falkeborn Cc: Andrew Morton , Arnd Bergmann , Emil Velikov , Kees Cook , Linus Walleij , Linux-Arch , Linux Kernel Mailing List , kbuild test robot , Syed Nayyar Waris , William Breathitt Gray , Masahiro Yamada Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 7, 2020 at 11:34 PM Rikard Falkeborn wrote: > > When calling the GENMASK and GENMASK_ULL macros with zero lower bit and > an unsigned unknown high bit, some gcc versions warn due to the > comparisons of the high and low bit in GENMASK_INPUT_CHECK. > > To silence the warnings, only perform the check if both inputs are > known. This does not trigger any warnings, from the Wtype-limits help: > > Warn if a comparison is always true or always false due to the > limited range of the data type, but do not warn for constant > expressions. > > As an example of the warning, kindly reported by the kbuild test robot: > > from drivers/mfd/atmel-smc.c:11: > drivers/mfd/atmel-smc.c: In function 'atmel_smc_cs_encode_ncycles': > include/linux/bits.h:26:28: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] > 26 | __builtin_constant_p((l) > (h)), (l) > (h), 0))) > | ^ > include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO' > 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) > | ^ > include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' > 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) > | ^~~~~~~~~~~~~~~~~~~ > >> drivers/mfd/atmel-smc.c:49:25: note: in expansion of macro 'GENMASK' > 49 | unsigned int lsbmask = GENMASK(msbpos - 1, 0); > | ^~~~~~~ It's much better, than previous variant, thanks! FWIW, Reviewed-by: Andy Shevchenko > Fixes: 295bcca84916 ("linux/bits.h: add compile time sanity check of GENMASK inputs") > Reported-by: kbuild test robot > Reported-by: Emil Velikov > Reported-by: Syed Nayyar Waris > Signed-off-by: Rikard Falkeborn > --- > v1->v2 > * Change to require both high and low bit to be constant expressions > instead of introducing somewhat arbitrary casts > > include/linux/bits.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/bits.h b/include/linux/bits.h > index 4671fbf28842..35ca3f5d11a0 100644 > --- a/include/linux/bits.h > +++ b/include/linux/bits.h > @@ -23,7 +23,8 @@ > #include > #define GENMASK_INPUT_CHECK(h, l) \ > (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > - __builtin_constant_p((l) > (h)), (l) > (h), 0))) > + __builtin_constant_p(l) && __builtin_constant_p(h), \ > + (l) > (h), 0))) > #else > /* > * BUILD_BUG_ON_ZERO is not available in h files included from asm files, > -- > 2.27.0 > -- With Best Regards, Andy Shevchenko