mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table()
@ 2024-10-24 21:47 Youssef Samir
  2024-10-24 21:48 ` Jeffrey Hugo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Youssef Samir @ 2024-10-24 21:47 UTC (permalink / raw)
  To: manivannan.sadhasivam; +Cc: mhi, linux-arm-msm, linux-kernel, Jeffrey Hugo

mhi_alloc_bhie_table() starts by allocating a vector of struct mhi_buf
then it allocates a DMA buffer for each element. If allocation fails,
it will free the allocated DMA buffers, but it neglects freeing the
mhi_buf vector.

Avoid memory leaks by freeing the mhi_buf vector on error.

Fixes: 3000f85b8f47 ("bus: mhi: core: Add support for basic PM operations")
Signed-off-by: Youssef Samir <quic_yabdulra@quicinc.com>
Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
---
 drivers/bus/mhi/host/boot.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
index 21bf042db9be..2e9ef55a566a 100644
--- a/drivers/bus/mhi/host/boot.c
+++ b/drivers/bus/mhi/host/boot.c
@@ -415,6 +415,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
 	for (--i, --mhi_buf; i >= 0; i--, mhi_buf--)
 		dma_free_coherent(mhi_cntrl->cntrl_dev, mhi_buf->len,
 				  mhi_buf->buf, mhi_buf->dma_addr);
+	kfree(img_info->mhi_buf);
 
 error_alloc_mhi_buf:
 	kfree(img_info);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table()
  2024-10-24 21:47 [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table() Youssef Samir
@ 2024-10-24 21:48 ` Jeffrey Hugo
  2024-11-15  6:06 ` Manivannan Sadhasivam
  2024-11-15  6:07 ` Manivannan Sadhasivam
  2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Hugo @ 2024-10-24 21:48 UTC (permalink / raw)
  To: Youssef Samir, manivannan.sadhasivam; +Cc: mhi, linux-arm-msm, linux-kernel

On 10/24/2024 3:47 PM, Youssef Samir wrote:
> mhi_alloc_bhie_table() starts by allocating a vector of struct mhi_buf
> then it allocates a DMA buffer for each element. If allocation fails,
> it will free the allocated DMA buffers, but it neglects freeing the
> mhi_buf vector.
> 
> Avoid memory leaks by freeing the mhi_buf vector on error.
> 
> Fixes: 3000f85b8f47 ("bus: mhi: core: Add support for basic PM operations")
> Signed-off-by: Youssef Samir <quic_yabdulra@quicinc.com>
> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> ---
>   drivers/bus/mhi/host/boot.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
> index 21bf042db9be..2e9ef55a566a 100644
> --- a/drivers/bus/mhi/host/boot.c
> +++ b/drivers/bus/mhi/host/boot.c
> @@ -415,6 +415,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
>   	for (--i, --mhi_buf; i >= 0; i--, mhi_buf--)
>   		dma_free_coherent(mhi_cntrl->cntrl_dev, mhi_buf->len,
>   				  mhi_buf->buf, mhi_buf->dma_addr);
> +	kfree(img_info->mhi_buf);
>   
>   error_alloc_mhi_buf:
>   	kfree(img_info);


Better  :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table()
  2024-10-24 21:47 [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table() Youssef Samir
  2024-10-24 21:48 ` Jeffrey Hugo
@ 2024-11-15  6:06 ` Manivannan Sadhasivam
  2024-11-15  6:07 ` Manivannan Sadhasivam
  2 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2024-11-15  6:06 UTC (permalink / raw)
  To: Youssef Samir; +Cc: mhi, linux-arm-msm, linux-kernel, Jeffrey Hugo

On Thu, Oct 24, 2024 at 11:47:15PM +0200, Youssef Samir wrote:
> mhi_alloc_bhie_table() starts by allocating a vector of struct mhi_buf
> then it allocates a DMA buffer for each element. If allocation fails,
> it will free the allocated DMA buffers, but it neglects freeing the
> mhi_buf vector.
> 
> Avoid memory leaks by freeing the mhi_buf vector on error.
> 
> Fixes: 3000f85b8f47 ("bus: mhi: core: Add support for basic PM operations")
> Signed-off-by: Youssef Samir <quic_yabdulra@quicinc.com>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> ---
>  drivers/bus/mhi/host/boot.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
> index 21bf042db9be..2e9ef55a566a 100644
> --- a/drivers/bus/mhi/host/boot.c
> +++ b/drivers/bus/mhi/host/boot.c
> @@ -415,6 +415,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
>  	for (--i, --mhi_buf; i >= 0; i--, mhi_buf--)
>  		dma_free_coherent(mhi_cntrl->cntrl_dev, mhi_buf->len,
>  				  mhi_buf->buf, mhi_buf->dma_addr);
> +	kfree(img_info->mhi_buf);
>  
>  error_alloc_mhi_buf:
>  	kfree(img_info);
> -- 
> 2.25.1
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table()
  2024-10-24 21:47 [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table() Youssef Samir
  2024-10-24 21:48 ` Jeffrey Hugo
  2024-11-15  6:06 ` Manivannan Sadhasivam
@ 2024-11-15  6:07 ` Manivannan Sadhasivam
  2 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2024-11-15  6:07 UTC (permalink / raw)
  To: Youssef Samir; +Cc: mhi, linux-arm-msm, linux-kernel, Jeffrey Hugo

On Thu, Oct 24, 2024 at 11:47:15PM +0200, Youssef Samir wrote:
> mhi_alloc_bhie_table() starts by allocating a vector of struct mhi_buf
> then it allocates a DMA buffer for each element. If allocation fails,
> it will free the allocated DMA buffers, but it neglects freeing the
> mhi_buf vector.
> 
> Avoid memory leaks by freeing the mhi_buf vector on error.
> 
> Fixes: 3000f85b8f47 ("bus: mhi: core: Add support for basic PM operations")
> Signed-off-by: Youssef Samir <quic_yabdulra@quicinc.com>

Applied to mhi-next!

- Mani

> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> ---
>  drivers/bus/mhi/host/boot.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
> index 21bf042db9be..2e9ef55a566a 100644
> --- a/drivers/bus/mhi/host/boot.c
> +++ b/drivers/bus/mhi/host/boot.c
> @@ -415,6 +415,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
>  	for (--i, --mhi_buf; i >= 0; i--, mhi_buf--)
>  		dma_free_coherent(mhi_cntrl->cntrl_dev, mhi_buf->len,
>  				  mhi_buf->buf, mhi_buf->dma_addr);
> +	kfree(img_info->mhi_buf);
>  
>  error_alloc_mhi_buf:
>  	kfree(img_info);
> -- 
> 2.25.1
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-15  6:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-24 21:47 [PATCH] bus: mhi: host: Free mhi_buf vector inside mhi_alloc_bhie_table() Youssef Samir
2024-10-24 21:48 ` Jeffrey Hugo
2024-11-15  6:06 ` Manivannan Sadhasivam
2024-11-15  6:07 ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®