Skip to contentSkip to conversation

ppdev: don't print a free'd string

PATCH In review Colin King 3 participants 3 messages Dec 2, 2016 – Dec 8, 2016

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 ppdev: don't print a free'd string

From: Colin Ian King <[email protected]>

A previous fix of a memory leak now prints the string 'name' that was previously free'd. Fix this by free'ing the string at the end of the function and adding an error exit path for the error conditions.

CoverityScan CID#1384523 ("Use after free")

Fixes 2bd362d5f45c1 ("ppdev: fix memory leak")
---
 drivers/char/ppdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/char/ppdev.c +8 -5
index 02819e0..4cf6d68 100644
@@ -290,6 +290,7 @@ static int register_device(int minor, struct pp_struct *pp)
 	struct pardevice *pdev = NULL;
 	char *name;
 	struct pardev_cb ppdev_cb;
+	int rc = 0;
 
 	name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
 	if (name == NULL)
@@ -298,8 +299,8 @@ static int register_device(int minor, struct pp_struct *pp)
 	port = parport_find_number(minor);
 	if (!port) {
 		pr_warn("%s: no associated port!\n", name);
-		kfree(name);
-		return -ENXIO;
+		rc = -ENXIO;
+		goto err;
 	}
 
 	memset(&ppdev_cb, 0, sizeof(ppdev_cb));
@@ -308,16 +309,18 @@ static int register_device(int minor, struct pp_struct *pp)
 	ppdev_cb.private = pp;
 	pdev = parport_register_dev_model(port, name, &ppdev_cb, minor);
 	parport_put_port(port);
-	kfree(name);
 
 	if (!pdev) {
 		pr_warn("%s: failed to register device!\n", name);
-		return -ENXIO;
+		rc = -ENXIO;
+		goto err;
 	}
 
 	pp->pdev = pdev;
 	dev_dbg(&pdev->dev, "registered pardevice\n");
-	return 0;
+err:
+	kfree(name);
+	return rc;
 }
 
 static enum ieee1284_phase init_phase(int mode)
Signature · 1 line
2.10.2
#1 lore raw
Quoted 7 lines · Colin King

From: Colin Ian King <[email protected]>

A previous fix of a memory leak now prints the string 'name' that was previously free'd. Fix this by free'ing the string at the end of the function and adding an error exit path for the error conditions.

Quoted 7 lines

CoverityScan CID#1384523 ("Use after free")

Fixes 2bd362d5f45c1 ("ppdev: fix memory leak")
---
 drivers/char/ppdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Sudip, any thoughts?

maintainer Acked-by
#2 lore raw
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

A previous fix of a memory leak now prints the string 'name' that was previously free'd. Fix this by free'ing the string at the end of the function and adding an error exit path for the error conditions.

CoverityScan CID#1384523 ("Use after free")

Quoted 8 lines
Quoted 5 lines
Fixes 2bd362d5f45c1 ("ppdev: fix memory leak")
---
  drivers/char/ppdev.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)

Sudip, any thoughts?

Hi Greg,

Sorry for the late reply. It looks good.

Regards
Sudip