alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel@vger.kernel.org, Liam Girdwood <lrg@ti.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	alsa-devel@alsa-project.org,
	Peter Hsiang <peter.hsiang@maxim-ic.com>,
	Jesse Marroquin <jesse.marroquin@maxim-ic.com>
Subject: Re: [PATCH 1/2] ASoC: Add BUG() assertion if max98088_get_channel returns -EINVAL
Date: Thu, 29 Sep 2011 09:15:03 +1000	[thread overview]
Message-ID: <4E83AA77.9040700@gmail.com> (raw)
In-Reply-To: <1317218471.8008.3.camel@phoenix>

On 29/09/11 00:01, Axel Lin wrote:
> The callers use the return value of max98088_get_channel as array index to
> access max98088->dai[] array.
> Add BUG() assertion for out of bound access of max98088->dai[] array.

BUG() is pretty heavy handed for a driver. Why not fix the problem
properly in the callers?

----
Check the return value of max98088_get_channel in the callers and
propagate any errors up.

Signed-off-by: Ryan Mallon <rmallon@gmail.com>
---

diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index ac65a2d..e07700e 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1811,6 +1811,9 @@ static int max98088_put_eq_enum(struct snd_kcontrol *kcontrol,
        struct max98088_cdata *cdata;
        int sel = ucontrol->value.integer.value[0];
 
+       if (channel < 0)
+	       return channel;
+
        cdata = &max98088->dai[channel];
 
        if (sel >= pdata->eq_cfgcnt)
@@ -1838,6 +1841,9 @@ static int max98088_get_eq_enum(struct snd_kcontrol *kcontrol,
        int channel = max98088_get_channel(kcontrol->id.name);
        struct max98088_cdata *cdata;
 
+       if (channel < 0)
+	       return channel;
+
        cdata = &max98088->dai[channel];
        ucontrol->value.enumerated.item[0] = cdata->eq_sel;
        return 0;

  parent reply	other threads:[~2011-09-28 23:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-28 14:01 [PATCH 1/2] ASoC: Add BUG() assertion if max98088_get_channel returns -EINVAL Axel Lin
2011-09-28 14:02 ` [PATCH 2/2] ASoC: Add BUG() assertion if max98095_get_bq_channel " Axel Lin
2011-09-28 23:19   ` Ryan Mallon
2011-09-29  1:35     ` Dave Young
2011-09-29  1:52       ` Ryan Mallon
2011-09-29  1:59         ` Dave Young
2011-09-29  2:01           ` Ryan Mallon
2011-09-29  2:06             ` Dave Young
2011-09-29  1:33   ` Dave Young
2011-09-28 23:15 ` Ryan Mallon [this message]
2011-09-29 10:34   ` [PATCH 1/2] ASoC: Add BUG() assertion if max98088_get_channel " Mark Brown
2011-09-29 11:28     ` Ryan Mallon
2011-09-29 23:13     ` Ryan Mallon
2011-09-30 12:56       ` 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=4E83AA77.9040700@gmail.com \
    --to=rmallon@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=jesse.marroquin@maxim-ic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=peter.hsiang@maxim-ic.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).