[alsa-devel] [PATCH] ASoC: rsnd: fix usrcnt decrementing bug

Andrzej Hajda a.hajda at samsung.com
Thu Dec 24 06:56:14 CET 2015


On 12/24/2015 01:04 AM, Kuninori Morimoto wrote:
> Hi Andrzej
>
>> Field usrcnt is unsigned so it cannot be lesser than zero.
>>
>> The problem has been detected using proposed semantic patch
>> scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].
>>
>> [1]: http://permalink.gmane.org/gmane.linux.kernel/2038576
>>
>> Signed-off-by: Andrzej Hajda <a.hajda at samsung.com>
>> ---
> Thank you for your patch. good catch !
> I noticed current error case is not good for ssi.c
> Can you agree below ?
Yes, of course.

Regards
Andrzej
>
> ---------
> diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
> index 7db05fd..e519e30 100644
> --- a/sound/soc/sh/rcar/ssi.c
> +++ b/sound/soc/sh/rcar/ssi.c
> @@ -403,6 +403,12 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod,
>  	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
>  	struct device *dev = rsnd_priv_to_dev(priv);
>  
> +	if (!ssi->usrcnt) {
> +		dev_err(dev, "%s[%d] usrcnt error\n",
> +			rsnd_mod_name(mod), rsnd_mod_id(mod));
> +		return -EIO;
> +	}
> +
>  	if (rsnd_ssi_is_parent(mod, io))
>  		goto rsnd_ssi_quit_end;
>  
> @@ -422,10 +428,6 @@ rsnd_ssi_quit_end:
>  
>  	ssi->usrcnt--;
>  
> -	if (ssi->usrcnt < 0)
> -		dev_err(dev, "%s[%d] usrcnt error\n",
> -			rsnd_mod_name(mod), rsnd_mod_id(mod));
> -
>  	return 0;
>  }
>  
> ---------
>
>
> Best regards
> ---
> Kuninori Morimoto
>
>



More information about the Alsa-devel mailing list