OSDN Git Service

spi: npcm: Fix uninitialized variable warning
authorOlof Johansson <olof@lixom.net>
Sat, 17 Nov 2018 03:55:04 +0000 (19:55 -0800)
committerMark Brown <broonie@kernel.org>
Tue, 27 Nov 2018 14:07:08 +0000 (14:07 +0000)
The compiler has no way to know that rsize 1 or 2 are the only valid
values. Also simplify the code a bit with early return.

The warning was:

drivers/spi/spi-npcm-pspi.c:215:6: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]

Signed-off-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-npcm-pspi.c

index fed05b0..dda91c1 100644 (file)
@@ -217,15 +217,23 @@ static void npcm_pspi_recv(struct npcm_pspi *priv)
        rsize = min(bytes_per_word(priv->bits_per_word), priv->rx_bytes);
        priv->rx_bytes -= rsize;
 
-       if (priv->rx_buf) {
-               if (rsize == 1)
-                       val = ioread8(priv->base + NPCM_PSPI_DATA);
-               if (rsize == 2)
-                       val = ioread16(priv->base + NPCM_PSPI_DATA);
+       if (!priv->rx_buf)
+               return;
 
-               *priv->rx_buf = val;
-               priv->rx_buf += rsize;
+       switch (rsize) {
+       case 1:
+               val = ioread8(priv->base + NPCM_PSPI_DATA);
+               break;
+       case 2:
+               val = ioread16(priv->base + NPCM_PSPI_DATA);
+               break;
+       default:
+               WARN_ON_ONCE(1);
+               return;
        }
+
+       *priv->rx_buf = val;
+       priv->rx_buf += rsize;
 }
 
 static int npcm_pspi_transfer_one(struct spi_master *master,