[PATCH 1/3] mtd: rawnand: cortina_nand: Fix -ENOMEM detection
Michael Nazzareno Trimarchi
michael at amarulasolutions.com
Sun Aug 3 10:13:28 CEST 2025
Hi
On Fri, Aug 1, 2025 at 11:54 AM Andrew Goodbody <andrew.goodbody at linaro.org>
wrote:
> In init_nand_dma there was code to detect failure to allocate memory but
> it had two problems. Firstly the 2nd clause when info->tx_desc was NULL
> attempted to free info->tx_desc when it should be freeing info->rx_desc.
> Secondly there was no detection of both allocations failing, arguably
> the more likely scenario. Refactor the code to simplify it and just fail
> as soon as either allocation fails.
>
> This issue was found by Smatch.
>
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
> drivers/mtd/nand/raw/cortina_nand.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/cortina_nand.c
> b/drivers/mtd/nand/raw/cortina_nand.c
> index 06918a46e93..a27a6994f56 100644
> --- a/drivers/mtd/nand/raw/cortina_nand.c
> +++ b/drivers/mtd/nand/raw/cortina_nand.c
> @@ -186,14 +186,13 @@ int init_nand_dma(struct nand_chip *nand)
>
> info->tx_desc = malloc_cache_aligned((sizeof(struct
> tx_descriptor_t) *
> CA_DMA_DESC_NUM));
> - info->rx_desc = malloc_cache_aligned((sizeof(struct
> rx_descriptor_t) *
> - CA_DMA_DESC_NUM));
> -
> - if (!info->rx_desc && info->tx_desc) {
> + if (!info->tx_desc) {
> printf("Fail to alloc DMA descript!\n");
> - kfree(info->tx_desc);
> return -ENOMEM;
> - } else if (info->rx_desc && !info->tx_desc) {
> + }
> + info->rx_desc = malloc_cache_aligned((sizeof(struct
> rx_descriptor_t) *
> + CA_DMA_DESC_NUM));
> + if (!info->rx_desc) {
> printf("Fail to alloc DMA descript!\n");
> kfree(info->tx_desc);
> return -ENOMEM;
>
>
Reviewed-by: Michael Trimarchi <michael at amarulasolutions.com>
> --
> 2.39.5
>
>
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael at amarulasolutions.com
__________________________________
Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info at amarulasolutions.com
www.amarulasolutions.com
More information about the U-Boot
mailing list