[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 12 Dec 2014 14:43:27 +0100
From: Rasmus Villemoes <linux@...musvillemoes.dk>
To: Mark Brown <broonie@...nel.org>
Cc: Takashi Iwai <tiwai@...e.de>, alsa-devel@...a-project.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ASoC: soc-dapm: Fix comparison of pointers
On Fri, Dec 12 2014, Mark Brown <broonie@...nel.org> wrote:
> On Tue, Dec 09, 2014 at 10:53:41PM +0100, Rasmus Villemoes wrote:
>
>> if (a->reg != b->reg)
>> return a->reg - b->reg;
>> - if (a->dapm != b->dapm)
>> - return (unsigned long)a->dapm - (unsigned long)b->dapm;
>> + if (a->dapm < b->dapm)
>> + return -1;
>> + if (a->dapm > b->dapm)
>> + return 1;
>
> If we're worrying about standards conformance type stuff here this is
> also buggy since it's out of spec to compare pointers that are not part
> of the same array like this. Casting to uintptr_t is a better fix here.
I'm not worrying about standards conformance. Casting pointers to and
from [unsigned] long is done everywhere in the kernel, and that's
fine. But subtracting ints or longs and using the sign of the result for
comparison is simply wrong. See acbbe6fbb2 (kcmp: fix standard
comparison bug) for the long story. In this case the narrowing (when
BITS_PER_LONG==64) of the result from long to int just makes it even
more wrong.
Rasmus
--
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