From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [patch] ALSA: emu10k1: shift wrapping bug in snd_emu10k1_ptr_read()
Date: Thu, 24 Nov 2016 14:23:33 +0300 [thread overview]
Message-ID: <20161124112333.GL17225@mwanda> (raw)
Static analysis says "size" is a number 0-63. So we really want to be
doing the shift as a u64 and not a int type. Presumably "size" is never
actually more than 31 otherwise the shift wrap would have been detected
in testing. The "mask" is a u32 so we only care about the bottom 32
bits which also implies that "size" is less than 32.
This code pre-dates git. I haven't tested this change, it's to fix a
static analysis warning. I can't think that shift wrapping is the
correct behavior so presumably this change is harmless but it definitely
changes how the code works when size is larger than 32.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index 706b4f0..fd204f3 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -46,7 +46,7 @@ unsigned int snd_emu10k1_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, un
size = (reg >> 24) & 0x3f;
offset = (reg >> 16) & 0x1f;
- mask = ((1 << size) - 1) << offset;
+ mask = ((1ULL << size) - 1) << offset;
spin_lock_irqsave(&emu->emu_lock, flags);
outl(regptr, emu->port + PTR);
@@ -81,7 +81,7 @@ void snd_emu10k1_ptr_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned i
size = (reg >> 24) & 0x3f;
offset = (reg >> 16) & 0x1f;
- mask = ((1 << size) - 1) << offset;
+ mask = ((1ULL << size) - 1) << offset;
data = (data << offset) & mask;
spin_lock_irqsave(&emu->emu_lock, flags);
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [patch] ALSA: emu10k1: shift wrapping bug in snd_emu10k1_ptr_read()
Date: Thu, 24 Nov 2016 11:23:33 +0000 [thread overview]
Message-ID: <20161124112333.GL17225@mwanda> (raw)
Static analysis says "size" is a number 0-63. So we really want to be
doing the shift as a u64 and not a int type. Presumably "size" is never
actually more than 31 otherwise the shift wrap would have been detected
in testing. The "mask" is a u32 so we only care about the bottom 32
bits which also implies that "size" is less than 32.
This code pre-dates git. I haven't tested this change, it's to fix a
static analysis warning. I can't think that shift wrapping is the
correct behavior so presumably this change is harmless but it definitely
changes how the code works when size is larger than 32.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index 706b4f0..fd204f3 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -46,7 +46,7 @@ unsigned int snd_emu10k1_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, un
size = (reg >> 24) & 0x3f;
offset = (reg >> 16) & 0x1f;
- mask = ((1 << size) - 1) << offset;
+ mask = ((1ULL << size) - 1) << offset;
spin_lock_irqsave(&emu->emu_lock, flags);
outl(regptr, emu->port + PTR);
@@ -81,7 +81,7 @@ void snd_emu10k1_ptr_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned i
size = (reg >> 24) & 0x3f;
offset = (reg >> 16) & 0x1f;
- mask = ((1 << size) - 1) << offset;
+ mask = ((1ULL << size) - 1) << offset;
data = (data << offset) & mask;
spin_lock_irqsave(&emu->emu_lock, flags);
next reply other threads:[~2016-11-24 11:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-24 11:23 Dan Carpenter [this message]
2016-11-24 11:23 ` [patch] ALSA: emu10k1: shift wrapping bug in snd_emu10k1_ptr_read() Dan Carpenter
2016-11-24 13:24 ` Takashi Iwai
2016-11-24 13:24 ` Takashi Iwai
2016-11-24 13:24 ` Takashi Iwai
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=20161124112333.GL17225@mwanda \
--to=dan.carpenter@oracle.com \
--cc=alsa-devel@alsa-project.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.