[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150915034632.GB25658@htj.duckdns.org>
Date: Mon, 14 Sep 2015 23:46:32 -0400
From: Tejun Heo <tj@...nel.org>
To: John Stultz <john.stultz@...aro.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Ingo Molnar <mingo@...nel.org>,
"Steven Rostedt (Red Hat)" <rostedt@...dmis.org>,
Peter Zijlstra <peterz@...radead.org>,
Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
Michal Nazarewicz <mina86@...a86.com>,
Prarit Bhargava <prarit@...hat.com>,
Richard Cochran <richardcochran@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Theodore Ts'o <tytso@....edu>,
Andreas Dilger <adilger.kernel@...ger.ca>,
Dave Chinner <dchinner@...hat.com>,
Joe Perches <joe@...ches.com>
Subject: Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists