diff mbox

[2/5] ASoC: dwc: Don't allow negative use counts

Message ID 547F3C9F.8080102@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jackson Dec. 3, 2014, 4:38 p.m. UTC
Signed-off-by: Andrew Jackson <Andrew.Jackson@arm.com>
---
 sound/soc/dwc/designware_i2s.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Mark Brown Dec. 3, 2014, 5:25 p.m. UTC | #1
On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:

>  	case SNDRV_PCM_TRIGGER_STOP:
>  	case SNDRV_PCM_TRIGGER_SUSPEND:
>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> -		dev->active--;
> +		if (dev->active > 0)
> +			dev->active--;

How is this triggering - this sounds like you're papering over some
other bug somewhere?
Rajeev Kumar Dec. 4, 2014, 6:40 a.m. UTC | #2
On Wed, Dec 3, 2014 at 10:55 PM, Mark Brown <broonie@kernel.org> wrote:
> On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:
>
>>       case SNDRV_PCM_TRIGGER_STOP:
>>       case SNDRV_PCM_TRIGGER_SUSPEND:
>>       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
>> -             dev->active--;
>> +             if (dev->active > 0)
>> +                     dev->active--;
>
> How is this triggering - this sounds like you're papering over some
> other bug somewhere?
Rajeev Kumar Dec. 4, 2014, 6:43 a.m. UTC | #3
On Thu, Dec 4, 2014 at 12:10 PM, rajeev kumar
<rajeevkumar.linux@gmail.com> wrote:
> On Wed, Dec 3, 2014 at 10:55 PM, Mark Brown <broonie@kernel.org> wrote:
>> On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:
>>
>>>       case SNDRV_PCM_TRIGGER_STOP:
>>>       case SNDRV_PCM_TRIGGER_SUSPEND:
>>>       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
>>> -             dev->active--;
>>> +             if (dev->active > 0)
>>> +                     dev->active--;
>>
>> How is this triggering - this sounds like you're papering over some
>> other bug somewhere?

This check can be removed as it is not going to triggered.

B'rgds
~Rajeev
Andrew Jackson Dec. 4, 2014, 9 a.m. UTC | #4
On 12/03/14 17:25, Mark Brown wrote:
> On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:
> 
>>  	case SNDRV_PCM_TRIGGER_STOP:
>>  	case SNDRV_PCM_TRIGGER_SUSPEND:
>>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
>> -		dev->active--;
>> +		if (dev->active > 0)
>> +			dev->active--;
> 
> How is this triggering - this sounds like you're papering over some
> other bug somewhere?
> 

When I looked at the code paths I couldn't convince myself that STOP wouldn't be called more than once.  Then actuve would be negative and the device might not be restartable.  I didn't have a problem per se, it was just that it seemed to be something of a loophole.

   Andrew
Andrew Jackson Dec. 4, 2014, 9:07 a.m. UTC | #5
On 12/04/14 06:43, rajeev kumar wrote:
> On Thu, Dec 4, 2014 at 12:10 PM, rajeev kumar
> <rajeevkumar.linux@gmail.com> wrote:
>> On Wed, Dec 3, 2014 at 10:55 PM, Mark Brown <broonie@kernel.org> wrote:
>>> On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:
>>>
>>>>       case SNDRV_PCM_TRIGGER_STOP:
>>>>       case SNDRV_PCM_TRIGGER_SUSPEND:
>>>>       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
>>>> -             dev->active--;
>>>> +             if (dev->active > 0)
>>>> +                     dev->active--;
>>>
>>> How is this triggering - this sounds like you're papering over some
>>> other bug somewhere?
> 
> This check can be removed as it is not going to triggered.

As I said in my email to Mark, I couldn't convince myself that STOP/SUSPEND would only be called once so it seemed like a loophole which /might/ result in the device not functioning correctly.

If this can never happen, I'll drop the patch.

	Andrew

> B'rgds
> ~Rajeev
>
Mark Brown Dec. 4, 2014, 10:51 a.m. UTC | #6
On Thu, Dec 04, 2014 at 09:00:35AM +0000, Andrew Jackson wrote:
> On 12/03/14 17:25, Mark Brown wrote:
> > On Wed, Dec 03, 2014 at 04:38:55PM +0000, Andrew Jackson wrote:

> >>  	case SNDRV_PCM_TRIGGER_STOP:
> >>  	case SNDRV_PCM_TRIGGER_SUSPEND:
> >>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> >> -		dev->active--;
> >> +		if (dev->active > 0)
> >> +			dev->active--;

> > How is this triggering - this sounds like you're papering over some
> > other bug somewhere?

> When I looked at the code paths I couldn't convince myself that STOP
> wouldn't be called more than once.  Then actuve would be negative and
> the device might not be restartable.  I didn't have a problem per se,
> it was just that it seemed to be something of a loophole.

If you're just adding the check on the off chance that it might fire you
need to add a warning message as well - what your change does is make
the code look like it's supposed to have broken reference counting since
it has a check to silently fix up and ignore problems.
diff mbox

Patch

diff --git a/sound/soc/dwc/designware_i2s.c b/sound/soc/dwc/designware_i2s.c
index 08f0229..f8946bd 100644
--- a/sound/soc/dwc/designware_i2s.c
+++ b/sound/soc/dwc/designware_i2s.c
@@ -280,7 +280,8 @@  static int dw_i2s_trigger(struct snd_pcm_substream *substream,
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		dev->active--;
+		if (dev->active > 0)
+			dev->active--;
 		i2s_stop(dev, substream);
 		break;
 	default: