All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable()
@ 2024-06-23  7:40 Ma Ke
  2024-06-23 12:52 ` Markus Elfring
  2024-06-24 17:58 ` Russ Weight
  0 siblings, 2 replies; 3+ messages in thread
From: Ma Ke @ 2024-06-23  7:40 UTC (permalink / raw)
  To: hao.wu, trix, mdf, yilun.xu; +Cc: linux-fpga, linux-kernel, Ma Ke

We should free 'feature->irq_ctx[idx].name' to avoid 'name'
memory leak when request_irq() failed.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/fpga/dfl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 094ee97ea26c..c52ebece5aef 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1911,7 +1911,7 @@ static int do_set_irq_trigger(struct dfl_feature *feature, unsigned int idx,
 			  feature->irq_ctx[idx].name, trigger);
 	if (!ret) {
 		feature->irq_ctx[idx].trigger = trigger;
-		return ret;
+		goto free_name;
 	}
 
 	eventfd_ctx_put(trigger);
-- 
2.25.1


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

* Re: [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable()
  2024-06-23  7:40 [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable() Ma Ke
@ 2024-06-23 12:52 ` Markus Elfring
  2024-06-24 17:58 ` Russ Weight
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-06-23 12:52 UTC (permalink / raw)
  To: Ma Ke, linux-fpga, Moritz Fischer, Tom Rix, Wu Hao, Xu Yilun; +Cc: LKML

> We should free 'feature->irq_ctx[idx].name' to avoid 'name'
> memory leak when request_irq() failed.

1. Please choose an imperative wording for an improved change description.
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc4#n94

2. Would you like to add any tags (like “Fixes” and “Cc”) accordingly?

3. How do you think about to use a summary phrase like “Avoid memory leak
   in do_set_irq_trigger()”?

4. Under which circumstances will development interests grow for increasing
   the application of scope-based resource management?
   https://elixir.bootlin.com/linux/v6.10-rc4/source/include/linux/cleanup.h#L8


Regards,
Markus

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

* Re: [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable()
  2024-06-23  7:40 [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable() Ma Ke
  2024-06-23 12:52 ` Markus Elfring
@ 2024-06-24 17:58 ` Russ Weight
  1 sibling, 0 replies; 3+ messages in thread
From: Russ Weight @ 2024-06-24 17:58 UTC (permalink / raw)
  To: Ma Ke; +Cc: hao.wu, trix, mdf, yilun.xu, linux-fpga, linux-kernel


On Sun, Jun 23, 2024 at 03:40:19PM +0800, Ma Ke wrote:
> We should free 'feature->irq_ctx[idx].name' to avoid 'name'
> memory leak when request_irq() failed.
> 
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/fpga/dfl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 094ee97ea26c..c52ebece5aef 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -1911,7 +1911,7 @@ static int do_set_irq_trigger(struct dfl_feature *feature, unsigned int idx,
>  			  feature->irq_ctx[idx].name, trigger);
>  	if (!ret) {
>  		feature->irq_ctx[idx].trigger = trigger;
> -		return ret;
> +		goto free_name;

I believe (!ret) represents the success case and that simply
returning is the right thing to do. In the case of an error,
eventfd_ctx_put() and kfree() are both called.

>  	}
>  
>  	eventfd_ctx_put(trigger);
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2024-06-24 17:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-23  7:40 [PATCH] fpga: dfl: fix potential memory leak in vfio_intx_enable() Ma Ke
2024-06-23 12:52 ` Markus Elfring
2024-06-24 17:58 ` Russ Weight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.