Skip to contentSkip to conversation

input: adxl34x: fix leak and use after free

PATCH Applied Dan Carpenter 2 participants 2 messages Jul 22, 2010 – Jul 23, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: adxl34x: fix leak and use after free

These are a couple smatch issues. In the original code, if only one of the allocation fails we leak the other variable so we should goto out_free_mem.

Also there was a use after free if debugging was enabled and so I moved the kfree() down a line.

drivers/input/misc/adxl34x.c +2 -2
index bb9c10f..e925d12 100644
@@ -709,7 +709,7 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 	input_dev = input_allocate_device();
 	if (!ac || !input_dev) {
 		err = -ENOMEM;
-		goto err_out;
+		goto err_free_mem;
 	}
 
 	ac->fifo_delay = fifo_delay_default;
@@ -904,9 +904,9 @@ int adxl34x_remove(struct adxl34x *ac)
 	sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group);
 	free_irq(ac->irq, ac);
 	input_unregister_device(ac->input);
+	dev_dbg(ac->dev, "unregistered accelerometer\n");
 	kfree(ac);
 
-	dev_dbg(ac->dev, "unregistered accelerometer\n");
 	return 0;
 }
 EXPORT_SYMBOL_GPL(adxl34x_remove);
maintainer Applied
#1 lore raw
Quoted 9 lines · Dan Carpenter

These are a couple smatch issues. In the original code, if only one of the allocation fails we leak the other variable so we should goto out_free_mem.

Also there was a use after free if debugging was enabled and so I moved the kfree() down a line.

Applied, thanks Dan.

Quoted 24 lines
drivers/input/misc/adxl34x.c +2 -2
index bb9c10f..e925d12 100644
@@ -709,7 +709,7 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 	input_dev = input_allocate_device();
 	if (!ac || !input_dev) {
 		err = -ENOMEM;
-		goto err_out;
+		goto err_free_mem;
 	}
 
 	ac->fifo_delay = fifo_delay_default;
@@ -904,9 +904,9 @@ int adxl34x_remove(struct adxl34x *ac)
 	sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group);
 	free_irq(ac->irq, ac);
 	input_unregister_device(ac->input);
+	dev_dbg(ac->dev, "unregistered accelerometer\n");
 	kfree(ac);
 
-	dev_dbg(ac->dev, "unregistered accelerometer\n");
 	return 0;
 }
 EXPORT_SYMBOL_GPL(adxl34x_remove);
Signature · 1 line
Dmitry