Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp249998ybi; Wed, 29 May 2019 20:38:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWzzZMvdPqIMnS/CBe8Szme5aEW96etkiDfpPtxXk58x5HFJRbs65sciGHImYUC7fl6ywS X-Received: by 2002:a17:902:aa85:: with SMTP id d5mr1694767plr.245.1559187511840; Wed, 29 May 2019 20:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559187511; cv=none; d=google.com; s=arc-20160816; b=JVL3JwyFXMavPjKgdACNctivgureQRE9cNm8MDZ3FfmvN2f6Zao5OBGevANGFA9IMe v8pNP9jMIeJv/mR9CHPckPERKGIvlhIsySas/LLhMG0oL3ZIUufwrtAd9yXhRuAkkJOY y2GJ8REYFuB0TD9N+PV2RRCGo9zbx4n/95NjEPW3dXZ9r9dPgd/WgyE8ASyvEvyzILfy IiARIEuj6LGL6bSrZVub7oIju5zgWsq1+y0riSVHwNqEho8tPk/QvjCkABygQ6r4AC5f ZiOF9/URCf60lxgispQG25c4/a4sgZzi7KAcdNP8JnVQbutP+M7GeopgrjPkGlmOtl2N 3kIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iTR3x1cAve9dRcTzxMxlsou3kqF9rrc0jpSTvmFrp34=; b=HTSIVqZnEhnHfp+0cVQ/9hOYeni1CEy/vn49XoFVFJJo6Jh8g4Y7Q+QRu/qhIk6TsL NQ/iI+R9aqVxs8K3b85Or9tAK97OZ3kt/yfWEFrAAdbMDXr9hCVNzRfTSYxZ4QYYkXVj os1zecoKRVQPc4QZWettEh/hIit3YjXC1bS6oSluVu0nYCW29ssUsSYtqTA2RvLcPJ1e KZAz3Z/xg+K54qqlPz2HIDraDRWYb+JEeLNWQt5HFbH6UY9mWGRqTih9TtuKB8PYWad8 FQWCBBbcAcgzvcshL4gsA4cvRvXOyUj80k7L7MwbYf7wnASZ6Vk5aQ4u/EK5vLio9vdA ktIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rg9YKHun; 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 d12si2107685pla.121.2019.05.29.20.38.15; Wed, 29 May 2019 20:38:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b=rg9YKHun; 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 S2387528AbfE3DZX (ORCPT + 99 others); Wed, 29 May 2019 23:25:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:51226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730078AbfE3DS0 (ORCPT ); Wed, 29 May 2019 23:18:26 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3C5C247C2; Thu, 30 May 2019 03:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186305; bh=i1++ugkGFy9cTN8Pw+YwfRoCFDrSB4l8XHeSdcQnPQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rg9YKHunu036IWBb0qgJSb3zg2aiOJDghrSQot/TXAaD0tg0PgPgvGQ+6zf4puISp 94ZanE0aJ38vUc//g4bI8d5dcFJqH9bZBIksG0rqMqfl6hNDB5wyECbhwC8YLghH6J CyAv51R84fEShfsPhuGkMc7unf5sKM+mf4WvpHR0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Kees Cook , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.19 230/276] overflow: Fix -Wtype-limits compilation warnings Date: Wed, 29 May 2019 20:06:28 -0700 Message-Id: <20190530030539.509570163@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit dc7fe518b0493faa0af0568d6d8c2a33c00f58d0 ] Attempt to use check_shl_overflow() with inputs of unsigned type produces the following compilation warnings. drivers/infiniband/hw/mlx5/qp.c: In function _set_user_rq_size_: ./include/linux/overflow.h:230:6: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits] _s >= 0 && _s < 8 * sizeof(*d) ? _s : 0; \ ^~ drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) ^~~~~~~~~~~~~~~~~~ ./include/linux/overflow.h:232:26: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] (_to_shift != _s || *_d < 0 || _a < 0 || \ ^ drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) ^~~~~~~~~~~~~~~~~~ ./include/linux/overflow.h:232:36: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] (_to_shift != _s || *_d < 0 || _a < 0 || \ ^ drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift,&rwq->buf_size)) ^~~~~~~~~~~~~~~~~~ Fixes: 0c66847793d1 ("overflow.h: Add arithmetic shift helper") Reviewed-by: Bart Van Assche Acked-by: Kees Cook Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- include/linux/overflow.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index 40b48e2133cb8..15eb85de92269 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -36,6 +36,12 @@ #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) #define type_min(T) ((T)((T)-type_max(T)-(T)1)) +/* + * Avoids triggering -Wtype-limits compilation warning, + * while using unsigned data types to check a < 0. + */ +#define is_non_negative(a) ((a) > 0 || (a) == 0) +#define is_negative(a) (!(is_non_negative(a))) #ifdef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW /* @@ -227,10 +233,10 @@ typeof(d) _d = d; \ u64 _a_full = _a; \ unsigned int _to_shift = \ - _s >= 0 && _s < 8 * sizeof(*d) ? _s : 0; \ + is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0; \ *_d = (_a_full << _to_shift); \ - (_to_shift != _s || *_d < 0 || _a < 0 || \ - (*_d >> _to_shift) != _a); \ + (_to_shift != _s || is_negative(*_d) || is_negative(_a) || \ + (*_d >> _to_shift) != _a); \ }) /** -- 2.20.1