diff mbox

ASoC: rsnd: fix usrcnt decrementing bug

Message ID 87y4ckg1fp.wl%kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kuninori Morimoto Dec. 24, 2015, 12:04 a.m. UTC
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@samsung.com>
> ---

Thank you for your patch. good catch !
I noticed current error case is not good for ssi.c
Can you agree below ?

---------
---------


Best regards
---
Kuninori Morimoto

Comments

Andrzej Hajda Dec. 24, 2015, 5:56 a.m. UTC | #1
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@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
>
>
Kuninori Morimoto Dec. 24, 2015, 6:14 a.m. UTC | #2
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@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.

Thanks.
Who send this patch ? you or me ?
I think you can do it ?
diff mbox

Patch

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;
 }