spi: stm32-qspi: Fix stm32_qspi_transfer_one_message() error path

patrice.chotard@foss.st.com posted 1 patch 3 years, 7 months ago
There is a newer version of this series
drivers/spi/spi-stm32-qspi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
spi: stm32-qspi: Fix stm32_qspi_transfer_one_message() error path
Posted by patrice.chotard@foss.st.com 3 years, 7 months ago
From: Patrice Chotard <patrice.chotard@foss.st.com>

The patch a557fca630cc: "spi: stm32_qspi: Add transfer_one_message()
spi callback" from Aug 23, 2022, leads to the following Smatch static
checker warning:

drivers/spi/spi-stm32-qspi.c:627 stm32_qspi_transfer_one_message()
error: uninitialized symbol 'ret'.Fix the following Smatch static checker warning:

Fixes: a557fca630cc ("spi: stm32_qspi: Add transfer_one_message() spi callback")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
---
 drivers/spi/spi-stm32-qspi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
index 92459daca95f..679fd1c34f7e 100644
--- a/drivers/spi/spi-stm32-qspi.c
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -562,7 +562,7 @@ static int stm32_qspi_transfer_one_message(struct spi_controller *ctrl,
 	struct spi_transfer *transfer;
 	struct spi_device *spi = msg->spi;
 	struct spi_mem_op op;
-	int ret;
+	int ret = 0;
 
 	if (!spi->cs_gpiod)
 		return -EOPNOTSUPP;
@@ -592,8 +592,10 @@ static int stm32_qspi_transfer_one_message(struct spi_controller *ctrl,
 			dummy_bytes = transfer->len;
 
 			/* if happens, means that message is not correctly built */
-			if (list_is_last(&transfer->transfer_list, &msg->transfers))
+			if (list_is_last(&transfer->transfer_list, &msg->transfers)) {
+				ret = -EINVAL;
 				goto end_of_transfer;
+			}
 
 			transfer = list_next_entry(transfer, transfer_list);
 		}
-- 
2.25.1
Re: spi: stm32-qspi: Fix stm32_qspi_transfer_one_message() error path
Posted by Patrice CHOTARD 3 years, 7 months ago
Hi Mark

Patch sent with incorrect commit title, a new one is in the pipe.
Sorry for that

Patrice

On 8/26/22 11:18, patrice.chotard@foss.st.com wrote:
> From: Patrice Chotard <patrice.chotard@foss.st.com>
> 
> The patch a557fca630cc: "spi: stm32_qspi: Add transfer_one_message()
> spi callback" from Aug 23, 2022, leads to the following Smatch static
> checker warning:
> 
> drivers/spi/spi-stm32-qspi.c:627 stm32_qspi_transfer_one_message()
> error: uninitialized symbol 'ret'.Fix the following Smatch static checker warning:
> 
> Fixes: a557fca630cc ("spi: stm32_qspi: Add transfer_one_message() spi callback")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
> ---
>  drivers/spi/spi-stm32-qspi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
> index 92459daca95f..679fd1c34f7e 100644
> --- a/drivers/spi/spi-stm32-qspi.c
> +++ b/drivers/spi/spi-stm32-qspi.c
> @@ -562,7 +562,7 @@ static int stm32_qspi_transfer_one_message(struct spi_controller *ctrl,
>  	struct spi_transfer *transfer;
>  	struct spi_device *spi = msg->spi;
>  	struct spi_mem_op op;
> -	int ret;
> +	int ret = 0;
>  
>  	if (!spi->cs_gpiod)
>  		return -EOPNOTSUPP;
> @@ -592,8 +592,10 @@ static int stm32_qspi_transfer_one_message(struct spi_controller *ctrl,
>  			dummy_bytes = transfer->len;
>  
>  			/* if happens, means that message is not correctly built */
> -			if (list_is_last(&transfer->transfer_list, &msg->transfers))
> +			if (list_is_last(&transfer->transfer_list, &msg->transfers)) {
> +				ret = -EINVAL;
>  				goto end_of_transfer;
> +			}
>  
>  			transfer = list_next_entry(transfer, transfer_list);
>  		}