From: Ryan Mallon <rmallon@gmail.com>
To: Dave Young <hidave.darkstar@gmail.com>
Cc: Axel Lin <axel.lin@gmail.com>,
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 2/2] ASoC: Add BUG() assertion if max98095_get_bq_channel returns -EINVAL
Date: Thu, 29 Sep 2011 12:01:06 +1000 [thread overview]
Message-ID: <4E83D162.2010004@gmail.com> (raw)
In-Reply-To: <CABqxG0eWVMTBAF=Tq_a0USEXFeVYGpR7kRGRTCpUrrfP+0AGmw@mail.gmail.com>
On 29/09/11 11:59, Dave Young wrote:
> On Thu, Sep 29, 2011 at 9:52 AM, Ryan Mallon <rmallon@gmail.com> wrote:
>> On 29/09/11 11:35, Dave Young wrote:
>>
>>> On Thu, Sep 29, 2011 at 7:19 AM, Ryan Mallon <rmallon@gmail.com> wrote:
>>>> On 29/09/11 00:02, Axel Lin wrote:
>>>>> The callers use the return value of max98095_get_bq_channel as array index to
>>>>> access max98095->dai[] array.
>>>>> Add BUG() assertion for out of bound access of max98095->dai[] array.
>>>>
>>>> Same here, fix the problem in the callers.
>>>>
>>>> ----
>>>> Check the return value of max98095_get_bq_channel in the callers and
>>>> propagate any errors up. Remove the BUG_ON(channel > 1) since
>>>> max98095_get_bq_channel never returns a value larger than 1.
>>>>
>>>> Signed-off-by: Ryan Mallon <rmallon@gmail.com>
>>>> ---
>>>>
>>>> diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
>>>> index 668434d..55eccea 100644
>>>> --- a/sound/soc/codecs/max98095.c
>>>> +++ b/sound/soc/codecs/max98095.c
>>>> @@ -2014,7 +2014,8 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
>>>> int fs, best, best_val, i;
>>>> int regmask, regsave;
>>>>
>>>> - BUG_ON(channel > 1);
>>>> + if (channel < 0)
>>>> + return channel;
>>>
>>> If use BUG() happens in max98095_get_bq_channel, it will not return here?
>>
>>
>> Not quite sure what you mean?
>
> I means if Axel Lin's patch applied, and CONFIG_BUG is on, it will
> panic firstly the if condition will be never entered.
My patch is a replacement for Axel's patch, not on top of it. For Axel's
patch it would panic if channel was less than zero if CONFIG_BUG was
enabled, but would still have undefined behaviour if CONFIG_BUG was not
enabled.
~Ryan
>>
>> If CONFIG_BUG was not enabled for the original version, then it would
>> not return at the BUG_ON and would either crash or cause odd behaviour
>> if it tried to index channel as -1.
>>
>> My patch is removing the BUG_ON and replacing it with a proper check and
>> return. It doesn't need to check > 1 since max98095_get_bq_channel never
>> returns that.
>>
>> My understanding is that device drivers, in general, should not call
>> BUG. BUG is for unrecoverable errors which leave the kernel in some
>> unstable state. Here we can just return an error code.
>
> Agree
>
>>
>> ~Ryan
>>
>>>
>>>>
>>>> if (!pdata || !max98095->bq_textcnt)
>>>> return 0;
>>>> @@ -2069,6 +2070,9 @@ static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
>>>> int channel = max98095_get_bq_channel(kcontrol->id.name);
>>>> struct max98095_cdata *cdata;
>>>>
>>>> + if (channel < 0)
>>>> + return channel;
>>>> +
>>>> cdata = &max98095->dai[channel];
>>>> ucontrol->value.enumerated.item[0] = cdata->bq_sel;
>>>>
>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>> Please read the FAQ at http://www.tux.org/lkml/
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>
next prev parent reply other threads:[~2011-09-29 2:01 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 [this message]
2011-09-29 2:06 ` Dave Young
2011-09-29 1:33 ` Dave Young
2011-09-28 23:15 ` [PATCH 1/2] ASoC: Add BUG() assertion if max98088_get_channel " Ryan Mallon
2011-09-29 10:34 ` 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=4E83D162.2010004@gmail.com \
--to=rmallon@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=axel.lin@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=hidave.darkstar@gmail.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).