From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.de>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ASoC: soc-dapm: Fix comparison of pointers
Date: Tue, 9 Dec 2014 22:53:41 +0100 [thread overview]
Message-ID: <1418162021-32229-1-git-send-email-linux@rasmusvillemoes.dk> (raw)
The idiom 'return a - b;' often used in comparison functions is wrong
unless one is certain the values being compared lie in a sufficiently
small range. In this case dapm_seq_compare would also return 0 if the
->dapm pointers happened to differ by a multiple of 2^32.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Notes:
I don't know if the other occurences of the idiom in this function are
ok; that depends on whether the values always lie in [0, 2^31-1].
sound/soc/soc-dapm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c61cb9cedbcd..a894a7c71557 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1255,8 +1255,10 @@ static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
}
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;
return 0;
}
--
2.1.3
next reply other threads:[~2014-12-09 21:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-09 21:53 Rasmus Villemoes [this message]
2014-12-12 13:21 ` Mark Brown
2014-12-12 13:43 ` Rasmus Villemoes
2014-12-12 14:17 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1418162021-32229-1-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®