[PATCH v4 2/2] staging: dgap: tty.c: removes smatch warning "unsigned '--un->un_open_count' is never less than zero"

Dan Carpenter dan.carpenter at oracle.com
Tue Oct 1 18:02:00 UTC 2013


On Tue, Oct 01, 2013 at 12:54:21PM -0400, Lidza Louina wrote:
> This patch removes this smatch warning:
> unsigned '--un->un_open_count' is never less than zero
> 
> The code decremented the un_open_count variable
> and tested to see if it was less than zero. Because
> un_open_count is unsigned and can't be below zero,
> this test didn't work.
> 
> Signed-off-by: Lidza Louina <lidza.louina at gmail.com>
> ---
>  drivers/staging/dgap/dgap_tty.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/dgap/dgap_tty.c b/drivers/staging/dgap/dgap_tty.c
> index 015bccf..58cdcf9 100644
> --- a/drivers/staging/dgap/dgap_tty.c
> +++ b/drivers/staging/dgap/dgap_tty.c
> @@ -1458,12 +1458,14 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
>  		un->un_open_count = 1;
>  	}  
>  
> -	if (--un->un_open_count < 0) {
> +	if (--un->un_open_count == 0) {
>  		APR(("bad serial port open count of %d\n", un->un_open_count));
> -		un->un_open_count = 0;
> +		un->un_open_count = 1;
>  	}
>  
>  	ch->ch_open_count--;
> +	un->un_open_count--;

This isn't correct.  Now we're decrementing it twice.  It should just
be:

	if (un->un_open_count == 0) {
		APR(("bad serial port open count of %d\n", un->un_open_count));
		un->un_open_count = 1;
	}

	un->un_open_count--;
	ch->ch_open_count--;

regards,
dan carpenter



More information about the devel mailing list