mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-12-24 10:52:13 +01:00
mtd: rawnand: cortina_nand: Fix -ENOMEM detection
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@linaro.org> Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
This commit is contained in:
parent
56372f834c
commit
ebf8aaf7af
@ -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));
|
||||
if (!info->tx_desc) {
|
||||
printf("Fail to alloc DMA descript!\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
info->rx_desc = malloc_cache_aligned((sizeof(struct rx_descriptor_t) *
|
||||
CA_DMA_DESC_NUM));
|
||||
|
||||
if (!info->rx_desc && info->tx_desc) {
|
||||
printf("Fail to alloc DMA descript!\n");
|
||||
kfree(info->tx_desc);
|
||||
return -ENOMEM;
|
||||
} else if (info->rx_desc && !info->tx_desc) {
|
||||
if (!info->rx_desc) {
|
||||
printf("Fail to alloc DMA descript!\n");
|
||||
kfree(info->tx_desc);
|
||||
return -ENOMEM;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user