Fix a memory leak where the mempool created by mempool_create_kmalloc_pool()
is not destroyed when dma_request_chan() fails for the rx1 channel.

The mempool is allocated at the beginning of sa_dma_init() with 64 elements
of 512 bytes each. When dma_request_chan("rx1") fails, the function returns
directly without calling mempool_destroy(), leaking 32KB of memory.

This issue was detected by kmemleak showing 40+ unreferenced 512-byte objects
with the following backtrace:
  mempool_create_node_noprof+0xa0/0xf8
  sa_ul_probe+0xf4/0x538
  platform_probe+0x70/0xe8

The fix changes the error handling to use goto err_dma_coerce, ensuring
mempool_destroy() is called in the cleanup path.

Signed-off-by: Xulin Sun <[email protected]>
---
 drivers/crypto/sa2ul.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 093b67ac120b..6cbd0bad889c 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -3393,9 +3393,11 @@ static int sa_dma_init(struct sa_crypto_data *dev_data)
                goto err_dma_coerce;
 
        dev_data->dma_rx1 = dma_request_chan(dev_data->dev, "rx1");
-       if (IS_ERR(dev_data->dma_rx1))
-               return dev_err_probe(dev_data->dev, PTR_ERR(dev_data->dma_rx1),
-                                    "Unable to request rx1 DMA channel\n");
+       if (IS_ERR(dev_data->dma_rx1)) {
+               ret = dev_err_probe(dev_data->dev, PTR_ERR(dev_data->dma_rx1),
+                                   "Unable to request rx1 DMA channel\n");
+               goto err_dma_coerce;
+       }
 
        dev_data->dma_rx2 = dma_request_chan(dev_data->dev, "rx2");
        if (IS_ERR(dev_data->dma_rx2)) {
-- 
2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16180): 
https://lists.yoctoproject.org/g/linux-yocto/message/16180
Mute This Topic: https://lists.yoctoproject.org/mt/117257664/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to