diff mbox series

fpga: dfl: fix potential memory leak in vfio_intx_enable()

Message ID 20240623074019.2083481-1-make24@iscas.ac.cn (mailing list archive)
State New
Headers show
Series fpga: dfl: fix potential memory leak in vfio_intx_enable() | expand

Commit Message

Ma Ke June 23, 2024, 7:40 a.m. UTC
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(-)

Comments

Markus Elfring June 23, 2024, 12:52 p.m. UTC | #1
> 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
Russ Weight June 24, 2024, 5:58 p.m. UTC | #2
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
>
diff mbox series

Patch

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