[PATCH] gpib: tnt4882: fix memory leak on probe failure

From: Guangshuo Li

Date: Sun Sep 13 2026 - 02:37:40 EST


ni_gpib_probe() allocates a local_info_t structure and stores it in
link->priv before calling ni_gpib_config().

If ni_gpib_config() fails, it calls ni_gpib_release(), which only
disables the PCMCIA device and does not free the local_info_t
structure. Since probe then returns an error, the remove callback is
not called and the allocation is leaked.

Handle the configuration failure in ni_gpib_probe() by freeing the
local_info_t structure and clearing link->priv before returning the
error.

This issue was found by manual code inspection.

Fixes: 0cd5b05551e02 ("staging: gpib: Add TNT4882 chip based GPIB driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/gpib/tnt4882/tnt4882_gpib.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpib/tnt4882/tnt4882_gpib.c b/drivers/gpib/tnt4882/tnt4882_gpib.c
index 3cd13f637ed4..fc201ad17e30 100644
--- a/drivers/gpib/tnt4882/tnt4882_gpib.c
+++ b/drivers/gpib/tnt4882/tnt4882_gpib.c
@@ -1585,7 +1585,13 @@ static int ni_gpib_probe(struct pcmcia_device *link)

/* Register with Card Services */
curr_dev = link;
- return ni_gpib_config(link);
+ ret = ni_gpib_config(link);
+ if (ret) {
+ kfree(info);
+ link->priv = NULL;
+ }
+
+ return ret;
}

/*
--
2.43.0