Skip to contentSkip to conversation

staging/comedi/drivers: free allocated priv and release resources if comedi_alloc_subdevices

PATCH In review Devendra Naga 2 participants 4 messages Jul 1, 2012 – Jul 2, 2012 1 message not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH v3 2/2 staging/comedi/drivers: free allocated priv and release resources if comedi_alloc_subdevices

as comedi_alloc_subdevices may fail, we leak out the memory allocated by alloc_private, and also the I/O regions we requested.

free out the private data pointer of the driver, and release the I/O regions

---
 drivers/staging/comedi/drivers/fl512.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/comedi/drivers/fl512.c +4 -1
index 52e6d14..1c372d1 100644
@@ -135,8 +135,11 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 #endif
 
 	ret = comedi_alloc_subdevices(dev, 2);
-	if (ret)
+	if (ret) {
+		kfree(dev->private);
+		release_region(iobase, FL512_SIZE);
 		return ret;
+	}
 
 	/*
 	 * this if the definitions of the supdevices, 2 have been defined
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 18 lines · Devendra Naga

as comedi_alloc_subdevices may fail, we leak out the memory allocated by alloc_private, and also the I/O regions we requested.

free out the private data pointer of the driver, and release the I/O regions

---
  drivers/staging/comedi/drivers/fl512.c |    5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/comedi/drivers/fl512.c +0 -0
index 52e6d14..1c372d1 100644
@@ -135,8 +135,11 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  #endif
 

drivers/staging/comedi/drivers/fl512.c static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it) · line 145

Quoted 10 lines
drivers/staging/comedi/drivers/fl512.c +4 -1
  	ret = comedi_alloc_subdevices(dev, 2);
-	if (ret)
+	if (ret) {
+		kfree(dev->private);
+		release_region(iobase, FL512_SIZE);
  		return ret;
+	}
 
  	/*
  	 * this if the definitions of the supdevices, 2 have been defined

As mentioned in my comment for your PATCH 1/2, this is unneccessary. In fact it will resuly in dev->private being freed twice and the I/O region being released twice due to clean-up in the comedi core when fl512_attach() returns an error, which will also call fl512_detach() during the clean-up.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
#2 lore raw
Quoted 40 lines · Ian Abbott
Quoted 31 lines · Devendra Naga

as comedi_alloc_subdevices may fail, we leak out the memory allocated by alloc_private,
and also the I/O regions we requested.

free out the private data pointer of the driver, and release the I/O regions

---
  drivers/staging/comedi/drivers/fl512.c |    5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/comedi/drivers/fl512.c +4 -1
index 52e6d14..1c372d1 100644
@@ -135,8 +135,11 @@ static int fl512_attach(struct comedi_device *dev,
 struct comedi_devconfig *it)
  #endif
 
        ret = comedi_alloc_subdevices(dev, 2);
-       if (ret)
+       if (ret) {
+               kfree(dev->private);
+               release_region(iobase, FL512_SIZE);
                return ret;
+       }
 
        /*
Quoted 2 lines

* this if the definitions of the supdevices, 2 have been defined

As mentioned in my comment for your PATCH 1/2, this is unneccessary. In fact it will resuly in dev->private being freed twice and the I/O region being released twice due to clean-up in the comedi core when fl512_attach() returns an error, which will also call fl512_detach() during the clean-up.

Quoted 5 lines

--
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

Ok, sorry for the heavy noise caused by these patches :(.

anyway i have a question

are you going to remove the alloc_private wapper and use kzalloc?

Thanks,
Devendra.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 9 lines · Ian Abbott
Quoted 4 lines · devendra.aaru

anyway i have a question

are you going to remove the alloc_private wapper and use kzalloc?

I'm not averse to the idea, but it's not a high priority.

Then will i do? and change all drivers?
I dunno about any other guys doing it ...

Quoted 6 lines

--
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

Thanks,
Devendra.