diff mbox series

spi: synquacer: Silence unused variable warnings

Message ID 20230407091300.2316694-1-ilias.apalodimas@linaro.org
State Accepted
Commit 8485595927e1685a8369426bda91b6a89dc2754c
Headers show
Series spi: synquacer: Silence unused variable warnings | expand

Commit Message

Ilias Apalodimas April 7, 2023, 9:13 a.m. UTC
When building with clang, the compiler compains with

drivers/spi/spi-synquacer.c:212:11: warning: variable 'bus_width' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        else if (priv->mode & SPI_TX_OCTAL)
                 ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/spi-synquacer.c:276:11: note: uninitialized use occurs here
        val |= ((bus_width >> 1) << BUS_WIDTH);
                 ^~~~~~~~~
drivers/spi/spi-synquacer.c:212:7: note: remove the 'if' if its condition is always true
        else if (priv->mode & SPI_TX_OCTAL)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/spi-synquacer.c:189:25: note: initialize the variable 'bus_width' to silence this warning

So initialize bus_width to 1 and add a warning if none of the configured
modes matches

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 drivers/spi/spi-synquacer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ilias Apalodimas April 7, 2023, 9:19 a.m. UTC | #1
s/unused/uninitialized on the subject....

On Fri, 7 Apr 2023 at 12:13, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> When building with clang, the compiler compains with
>
> drivers/spi/spi-synquacer.c:212:11: warning: variable 'bus_width' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>         else if (priv->mode & SPI_TX_OCTAL)
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:276:11: note: uninitialized use occurs here
>         val |= ((bus_width >> 1) << BUS_WIDTH);
>                  ^~~~~~~~~
> drivers/spi/spi-synquacer.c:212:7: note: remove the 'if' if its condition is always true
>         else if (priv->mode & SPI_TX_OCTAL)
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:189:25: note: initialize the variable 'bus_width' to silence this warning
>
> So initialize bus_width to 1 and add a warning if none of the configured
> modes matches
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  drivers/spi/spi-synquacer.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-synquacer.c b/drivers/spi/spi-synquacer.c
> index 0cae3dfc778f..0f5d0a30c39d 100644
> --- a/drivers/spi/spi-synquacer.c
> +++ b/drivers/spi/spi-synquacer.c
> @@ -186,7 +186,7 @@ static void synquacer_spi_config(struct udevice *dev, void *rx, const void *tx)
>         struct udevice *bus = dev->parent;
>         struct synquacer_spi_priv *priv = dev_get_priv(bus);
>         struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev);
> -       u32 val, div, bus_width;
> +       u32 val, div, bus_width = 1;
>         int rwflag;
>
>         rwflag = (rx ? 1 : 0) | (tx ? 2 : 0);
> @@ -211,6 +211,8 @@ static void synquacer_spi_config(struct udevice *dev, void *rx, const void *tx)
>                 bus_width = 4;
>         else if (priv->mode & SPI_TX_OCTAL)
>                 bus_width = 8;
> +       else
> +               log_warning("SPI mode not configured, setting to byte mode\n");
>
>         div = DIV_ROUND_UP(125000000, priv->speed);
>
> --
> 2.39.2
>
Jassi Brar April 8, 2023, 3:01 p.m. UTC | #2
On Fri, 7 Apr 2023 at 04:13, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> When building with clang, the compiler compains with
>
> drivers/spi/spi-synquacer.c:212:11: warning: variable 'bus_width' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>         else if (priv->mode & SPI_TX_OCTAL)
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:276:11: note: uninitialized use occurs here
>         val |= ((bus_width >> 1) << BUS_WIDTH);
>                  ^~~~~~~~~
> drivers/spi/spi-synquacer.c:212:7: note: remove the 'if' if its condition is always true
>         else if (priv->mode & SPI_TX_OCTAL)
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:189:25: note: initialize the variable 'bus_width' to silence this warning
>
> So initialize bus_width to 1 and add a warning if none of the configured
> modes matches
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>
Acked-by: Jassi Brar <jaswinder.singh@linaro.org>
Jagan Teki April 25, 2023, 5:36 p.m. UTC | #3
On Fri, Apr 7, 2023 at 2:43 PM Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> When building with clang, the compiler compains with
>
> drivers/spi/spi-synquacer.c:212:11: warning: variable 'bus_width' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>         else if (priv->mode & SPI_TX_OCTAL)
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:276:11: note: uninitialized use occurs here
>         val |= ((bus_width >> 1) << BUS_WIDTH);
>                  ^~~~~~~~~
> drivers/spi/spi-synquacer.c:212:7: note: remove the 'if' if its condition is always true
>         else if (priv->mode & SPI_TX_OCTAL)
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-synquacer.c:189:25: note: initialize the variable 'bus_width' to silence this warning
>
> So initialize bus_width to 1 and add a warning if none of the configured
> modes matches
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---

Applied to u-boot-spi/master
diff mbox series

Patch

diff --git a/drivers/spi/spi-synquacer.c b/drivers/spi/spi-synquacer.c
index 0cae3dfc778f..0f5d0a30c39d 100644
--- a/drivers/spi/spi-synquacer.c
+++ b/drivers/spi/spi-synquacer.c
@@ -186,7 +186,7 @@  static void synquacer_spi_config(struct udevice *dev, void *rx, const void *tx)
 	struct udevice *bus = dev->parent;
 	struct synquacer_spi_priv *priv = dev_get_priv(bus);
 	struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev);
-	u32 val, div, bus_width;
+	u32 val, div, bus_width = 1;
 	int rwflag;
 
 	rwflag = (rx ? 1 : 0) | (tx ? 2 : 0);
@@ -211,6 +211,8 @@  static void synquacer_spi_config(struct udevice *dev, void *rx, const void *tx)
 		bus_width = 4;
 	else if (priv->mode & SPI_TX_OCTAL)
 		bus_width = 8;
+	else
+		log_warning("SPI mode not configured, setting to byte mode\n");
 
 	div = DIV_ROUND_UP(125000000, priv->speed);