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

Guangshuo Li posted 1 patch 1 week, 5 days ago
drivers/gpib/ines/ines_gpib.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[PATCH] gpib: ines: fix memory leak on probe failure
Posted by Guangshuo Li 1 week, 5 days ago
ines_gpib_probe() allocates a local_info structure and stores it in
link->priv before calling ines_gpib_config().

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

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

This issue was found by manual code inspection.

Fixes: bb1bd92fa0f2c ("staging: gpib: Add ines GPIB driver")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/gpib/ines/ines_gpib.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpib/ines/ines_gpib.c b/drivers/gpib/ines/ines_gpib.c
index 6cd6ff596fda..6d09dff5e797 100644
--- a/drivers/gpib/ines/ines_gpib.c
+++ b/drivers/gpib/ines/ines_gpib.c
@@ -1143,6 +1143,7 @@ struct local_info {
 static int ines_gpib_probe(struct pcmcia_device *link)
 {
 	struct local_info *info;
+	int ret;
 
 //	int ret, i;
 
@@ -1165,7 +1166,13 @@ static int ines_gpib_probe(struct pcmcia_device *link)
 
 	/* Register with Card Services */
 	curr_dev = link;
-	return ines_gpib_config(link);
+	ret = ines_gpib_config(link);
+	if (ret) {
+		kfree(info);
+		link->priv = NULL;
+	}
+
+	return ret;
 }
 
 /*
-- 
2.43.0