From patchwork Tue Sep 15 01:05:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53611 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 87DF622B17 for ; Tue, 15 Sep 2015 01:05:47 +0000 (UTC) Received: by lbot4 with SMTP id t4sf2435565lbo.0 for ; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=jgNi6Aa87BlOUgqYFEgNSQbQPsRwkTi0A1Oje3OTZdk=; b=IADe69PFHysuDi5lMgn84J2fAC3uX4mVxTyT1h9AZ+B22puE7I5xPtIinWaK49DdfK wP3QXnR5Wa/Ig/bQTkir6bBWZwlo348kIiKwXntI5sc2FDeBGUVp7RQ1/uFSQMpWvS80 XBgeGwwJcgPrCFvpSTFPhiuX5RZlrjG8ziExiyITz8zxBIrnu5Cbmj0JhQEetySvsYnO QBsRdZHlKL43WjKlDUOM1UNdkYO7Vwg4mcnqFY+uq+eZp6rrdy+AD4YPIHcMUIlkJyid REpMY9MNcAaoWHDXMkoQPLiF4pm1BfXeHtTA6DEMqjkivrs/+56q/kEvwQl7N15fghfa sWNQ== X-Gm-Message-State: ALoCoQnjWPRMhBtK6svZ5mAqzeZA3qkURcQo9VMbfw2ZJYeIXCsBIMbtXhFHhj4luVAYurXwl6JD X-Received: by 10.112.78.101 with SMTP id a5mr3735274lbx.9.1442279146480; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.245.140 with SMTP id xo12ls625250lac.73.gmail; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) X-Received: by 10.152.21.74 with SMTP id t10mr399773lae.107.1442279146331; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id q10si502648lbb.150.2015.09.14.18.05.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 18:05:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lagj9 with SMTP id j9so98747467lag.2 for ; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) X-Received: by 10.112.125.134 with SMTP id mq6mr17522140lbb.19.1442279146214; Mon, 14 Sep 2015 18:05:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1489239lbq; Mon, 14 Sep 2015 18:05:45 -0700 (PDT) X-Received: by 10.107.136.88 with SMTP id k85mr27874367iod.135.1442279138392; Mon, 14 Sep 2015 18:05:38 -0700 (PDT) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com. [209.85.220.53]) by mx.google.com with ESMTPS id qw9si27249573pbc.223.2015.09.14.18.05.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 18:05:38 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.53 as permitted sender) client-ip=209.85.220.53; Received: by pacfv12 with SMTP id fv12so162047485pac.2 for ; Mon, 14 Sep 2015 18:05:37 -0700 (PDT) X-Received: by 10.66.190.135 with SMTP id gq7mr41138115pac.65.1442279137443; Mon, 14 Sep 2015 18:05:37 -0700 (PDT) Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by smtp.gmail.com with ESMTPSA id td5sm18441531pbc.67.2015.09.14.18.05.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Sep 2015 18:05:36 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , Andrew Morton , Ingo Molnar , "Steven Rostedt (Red Hat)" , Peter Zijlstra , Masami Hiramatsu , Michal Nazarewicz Subject: [RFC][PATCH 5/5] abs(): Provide build error on passing 64bit value to abs() Date: Mon, 14 Sep 2015 18:05:24 -0700 Message-Id: <1442279124-7309-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442279124-7309-1-git-send-email-john.stultz@linaro.org> References: <1442279124-7309-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , As noted in the comment above abs(): "abs() should not be used for 64-bit types (s64, u64, long long) - use abs64() for those." Unfortunately, its quite easy to pass 64-bit values to abs() accidentally, and the compiler provides no warning when the returned value is erroniously capped at 32-bits. So this patch tries to make it easier to detect when 64-bit values are passed to abs() by generating a build error. Obviously, since this causes build errors, this patch is last in the series, and I tried to fix up all of the issues I ran into in my build testing. But there are likely still some out there. Cc: Andrew Morton Cc: Ingo Molnar Cc: "Steven Rostedt (Red Hat)" Cc: Peter Zijlstra Cc: Masami Hiramatsu Cc: Michal Nazarewicz Signed-off-by: John Stultz Tested-by: John Stultz --- include/linux/kernel.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5582410..6f01151 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -208,6 +208,9 @@ extern int _cond_resched(void); */ #define abs(x) ({ \ long ret; \ + compiletime_assert( \ + !(sizeof(typeof(x)) > sizeof(long)), \ + "abs() should not be used for 64-bit types - use abs64()");\ if (sizeof(x) == sizeof(long)) { \ long __x = (x); \ ret = (__x < 0) ? -__x : __x; \