[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251228081926.3503643-1-zilin@seu.edu.cn>
Date: Sun, 28 Dec 2025 08:19:26 +0000
From: Zilin Guan <zilin@....edu.cn>
To: dpenkler@...il.com
Cc: gregkh@...uxfoundation.org,
matchstick@...erthere.org,
mingo@...nel.org,
tglx@...utronix.de,
linux-kernel@...r.kernel.org,
jianhao.xu@....edu.cn,
Zilin Guan <zilin@....edu.cn>
Subject: [PATCH] staging: gpib: Fix memory leak in ni_usb_init()
In ni_usb_init(), if ni_usb_setup_init() fails, the function returns
immediately without freeing the allocated memory for writes, leading
to a memory leak.
Fix this by jumping to the out label to ensure the memory is properly
freed.
Fixes: 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver")
Co-developed-by: Jianhao Xu <jianhao.xu@....edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@....edu.cn>
Signed-off-by: Zilin Guan <zilin@....edu.cn>
---
drivers/gpib/ni_usb/ni_usb_gpib.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpib/ni_usb/ni_usb_gpib.c b/drivers/gpib/ni_usb/ni_usb_gpib.c
index 1f8412de9fa3..4cf45e94c750 100644
--- a/drivers/gpib/ni_usb/ni_usb_gpib.c
+++ b/drivers/gpib/ni_usb/ni_usb_gpib.c
@@ -1802,7 +1802,7 @@ static int ni_usb_init(struct gpib_board *board)
if (writes_len)
retval = ni_usb_write_registers(ni_priv, writes, writes_len, &ibsta);
else
- return -EFAULT;
+ goto out;
kfree(writes);
if (retval) {
dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
@@ -1810,6 +1810,10 @@ static int ni_usb_init(struct gpib_board *board)
}
ni_usb_soft_update_status(board, ibsta, 0);
return 0;
+
+out:
+ kfree(writes);
+ return -EFAULT;
}
static void ni_usb_interrupt_complete(struct urb *urb)
--
2.34.1
Powered by blists - more mailing lists