Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1318473 > unrolled thread

[PATCH] tty/metag_da: initialize number_written to zero

Started byColin King <colin.king@canonical.com>
First post2016-01-27 00:40 +0100
Last post2016-01-27 12:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] tty/metag_da: initialize number_written to zero Colin King <colin.king@canonical.com> - 2016-01-27 00:40 +0100
    Re: [PATCH] tty/metag_da: initialize number_written to zero James Hogan <james.hogan@imgtec.com> - 2016-01-27 12:50 +0100

#1318473 — [PATCH] tty/metag_da: initialize number_written to zero

FromColin King <colin.king@canonical.com>
Date2016-01-27 00:40 +0100
Subject[PATCH] tty/metag_da: initialize number_written to zero
Message-ID<qVlnk-385-23@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

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.
Fix this by initializing it to zero for the case when
dport->xmit_count is zero.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 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

[toc] | [next] | [standalone]


#1318900

FromJames Hogan <james.hogan@imgtec.com>
Date2016-01-27 12:50 +0100
Message-ID<qVwLN-2Tu-49@gated-at.bofh.it>
In reply to#1318473

[Multipart message — attachments visible in raw view] — view raw

Hi Colin,

On Tue, Jan 26, 2016 at 11:37:25PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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@canonical.com>
> ---
>  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
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web