[PATCH] staging: comedi: drivers: prevent memory leak

Navid Emamdoost navid.emamdoost at gmail.com
Tue Sep 17 02:41:43 UTC 2019


In das1800_attach, the buffer allocated via kmalloc_array needs to be
released if an error happens.

Signed-off-by: Navid Emamdoost <navid.emamdoost at gmail.com>
---
 drivers/staging/comedi/drivers/das1800.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index f16aa7e9f4f3..5f2d5f7a6229 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -1237,12 +1237,16 @@ static int das1800_attach(struct comedi_device *dev,
 
 	dev->pacer = comedi_8254_init(dev->iobase + DAS1800_COUNTER,
 				      I8254_OSC_BASE_5MHZ, I8254_IO8, 0);
-	if (!dev->pacer)
+	if (!dev->pacer) {
+		kfree(devpriv->fifo_buf);
 		return -ENOMEM;
+	}
 
 	ret = comedi_alloc_subdevices(dev, 4);
-	if (ret)
+	if (ret) {
+		kfree(devpriv->fifo_buf);
 		return ret;
+	}
 
 	/*
 	 * Analog Input subdevice
@@ -1290,8 +1294,10 @@ static int das1800_attach(struct comedi_device *dev,
 		s->insn_write	= das1800_ao_insn_write;
 
 		ret = comedi_alloc_subdev_readback(s);
-		if (ret)
+		if (ret) {
+			kfree(devpriv->fifo_buf);
 			return ret;
+		}
 
 		/* initialize all channels to 0V */
 		for (i = 0; i < s->n_chan; i++) {
-- 
2.17.1



More information about the devel mailing list