public inbox for linux-metag@vger.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
To: Colin King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Cc: Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Jiri Slaby <jslaby-IBi9RG/b67k@public.gmane.org>,
	linux-metag-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] tty/metag_da: initialize number_written to zero
Date: Wed, 27 Jan 2016 11:42:06 +0000	[thread overview]
Message-ID: <20160127114206.GB20777@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1453851445-4645-1-git-send-email-colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1572 bytes --]

Hi Colin,

On Tue, Jan 26, 2016 at 11:37:25PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> 
> number_written is not initialized, so it can be any value. In the
> case where dport->xmit_cnt is zero, number_written is not set
> and subsequent accesses to it will be reading a garbage value.

the only subsequent accesses when dport->xmit_cnt == 0 are:

	/* if we've made more data available, wake up tty */
	if (count && number_written) {

and:

	/* did the write fail? */
	return count && !number_written;

but dport->xmit_cnt == 0 implies count == 0, so number_written shouldn't
be used, and both will evaluate to false regardless of the uninitialised
value, so it looks fine as it is to me.

Is this tripping up some static analysis tool or something?

Thanks
James

> Fix this by initializing it to zero for the case when
> dport->xmit_count is zero.
> 
> Signed-off-by: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> ---
>  drivers/tty/metag_da.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/metag_da.c b/drivers/tty/metag_da.c
> index 9325262..3da89c1 100644
> --- a/drivers/tty/metag_da.c
> +++ b/drivers/tty/metag_da.c
> @@ -230,7 +230,7 @@ static int put_channel_data(unsigned int chan)
>  {
>  	struct dashtty_port *dport;
>  	struct tty_struct *tty;
> -	int number_written;
> +	int number_written = 0;
>  	unsigned int count = 0;
>  
>  	dport = &dashtty_ports[chan];
> -- 
> 2.7.0.rc3
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-01-27 11:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 23:37 [PATCH] tty/metag_da: initialize number_written to zero Colin King
     [not found] ` <1453851445-4645-1-git-send-email-colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2016-01-27 11:42   ` James Hogan [this message]
2016-01-28 18:48     ` Colin Ian King
2016-02-07  7:41       ` Greg Kroah-Hartman
     [not found]         ` <20160207074109.GA6508-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2016-02-07  7:59           ` Colin Ian King

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=20160127114206.GB20777@jhogan-linux.le.imgtec.org \
    --to=james.hogan-1axoqhu6uovqt0dzr+alfa@public.gmane.org \
    --cc=colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=jslaby-IBi9RG/b67k@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-metag-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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