* [PATCH] spi: stm32: fix NULL check on pointer-to-pointer variable
@ 2025-06-28 0:02 Antonio Quartulli
2025-06-30 7:34 ` Clement LE GOFFIC
0 siblings, 1 reply; 10+ messages in thread
From: Antonio Quartulli @ 2025-06-28 0:02 UTC (permalink / raw)
To: linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel,
Clément Le Goffic, Alexandre Torgue, Maxime Coquelin,
Mark Brown, Alain Volmat, Antonio Quartulli
In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
and rx_mdma_desc are passed as pointer-to-pointer arguments.
The goal is to pass back to the caller the value returned
by dmaengine_prep_slave_sg(), when it is not NULL.
However, the NULL check on the result is erroneously
performed without dereferencing the pointer.
Add the proper dereference operator to both checks.
Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
drivers/spi/spi-stm32.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 3d20f09f1ae7..e9fa17e52fb0 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1529,7 +1529,7 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
DMA_PREP_INTERRUPT);
sg_free_table(&dma_sgt);
- if (!rx_dma_desc)
+ if (!*rx_dma_desc)
return -EINVAL;
/* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
@@ -1563,8 +1563,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
DMA_PREP_INTERRUPT);
sg_free_table(&mdma_sgt);
- if (!rx_mdma_desc) {
- rx_dma_desc = NULL;
+ if (!*rx_mdma_desc) {
+ *rx_dma_desc = NULL;
return -EINVAL;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] spi: stm32: fix NULL check on pointer-to-pointer variable
2025-06-28 0:02 [PATCH] spi: stm32: fix NULL check on pointer-to-pointer variable Antonio Quartulli
@ 2025-06-30 7:34 ` Clement LE GOFFIC
2025-06-30 7:48 ` Antonio Quartulli
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
0 siblings, 2 replies; 10+ messages in thread
From: Clement LE GOFFIC @ 2025-06-30 7:34 UTC (permalink / raw)
To: Antonio Quartulli, linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel, Alexandre Torgue,
Maxime Coquelin, Mark Brown, Alain Volmat
Hi Antonio,
On 6/28/25 02:02, Antonio Quartulli wrote:
> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>
> The goal is to pass back to the caller the value returned
> by dmaengine_prep_slave_sg(), when it is not NULL.
>
> However, the NULL check on the result is erroneously
> performed without dereferencing the pointer.
>
> Add the proper dereference operator to both checks.
>
> Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
> Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
> ---
> drivers/spi/spi-stm32.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 3d20f09f1ae7..e9fa17e52fb0 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -1529,7 +1529,7 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> DMA_PREP_INTERRUPT);
> sg_free_table(&dma_sgt);
>
> - if (!rx_dma_desc)
> + if (!*rx_dma_desc)
> return -EINVAL;
>
> /* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
> @@ -1563,8 +1563,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> DMA_PREP_INTERRUPT);
> sg_free_table(&mdma_sgt);
>
> - if (!rx_mdma_desc) {
> - rx_dma_desc = NULL;
> + if (!*rx_mdma_desc) {
> + *rx_dma_desc = NULL;
> return -EINVAL;
> }
>
Good catch for both pointers !
For readability, I would suggest to define two dma_async_tx_descriptor
ptr at the beginning of the function such as :
struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
And then use them all along the function even in the assignation.
Best regards,
Clément
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] spi: stm32: fix NULL check on pointer-to-pointer variable
2025-06-30 7:34 ` Clement LE GOFFIC
@ 2025-06-30 7:48 ` Antonio Quartulli
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
1 sibling, 0 replies; 10+ messages in thread
From: Antonio Quartulli @ 2025-06-30 7:48 UTC (permalink / raw)
To: Clement LE GOFFIC, linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel, Alexandre Torgue,
Maxime Coquelin, Mark Brown, Alain Volmat
Hi Clement,
On 30/06/2025 09:34, Clement LE GOFFIC wrote:
> Hi Antonio,
>
> On 6/28/25 02:02, Antonio Quartulli wrote:
>> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
>> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>>
>> The goal is to pass back to the caller the value returned
>> by dmaengine_prep_slave_sg(), when it is not NULL.
>>
>> However, the NULL check on the result is erroneously
>> performed without dereferencing the pointer.
>>
>> Add the proper dereference operator to both checks.
>>
>> Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to
>> enhance DDR use")
>> Addresses-Coverity-ID: 1644715 ("Null pointer dereferences
>> (REVERSE_INULL)")
>> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>> ---
>> drivers/spi/spi-stm32.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
>> index 3d20f09f1ae7..e9fa17e52fb0 100644
>> --- a/drivers/spi/spi-stm32.c
>> +++ b/drivers/spi/spi-stm32.c
>> @@ -1529,7 +1529,7 @@ static int
>> stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
>> DMA_PREP_INTERRUPT);
>> sg_free_table(&dma_sgt);
>> - if (!rx_dma_desc)
>> + if (!*rx_dma_desc)
>> return -EINVAL;
>> /* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
>> @@ -1563,8 +1563,8 @@ static int
>> stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
>> DMA_PREP_INTERRUPT);
>> sg_free_table(&mdma_sgt);
>> - if (!rx_mdma_desc) {
>> - rx_dma_desc = NULL;
>> + if (!*rx_mdma_desc) {
>> + *rx_dma_desc = NULL;
>> return -EINVAL;
>> }
>
> Good catch for both pointers !
>
> For readability, I would suggest to define two dma_async_tx_descriptor
> ptr at the beginning of the function such as :
> struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
> struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
>
> And then use them all along the function even in the assignation.
>
Thanks for the comment.
Will send v2!
Regards,
--
Antonio Quartulli
CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 7:34 ` Clement LE GOFFIC
2025-06-30 7:48 ` Antonio Quartulli
@ 2025-06-30 8:12 ` Antonio Quartulli
2025-06-30 8:28 ` Clement LE GOFFIC
` (3 more replies)
1 sibling, 4 replies; 10+ messages in thread
From: Antonio Quartulli @ 2025-06-30 8:12 UTC (permalink / raw)
To: linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel,
Clément Le Goffic, Alexandre Torgue, Maxime Coquelin,
Mark Brown, Alain Volmat, Antonio Quartulli
In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
and rx_mdma_desc are passed as pointer-to-pointer arguments.
The goal is to pass back to the caller the value returned
by dmaengine_prep_slave_sg(), when it is not NULL.
However, these variables are wrongly handled as simple pointers
during later assignments and checks.
Fix this behaviour by introducing two pointer variables
which can then be treated accordingly.
Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
Changes from v1:
* introduce *_mdma_desc and *_dma_desc for better readability
* fix another instance of rx_dma_desc bogus assignment in case of
failure of sg_alloc_table()
* commit title/message reworded accordingly to the previous point
---
drivers/spi/spi-stm32.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 3d20f09f1ae7..4b7f074fdba9 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1474,6 +1474,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
struct dma_async_tx_descriptor **rx_dma_desc,
struct dma_async_tx_descriptor **rx_mdma_desc)
{
+ struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
+ struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
struct dma_slave_config rx_mdma_conf = {0};
u32 sram_period, nents = 0, spi_s_len;
struct sg_table dma_sgt, mdma_sgt;
@@ -1524,18 +1526,18 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
}
}
- *rx_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
- dma_sgt.nents, rx_dma_conf->direction,
- DMA_PREP_INTERRUPT);
+ _dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
+ dma_sgt.nents, rx_dma_conf->direction,
+ DMA_PREP_INTERRUPT);
sg_free_table(&dma_sgt);
- if (!rx_dma_desc)
+ if (!_dma_desc)
return -EINVAL;
/* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
ret = sg_alloc_table(&mdma_sgt, nents, GFP_ATOMIC);
if (ret) {
- rx_dma_desc = NULL;
+ _dma_desc = NULL;
return ret;
}
@@ -1558,13 +1560,13 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
}
}
- *rx_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
- mdma_sgt.nents, rx_mdma_conf.direction,
- DMA_PREP_INTERRUPT);
+ _mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
+ mdma_sgt.nents, rx_mdma_conf.direction,
+ DMA_PREP_INTERRUPT);
sg_free_table(&mdma_sgt);
- if (!rx_mdma_desc) {
- rx_dma_desc = NULL;
+ if (!_mdma_desc) {
+ _dma_desc = NULL;
return -EINVAL;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
@ 2025-06-30 8:28 ` Clement LE GOFFIC
2025-06-30 11:20 ` Mark Brown
2025-06-30 11:40 ` Alain Volmat
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Clement LE GOFFIC @ 2025-06-30 8:28 UTC (permalink / raw)
To: Antonio Quartulli, linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel, Alexandre Torgue,
Maxime Coquelin, Mark Brown, Alain Volmat
On 6/30/25 10:12, Antonio Quartulli wrote:
> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>
> The goal is to pass back to the caller the value returned
> by dmaengine_prep_slave_sg(), when it is not NULL.
>
> However, these variables are wrongly handled as simple pointers
> during later assignments and checks.
>
> Fix this behaviour by introducing two pointer variables
> which can then be treated accordingly.
>
> Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
> Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>
> ---
> Changes from v1:
> * introduce *_mdma_desc and *_dma_desc for better readability
> * fix another instance of rx_dma_desc bogus assignment in case of
> failure of sg_alloc_table()
> * commit title/message reworded accordingly to the previous point
> ---
> drivers/spi/spi-stm32.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 3d20f09f1ae7..4b7f074fdba9 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -1474,6 +1474,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> struct dma_async_tx_descriptor **rx_dma_desc,
> struct dma_async_tx_descriptor **rx_mdma_desc)
> {
> + struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
> + struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
> struct dma_slave_config rx_mdma_conf = {0};
> u32 sram_period, nents = 0, spi_s_len;
> struct sg_table dma_sgt, mdma_sgt;
> @@ -1524,18 +1526,18 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> - dma_sgt.nents, rx_dma_conf->direction,
> - DMA_PREP_INTERRUPT);
> + _dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> + dma_sgt.nents, rx_dma_conf->direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&dma_sgt);
>
> - if (!rx_dma_desc)
> + if (!_dma_desc)
> return -EINVAL;
>
> /* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
> ret = sg_alloc_table(&mdma_sgt, nents, GFP_ATOMIC);
> if (ret) {
> - rx_dma_desc = NULL;
> + _dma_desc = NULL;
> return ret;
> }
>
> @@ -1558,13 +1560,13 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> - mdma_sgt.nents, rx_mdma_conf.direction,
> - DMA_PREP_INTERRUPT);
> + _mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> + mdma_sgt.nents, rx_mdma_conf.direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&mdma_sgt);
>
> - if (!rx_mdma_desc) {
> - rx_dma_desc = NULL;
> + if (!_mdma_desc) {
> + _dma_desc = NULL;
> return -EINVAL;
> }
>
Thank you, LGTM
You can add my Reviewed-by
Best regards,
Clément
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 8:28 ` Clement LE GOFFIC
@ 2025-06-30 11:20 ` Mark Brown
2025-06-30 12:00 ` Clement LE GOFFIC
0 siblings, 1 reply; 10+ messages in thread
From: Mark Brown @ 2025-06-30 11:20 UTC (permalink / raw)
To: Clement LE GOFFIC
Cc: Antonio Quartulli, linux-spi, linux-stm32, linux-arm-kernel,
linux-kernel, Alexandre Torgue, Maxime Coquelin, Alain Volmat
[-- Attachment #1: Type: text/plain, Size: 243 bytes --]
On Mon, Jun 30, 2025 at 10:28:50AM +0200, Clement LE GOFFIC wrote:
> Thank you, LGTM
> You can add my Reviewed-by
If you want to add a Reviewed-by you should actually write it out in the
mail, people rely on tooling like b4 to pick them up.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
2025-06-30 8:28 ` Clement LE GOFFIC
@ 2025-06-30 11:40 ` Alain Volmat
2025-06-30 11:58 ` Clement LE GOFFIC
2025-07-01 22:15 ` Mark Brown
3 siblings, 0 replies; 10+ messages in thread
From: Alain Volmat @ 2025-06-30 11:40 UTC (permalink / raw)
To: Antonio Quartulli
Cc: linux-spi, linux-stm32, linux-arm-kernel, linux-kernel,
Clément Le Goffic, Alexandre Torgue, Maxime Coquelin,
Mark Brown
Hi Antonio,
Thank you for the patch.
On Mon, Jun 30, 2025 at 10:12:53AM +0200, Antonio Quartulli wrote:
> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>
> The goal is to pass back to the caller the value returned
> by dmaengine_prep_slave_sg(), when it is not NULL.
>
> However, these variables are wrongly handled as simple pointers
> during later assignments and checks.
>
> Fix this behaviour by introducing two pointer variables
> which can then be treated accordingly.
>
> Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
> Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>
> ---
> Changes from v1:
> * introduce *_mdma_desc and *_dma_desc for better readability
> * fix another instance of rx_dma_desc bogus assignment in case of
> failure of sg_alloc_table()
> * commit title/message reworded accordingly to the previous point
> ---
> drivers/spi/spi-stm32.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 3d20f09f1ae7..4b7f074fdba9 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -1474,6 +1474,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> struct dma_async_tx_descriptor **rx_dma_desc,
> struct dma_async_tx_descriptor **rx_mdma_desc)
> {
> + struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
> + struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
> struct dma_slave_config rx_mdma_conf = {0};
> u32 sram_period, nents = 0, spi_s_len;
> struct sg_table dma_sgt, mdma_sgt;
> @@ -1524,18 +1526,18 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> - dma_sgt.nents, rx_dma_conf->direction,
> - DMA_PREP_INTERRUPT);
> + _dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> + dma_sgt.nents, rx_dma_conf->direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&dma_sgt);
>
> - if (!rx_dma_desc)
> + if (!_dma_desc)
> return -EINVAL;
>
> /* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
> ret = sg_alloc_table(&mdma_sgt, nents, GFP_ATOMIC);
> if (ret) {
> - rx_dma_desc = NULL;
> + _dma_desc = NULL;
> return ret;
> }
>
> @@ -1558,13 +1560,13 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> - mdma_sgt.nents, rx_mdma_conf.direction,
> - DMA_PREP_INTERRUPT);
> + _mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> + mdma_sgt.nents, rx_mdma_conf.direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&mdma_sgt);
>
> - if (!rx_mdma_desc) {
> - rx_dma_desc = NULL;
> + if (!_mdma_desc) {
> + _dma_desc = NULL;
> return -EINVAL;
> }
>
Acked-by: Alain Volmat <alain.volmat@foss.st.com>
Regards,
Alain
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
2025-06-30 8:28 ` Clement LE GOFFIC
2025-06-30 11:40 ` Alain Volmat
@ 2025-06-30 11:58 ` Clement LE GOFFIC
2025-07-01 22:15 ` Mark Brown
3 siblings, 0 replies; 10+ messages in thread
From: Clement LE GOFFIC @ 2025-06-30 11:58 UTC (permalink / raw)
To: Antonio Quartulli, linux-spi
Cc: linux-stm32, linux-arm-kernel, linux-kernel, Alexandre Torgue,
Maxime Coquelin, Mark Brown, Alain Volmat
On 6/30/25 10:12, Antonio Quartulli wrote:
> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>
> The goal is to pass back to the caller the value returned
> by dmaengine_prep_slave_sg(), when it is not NULL.
>
> However, these variables are wrongly handled as simple pointers
> during later assignments and checks.
>
> Fix this behaviour by introducing two pointer variables
> which can then be treated accordingly.
>
> Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
> Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)")
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>
> ---
> Changes from v1:
> * introduce *_mdma_desc and *_dma_desc for better readability
> * fix another instance of rx_dma_desc bogus assignment in case of
> failure of sg_alloc_table()
> * commit title/message reworded accordingly to the previous point
> ---
> drivers/spi/spi-stm32.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 3d20f09f1ae7..4b7f074fdba9 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -1474,6 +1474,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> struct dma_async_tx_descriptor **rx_dma_desc,
> struct dma_async_tx_descriptor **rx_mdma_desc)
> {
> + struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
> + struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
> struct dma_slave_config rx_mdma_conf = {0};
> u32 sram_period, nents = 0, spi_s_len;
> struct sg_table dma_sgt, mdma_sgt;
> @@ -1524,18 +1526,18 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> - dma_sgt.nents, rx_dma_conf->direction,
> - DMA_PREP_INTERRUPT);
> + _dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
> + dma_sgt.nents, rx_dma_conf->direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&dma_sgt);
>
> - if (!rx_dma_desc)
> + if (!_dma_desc)
> return -EINVAL;
>
> /* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
> ret = sg_alloc_table(&mdma_sgt, nents, GFP_ATOMIC);
> if (ret) {
> - rx_dma_desc = NULL;
> + _dma_desc = NULL;
> return ret;
> }
>
> @@ -1558,13 +1560,13 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
> }
> }
>
> - *rx_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> - mdma_sgt.nents, rx_mdma_conf.direction,
> - DMA_PREP_INTERRUPT);
> + _mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
> + mdma_sgt.nents, rx_mdma_conf.direction,
> + DMA_PREP_INTERRUPT);
> sg_free_table(&mdma_sgt);
>
> - if (!rx_mdma_desc) {
> - rx_dma_desc = NULL;
> + if (!_mdma_desc) {
> + _dma_desc = NULL;
> return -EINVAL;
> }
>
Reviewed-by: Clément Le Goffic <clement.legoffic@foss.st.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 11:20 ` Mark Brown
@ 2025-06-30 12:00 ` Clement LE GOFFIC
0 siblings, 0 replies; 10+ messages in thread
From: Clement LE GOFFIC @ 2025-06-30 12:00 UTC (permalink / raw)
To: Mark Brown
Cc: Antonio Quartulli, linux-spi, linux-stm32, linux-arm-kernel,
linux-kernel, Alexandre Torgue, Maxime Coquelin, Alain Volmat
On 6/30/25 13:20, Mark Brown wrote:
> On Mon, Jun 30, 2025 at 10:28:50AM +0200, Clement LE GOFFIC wrote:
>
>> Thank you, LGTM
>> You can add my Reviewed-by
>
> If you want to add a Reviewed-by you should actually write it out in the
> mail, people rely on tooling like b4 to pick them up.
Yes, sorry.
Fixed it.
Best regards,
Clément
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
` (2 preceding siblings ...)
2025-06-30 11:58 ` Clement LE GOFFIC
@ 2025-07-01 22:15 ` Mark Brown
3 siblings, 0 replies; 10+ messages in thread
From: Mark Brown @ 2025-07-01 22:15 UTC (permalink / raw)
To: linux-spi, Antonio Quartulli
Cc: linux-stm32, linux-arm-kernel, linux-kernel,
Clément Le Goffic, Alexandre Torgue, Maxime Coquelin,
Alain Volmat
On Mon, 30 Jun 2025 10:12:53 +0200, Antonio Quartulli wrote:
> In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc
> and rx_mdma_desc are passed as pointer-to-pointer arguments.
>
> The goal is to pass back to the caller the value returned
> by dmaengine_prep_slave_sg(), when it is not NULL.
>
> However, these variables are wrongly handled as simple pointers
> during later assignments and checks.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: stm32: fix pointer-to-pointer variables usage
commit: c4f2c05ab02952c9a56067aeb700ded95b183570
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-01 22:42 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-28 0:02 [PATCH] spi: stm32: fix NULL check on pointer-to-pointer variable Antonio Quartulli
2025-06-30 7:34 ` Clement LE GOFFIC
2025-06-30 7:48 ` Antonio Quartulli
2025-06-30 8:12 ` [PATCH v2] spi: stm32: fix pointer-to-pointer variables usage Antonio Quartulli
2025-06-30 8:28 ` Clement LE GOFFIC
2025-06-30 11:20 ` Mark Brown
2025-06-30 12:00 ` Clement LE GOFFIC
2025-06-30 11:40 ` Alain Volmat
2025-06-30 11:58 ` Clement LE GOFFIC
2025-07-01 22:15 ` Mark Brown
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).