linux/drivers/staging/gpib
Zilin Guan 9c97fcfb7a gpib: Fix memory leak in ni_usb_init()
[ Upstream commit b89921eed8 ]

In ni_usb_init(), if ni_usb_setup_init() fails, the function returns
-EFAULT without freeing the allocated writes buffer, leading to a
memory leak.

Additionally, ni_usb_setup_init() returns 0 on failure, which causes
ni_usb_init() to return -EFAULT, an inappropriate error code for this
situation.

Fix the leak by freeing writes in the error path. Modify
ni_usb_setup_init() to return -EINVAL on failure and propagate this
error code in ni_usb_init().

Fixes: 4e127de14f ("staging: gpib: Add National Instruments USB GPIB driver")
Suggested-by: Greg KH <gregkh@linuxfoundation.org>
Suggested-by: Dave Penkler <dpenkler@gmail.com>
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Link: https://patch.msgid.link/20251230034546.929452-1-zilin@seu.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-02-26 14:59:33 -08:00
..
agilent_82350b staging: gpib: Fix no EOI on 1 and 2 byte writes 2025-10-13 10:53:52 +02:00
agilent_82357a staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
cb7210 staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
cec staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
common gpib: Fix error code in ibonline() 2026-02-26 14:59:33 -08:00
eastwood staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
fmh_gpib staging: gpib: Fix device reference leak in fmh_gpib driver 2025-10-13 10:55:03 +02:00
gpio staging: gpib: use int type to store negative error codes 2025-09-06 15:55:35 +02:00
hp_82335 staging: gpib: Add return value to request_control 2025-04-18 16:49:00 +02:00
hp_82341 staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
include staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
ines staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
lpvo_usb_gpib staging: gpib: lpvo_usb_gpib: Remove unreachable return statement 2025-07-09 13:11:35 +02:00
nec7210 staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
ni_usb gpib: Fix memory leak in ni_usb_init() 2026-02-26 14:59:33 -08:00
pc2 staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
tms9914 staging: gpib: tidy-up comments 2025-08-19 12:58:19 +02:00
tnt4882 staging: gpib: tnt4882: Remove redundant header files 2025-09-06 15:54:23 +02:00
uapi staging: gpib: Add bit and byte padding to ioctl structs 2025-06-19 17:32:32 +02:00
Kconfig staging: gpib: Remove dependencies on !X86_PAE 2025-02-19 16:47:25 +01:00
Makefile staging: gpib: Replace custom debug with dev_dbg 2024-11-07 09:27:34 +01:00
TODO staging: gpib: Update TODO 2025-06-19 17:31:52 +02:00