diff mbox

ALSA: dice: fix a bounds check in snd_dice_detect_tcelectronic_formats()

Message ID 20180518091607.GA32078@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter May 18, 2018, 9:16 a.m. UTC
The "entry" pointer is always non-NULL so this test for out of bounds
won't work.

Fixes: f1f0f330b1d0 ("ALSA: dice: add parameters of stream formats for models produced by TC Electronic")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Takashi Sakamoto May 18, 2018, 11:36 a.m. UTC | #1
Hi,

On May 18 2018 18:16, Dan Carpenter wrote:
> The "entry" pointer is always non-NULL so this test for out of bounds
> won't work.
> 
> Fixes: f1f0f330b1d0 ("ALSA: dice: add parameters of stream formats for models produced by TC Electronic")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/sound/firewire/dice/dice-tcelectronic.c b/sound/firewire/dice/dice-tcelectronic.c
> index af8203b9d1a6..e134a5110c6c 100644
> --- a/sound/firewire/dice/dice-tcelectronic.c
> +++ b/sound/firewire/dice/dice-tcelectronic.c
> @@ -75,13 +75,12 @@ int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice)
>   		}
>   	}
>   
> -	entry = NULL;
>   	for (i = 0; i < ARRAY_SIZE(entries); ++i) {
>   		entry = entries + i;
>   		if (entry->model_id == model_id)
>   			break;
>   	}
> -	if (!entry)
> +	if (i == ARRAY_SIZE(entries))
>   		return -ENODEV;
>   
>   	memcpy(dice->tx_pcm_chs, entry->spec->tx_pcm_chs,

Oops, indeed.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>


Thanks

Takashi Sakamoto
Takashi Iwai May 18, 2018, 11:39 a.m. UTC | #2
On Fri, 18 May 2018 11:16:07 +0200,
Dan Carpenter wrote:
> 
> The "entry" pointer is always non-NULL so this test for out of bounds
> won't work.
> 
> Fixes: f1f0f330b1d0 ("ALSA: dice: add parameters of stream formats for models produced by TC Electronic")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied, thanks.


Takashi
diff mbox

Patch

diff --git a/sound/firewire/dice/dice-tcelectronic.c b/sound/firewire/dice/dice-tcelectronic.c
index af8203b9d1a6..e134a5110c6c 100644
--- a/sound/firewire/dice/dice-tcelectronic.c
+++ b/sound/firewire/dice/dice-tcelectronic.c
@@ -75,13 +75,12 @@  int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice)
 		}
 	}
 
-	entry = NULL;
 	for (i = 0; i < ARRAY_SIZE(entries); ++i) {
 		entry = entries + i;
 		if (entry->model_id == model_id)
 			break;
 	}
-	if (!entry)
+	if (i == ARRAY_SIZE(entries))
 		return -ENODEV;
 
 	memcpy(dice->tx_pcm_chs, entry->spec->tx_pcm_chs,