All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Takashi Iwai <tiwai@suse.de>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org
Subject: [patch v2] [ALSA] hwdep: silence integer overflow warning
Date: Fri, 28 Oct 2011 09:46:01 +0300	[thread overview]
Message-ID: <20111028064601.GB14707@longonot.mountain> (raw)
In-Reply-To: <4E9FD02B.6030307@bfs.de>

Smatch complains that if device is INT_MAX then device + 1 can
overflow.  It just means we would have an annoying loop while we
check all the devices from -2147483648 to SNDRV_MINOR_HWDEPS.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: reshuffled it a bit per Walter Harms's suggestion.

diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index c7ceb28..75ea16f 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -273,7 +273,14 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
 			if (get_user(device, (int __user *)arg))
 				return -EFAULT;
 			mutex_lock(&register_mutex);
-			device = device < 0 ? 0 : device + 1;
+
+			if (device < 0)
+				device = 0;
+			else if (device < SNDRV_MINOR_HWDEPS)
+				device++;
+			else
+				device = SNDRV_MINOR_HWDEPS;
+
 			while (device < SNDRV_MINOR_HWDEPS) {
 				if (snd_hwdep_search(card, device))
 					break;

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Takashi Iwai <tiwai@suse.de>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org
Subject: [patch v2] [ALSA] hwdep: silence integer overflow warning
Date: Fri, 28 Oct 2011 06:46:01 +0000	[thread overview]
Message-ID: <20111028064601.GB14707@longonot.mountain> (raw)
In-Reply-To: <4E9FD02B.6030307@bfs.de>

Smatch complains that if device is INT_MAX then device + 1 can
overflow.  It just means we would have an annoying loop while we
check all the devices from -2147483648 to SNDRV_MINOR_HWDEPS.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: reshuffled it a bit per Walter Harms's suggestion.

diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index c7ceb28..75ea16f 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -273,7 +273,14 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
 			if (get_user(device, (int __user *)arg))
 				return -EFAULT;
 			mutex_lock(&register_mutex);
-			device = device < 0 ? 0 : device + 1;
+
+			if (device < 0)
+				device = 0;
+			else if (device < SNDRV_MINOR_HWDEPS)
+				device++;
+			else
+				device = SNDRV_MINOR_HWDEPS;
+
 			while (device < SNDRV_MINOR_HWDEPS) {
 				if (snd_hwdep_search(card, device))
 					break;


  parent reply	other threads:[~2011-10-28  6:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-20  6:09 [patch] [ALSA] hwdep: silence integer overflow warning Dan Carpenter
2011-10-20  6:09 ` Dan Carpenter
2011-10-20  7:39 ` walter harms
2011-10-28  6:45   ` Dan Carpenter
2011-10-28  6:45     ` Dan Carpenter
2011-10-28  7:33     ` walter harms
2011-10-28  7:33       ` walter harms
2011-10-28  8:55       ` Dan Carpenter
2011-10-28  8:55         ` Dan Carpenter
2011-10-28  6:46   ` Dan Carpenter [this message]
2011-10-28  6:46     ` [patch v2] " Dan Carpenter
2011-10-31  8:55     ` Takashi Iwai
2011-10-31  8:55       ` [alsa-devel] " 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=20111028064601.GB14707@longonot.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=tiwai@suse.de \
    --cc=wharms@bfs.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 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.