From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752809AbbIOMsT (ORCPT ); Tue, 15 Sep 2015 08:48:19 -0400 Received: from zaphod.unpythonic.net ([76.79.27.186]:57487 "EHLO zaphod.unpythonic.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752744AbbIOMsR (ORCPT ); Tue, 15 Sep 2015 08:48:17 -0400 X-Greylist: delayed 2296 seconds by postgrey-1.27 at vger.kernel.org; Tue, 15 Sep 2015 08:48:17 EDT Date: Tue, 15 Sep 2015 07:09:42 -0500 From: Jeff Epler To: Tejun Heo Cc: John Stultz , LKML , Andrew Morton , Ingo Molnar , "Steven Rostedt (Red Hat)" , Peter Zijlstra , Masami Hiramatsu , Michal Nazarewicz , Prarit Bhargava , Richard Cochran , Thomas Gleixner , "Theodore Ts'o" , Andreas Dilger , Dave Chinner , Joe Perches Subject: Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Message-ID: <20150915120941.GA81750@unpythonic.net> References: <1442279124-7309-1-git-send-email-john.stultz@linaro.org> <20150915014936.GA25658@htj.duckdns.org> <20150915034632.GB25658@htj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150915034632.GB25658@htj.duckdns.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 14, 2015 at 11:46:32PM -0400, Tejun Heo wrote: > Hello, > > On Mon, Sep 14, 2015 at 08:27:08PM -0700, John Stultz wrote: > > Yea. The above make sense to me, but I suspect there's some very > > subtle reason for the existing separated logic. > > But I'd have to defer to akpm for hints on that. > > Hmmm... people could be using it for calculating the distance between > two unsigned values and in that case the original behavior would be > the correct one. e.g. > > unsigned diff, a, b; > diff = abs(a - b); This kind of construct can overflow whether a and b are signed or unsigned. Only a two-argument function can correctly return the absolute difference of two integers. At my day job, we arranged for abs(unsigned type) to be a compile-time error and supplied a two args function absdiff for use in these situations -- absdiff(a,b) is the same as abs(a-b) except it avoids overflow and returns an unsigned type. (though I have no doubt that some instances of abs(a - b) still exist where a and b are signed and the intermediate could still overflow...) Jeff