[PATCH] gpib: ines: Fix resource leak in ines_isa_attach()

Hongling Zeng posted 1 patch 1 week, 4 days ago
drivers/gpib/ines/ines_gpib.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] gpib: ines: Fix resource leak in ines_isa_attach()
Posted by Hongling Zeng 1 week, 4 days ago
When request_irq() fails in ines_isa_attach(), the function returns -1
without releasing the I/O port region that was successfully acquired
earlier by request_region(). This causes a resource leak.

Fix this by adding a proper error path that releases the I/O port
region before returning.

Fixes: 0de51244e7b7e3 ("gpib: ines: use request_region for isa devices")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
Cc: stable@vger.kernel.org
---
 drivers/gpib/ines/ines_gpib.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpib/ines/ines_gpib.c b/drivers/gpib/ines/ines_gpib.c
index c000f647fbb5..1e5112d05dfc 100644
--- a/drivers/gpib/ines/ines_gpib.c
+++ b/drivers/gpib/ines/ines_gpib.c
@@ -911,11 +911,16 @@ static int ines_isa_attach(struct gpib_board *board, const struct gpib_board_con
 	nec7210_board_reset(nec_priv, board);
 	if (request_irq(config->ibirq, ines_pci_interrupt, isr_flags, DRV_NAME, board)) {
 		dev_err(board->gpib_dev, "failed to allocate IRQ %d\n", config->ibirq);
-		return -1;
+		retval = -ENODEV;
+		goto err_release_region;
 	}
 	ines_priv->irq = config->ibirq;
 	ines_online(ines_priv, board, 1);
 	return 0;
+
+err_release_region:
+	release_region(config->ibbase, ines_isa_iosize);
+	return retval;
 }
 
 static void ines_pci_detach(struct gpib_board *board)
-- 
2.25.1
Re: [PATCH] gpib: ines: Fix resource leak in ines_isa_attach()
Posted by Dominik Karol Piątkowski 1 week, 3 days ago
Hi Hongling Zeng,

On Thursday, May 28th, 2026 at 04:03, Hongling Zeng <zenghongling@kylinos.cn> wrote:

> When request_irq() fails in ines_isa_attach(), the function returns -1
> without releasing the I/O port region that was successfully acquired
> earlier by request_region(). This causes a resource leak.
> 
> Fix this by adding a proper error path that releases the I/O port
> region before returning.
> 
> Fixes: 0de51244e7b7e3 ("gpib: ines: use request_region for isa devices")
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpib/ines/ines_gpib.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpib/ines/ines_gpib.c b/drivers/gpib/ines/ines_gpib.c
> index c000f647fbb5..1e5112d05dfc 100644
> --- a/drivers/gpib/ines/ines_gpib.c
> +++ b/drivers/gpib/ines/ines_gpib.c
> @@ -911,11 +911,16 @@ static int ines_isa_attach(struct gpib_board *board, const struct gpib_board_con
>  	nec7210_board_reset(nec_priv, board);
>  	if (request_irq(config->ibirq, ines_pci_interrupt, isr_flags, DRV_NAME, board)) {
>  		dev_err(board->gpib_dev, "failed to allocate IRQ %d\n", config->ibirq);
> -		return -1;
> +		retval = -ENODEV;
> +		goto err_release_region;
>  	}
>  	ines_priv->irq = config->ibirq;
>  	ines_online(ines_priv, board, 1);
>  	return 0;
> +
> +err_release_region:
> +	release_region(config->ibbase, ines_isa_iosize);
> +	return retval;

I see a similar problem to what I've found in fmh_gpib patch:
https://lore.kernel.org/all/LpJShJPaUZ8iZoWRA7Sy9TPz_7ZPHNvoU0lHOBrVEXvQGqlz493ShbF6ZKQ2zcRqPHVuxOkjzR0KCdS6OngnflPYa0gsqaRTpRWFbxuqQ4A=@protonmail.com/

Thanks,
Dominik Karol

>  }
> 
>  static void ines_pci_detach(struct gpib_board *board)
> --
> 2.25.1
> 
>