From patchwork Tue May 19 21:14:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 11558817 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E13C912 for ; Tue, 19 May 2020 21:17:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CA2820758 for ; Tue, 19 May 2020 21:17:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tgjdqjgk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CA2820758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DBA16E091; Tue, 19 May 2020 21:17:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 625256E091 for ; Tue, 19 May 2020 21:17:45 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id n18so751329wmj.5 for ; Tue, 19 May 2020 14:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UrBghAL5CPtw/Nggrgh37CwRoMhdgtGcnzOBXGkN41E=; b=TgjdqjgkUPa75MEFE4xAFZFGv1E1DgFAC1F82WUpDVPTO7iKyR5qdX/dQ3dxhgXBZj LCrQzmmhWU+8qSfEzR3npbQM/arN2gLGFLlhLFRau8KjsmGrQxFizIthZys91trAvB52 ssnpc5dPKoJeMGh+KRsxIFBQ/M+r5tFmF6qTpqtG/tO0kWjQP/tKTgzHOncPEWuuA4+D ggHEXQzDebpEh8Z9pXVmJFK+ez59x0jBI8hwGsrEi1CMkdNaGgC8uhJOh3BkStUqPitK DJfRa7Rk0qlN7hhfhTf0hRhsT2h3FFMyzVNMgMDQH3aMtlDgaPTjpGOdo9XnIKLhh1dN wA0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UrBghAL5CPtw/Nggrgh37CwRoMhdgtGcnzOBXGkN41E=; b=mNQfsbwqRefS2XGoNYBFyvzYa0WohWyj7SzkxzP4M1lVe1ItjcrLbmlxG5pIqZHSVD VRAh5pz2lCPPMjQQjtxpN1UjYj1RAo5A695cCq3fR5QPjOz+RME1aB/u0WeYtIbbjrdU iddeUbnlNQhLmQxRbIlSqO/Vwa4KR/wabY8d31IdMtlDNezAD/D5EqUNnJK73x0koiG6 2LTyQ4ItBNdh3ghJZM8SzqcX6uU8BeemP34maZoeC6sdiNKDp9HCiYKf9jWJQiYq8rS2 j8eNS5QE8WO5d+zSvkPQEY2g2dJeb1jKmabLPgh47pUG5nn3wehda+QV/BNjbsVkx2pB OtNg== X-Gm-Message-State: AOAM533TCyVPBD2jqvsvVgkfVv6FfMAN84TEA1FM9m4qxjHhVCWpxRG8 jqsOrtwDVxacAAxU6OqkzTjQ/RU6 X-Google-Smtp-Source: ABdhPJzNoq+nTV4mzeUKHdB6/aKVEe21pblSTqDQWAVzZ699ciNkqr7KBNv5A61nhuwdTK5d80UkiQ== X-Received: by 2002:a1c:2bc1:: with SMTP id r184mr1360259wmr.58.1589923063698; Tue, 19 May 2020 14:17:43 -0700 (PDT) Received: from localhost.localdomain (cpc91192-cmbg18-2-0-cust374.5-4.cable.virginm.net. [80.6.113.119]) by smtp.gmail.com with ESMTPSA id z9sm710425wrp.66.2020.05.19.14.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 14:17:42 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] linux/bits.h: adjust GENMASK_INPUT_CHECK() check Date: Tue, 19 May 2020 22:14:52 +0100 Message-Id: <20200519211452.422179-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200519101320.33495-1-emil.l.velikov@gmail.com> References: <20200519101320.33495-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Torvalds , emil.l.velikov@gmail.com, Rikard Falkeborn , Chris Wilson Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases where there GENMASK arguments are flipped. Although it seems to be triggering -Wtype-limits in the following cases: unsigned foo = (10 + x); unsigned bar = GENMASK(foo, 0); const unsigned foo = (10 + x); unsigned bar = GENMASK(foo, 0); Here are the warnings, from my GCC 9.2 box. warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] __builtin_constant_p((l) > (h)), (l) > (h), 0))) ^ warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] __builtin_constant_p((l) > (h)), (l) > (h), 0))) ^ This results in people disabling the warning all together or promoting foo to signed. Either of which being a sub par option IMHO. Add a trivial "+ 1" to each h and l in the constant expression. v2: drop accidental ! Fixes: 295bcca84916 ("linux/bits.h: add compile time sanity check of GENMASK inputs") Cc: Rikard Falkeborn Cc: Linus Torvalds Cc: Chris Wilson Cc: dri-devel@lists.freedesktop.org Signed-off-by: Emil Velikov Reported-by: kbuild test robot Reported-by: kbuild test robot --- include/linux/bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 4671fbf28842..02a42866d198 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -23,7 +23,7 @@ #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 + 1) > (h + 1)), (l + 1) > (h + 1), 0))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files,