dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] dmaengine: qcom: Fix possible memory leak
@ 2021-06-17  8:20 Zhen Lei
  0 siblings, 0 replies; only message in thread
From: Zhen Lei @ 2021-06-17  8:20 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Vinod Koul, linux-arm-msm,
	dmaengine, linux-kernel
  Cc: Zhen Lei

When krealloc() fails to expand the memory and returns NULL, the original
memory is not released. In addition, subsequent memcpy() operation will
overwrite the entire valid memory space, so using krealloc() to preserve
the old content is not necessary.

Change to release the old memory and then apply for new memory.

Fixes: 5d0c3533a19f ("dmaengine: qcom: Add GPI dma driver")
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/dma/qcom/gpi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
index 43ac3ab23d4c..e24fe64f3b63 100644
--- a/drivers/dma/qcom/gpi.c
+++ b/drivers/dma/qcom/gpi.c
@@ -1625,7 +1625,8 @@ gpi_peripheral_config(struct dma_chan *chan, struct dma_slave_config *config)
 	if (!config->peripheral_config)
 		return -EINVAL;
 
-	gchan->config = krealloc(gchan->config, config->peripheral_size, GFP_NOWAIT);
+	kfree(gchan->config);
+	gchan->config = kmalloc(config->peripheral_size, GFP_NOWAIT);
 	if (!gchan->config)
 		return -ENOMEM;
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-17  8:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17  8:20 [PATCH 1/1] dmaengine: qcom: Fix possible memory leak Zhen Lei

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).