From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbbIODqh (ORCPT ); Mon, 14 Sep 2015 23:46:37 -0400 Received: from mail-qk0-f180.google.com ([209.85.220.180]:32831 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752010AbbIODqg (ORCPT ); Mon, 14 Sep 2015 23:46:36 -0400 Date: Mon, 14 Sep 2015 23:46:32 -0400 From: Tejun Heo To: John Stultz Cc: 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: <20150915034632.GB25658@htj.duckdns.org> References: <1442279124-7309-1-git-send-email-john.stultz@linaro.org> <20150915014936.GA25658@htj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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); u8 and u16 being treated differently from u32 and u64 makes sense too because u6 and u16 are always casted to unsigned for calculations anyway. Maintaining the current behavior and combining the two isn't difficult tho. Sth like the following could work. #define abs(x) \ ({ \ typeof(x) __ret; \ if (sizeof(x) <= sizeof(s32)) { \ s32 __x = (x); \ __ret = __x < 0 ? -__x : __x; \ } else { \ s64 __x = (x); \ __ret = __x < 0 ? -__x : __x; \ } __ret; }) It might trigger some printf format warnings due to the change in return type but I think the end results would be the same as the combination of the current abs() and abs64(). Anyways, let's please get abs() working for all types, one way or the other. Thanks. -- tejun