netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wan: fix a missing check of spi_write_then_read
@ 2018-12-26  4:34 Kangjie Lu
  2018-12-28  0:25 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Kangjie Lu @ 2018-12-26  4:34 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, David S. Miller, netdev, linux-kernel

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;
 
 	data = bitrev8(data);
 	return data;
-- 
2.17.2 (Apple Git-113)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-28  0:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).