netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: kjlu@umn.edu
Cc: pakki001@umn.edu, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wan: fix a missing check of spi_write_then_read
Date: Thu, 27 Dec 2018 16:25:07 -0800 (PST)	[thread overview]
Message-ID: <20181227.162507.1378702299026670300.davem@davemloft.net> (raw)
In-Reply-To: <20181226043443.74229-1-kjlu@umn.edu>

From: Kangjie Lu <kjlu@umn.edu>
Date: Tue, 25 Dec 2018 22:34:41 -0600

> When spi_write_then_read() fails, "data" can be uninitialized and thus
> may contain a random value; the following execution checks "data" with a
> mask, the result could be random.
> 
> The fix inserts a check of spi_write_then_read(): if it fails, always
> returns -1.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/net/wan/slic_ds26522.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wan/slic_ds26522.c b/drivers/net/wan/slic_ds26522.c
> index 1f6bc8791d51..89681910d875 100644
> --- a/drivers/net/wan/slic_ds26522.c
> +++ b/drivers/net/wan/slic_ds26522.c
> @@ -64,8 +64,9 @@ static u8 slic_read(struct spi_device *spi, u16 addr)
>  	temp[0] = (u8)(((addr >> 8) & 0x7f) | 0x80);
>  	temp[1] = (u8)(addr & 0xfe);
>  
> -	spi_write_then_read(spi, &temp[0], SLIC_TWO_LEN, &data,
> -			    SLIC_TRANS_LEN);
> +	if (spi_write_then_read(spi, &temp[0], SLIC_TWO_LEN, &data,
> +			    SLIC_TRANS_LEN))
> +		return -1;

This makes no sense, all callers use the data value as-is and perform
no error checking.

You have to either accept this code to stay as it is, or adjust all of
the call sites to do error handling.

And that's not easy, -1 is a valud return value.

      reply	other threads:[~2018-12-28  0:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-26  4:34 [PATCH] wan: fix a missing check of spi_write_then_read Kangjie Lu
2018-12-28  0:25 ` David Miller [this message]

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=20181227.162507.1378702299026670300.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pakki001@umn.edu \
    /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;
as well as URLs for NNTP newsgroup(s).