Re: [PATCH 1/2] staging: comedi: unioxx5: fix unioxx5_detach()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[Originally posted 2013-06-25.  Reposting to new driverdev-devel list.]

On 2013-06-25 00:23, H Hartley Sweeten wrote:
During the attach of this driver, it's possible for the allocation
of the subdevice private data to fail. It's also possible that the
io region was not successfully requested.

Validate the pointer and iobase before trying to release the region.

For aesthetic reasons, rename the local variables.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  drivers/staging/comedi/drivers/unioxx5.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c
index d05d46d..fc88b66 100644
--- a/drivers/staging/comedi/drivers/unioxx5.c
+++ b/drivers/staging/comedi/drivers/unioxx5.c
@@ -474,15 +474,16 @@ static int unioxx5_attach(struct comedi_device *dev,

  static void unioxx5_detach(struct comedi_device *dev)
  {
+	struct comedi_subdevice *s;
+	struct unioxx5_subd_priv *spriv;
  	int i;
-	struct comedi_subdevice *subdev;
-	struct unioxx5_subd_priv *usp;

  	for (i = 0; i < dev->n_subdevices; i++) {
-		subdev = &dev->subdevices[i];
-		usp = subdev->private;
-		release_region(usp->usp_iobase, UNIOXX5_SIZE);
-		kfree(subdev->private);
+		s = &dev->subdevices[i];
+		spriv = s->private;
+		if (spriv && spriv->usp_iobase)

I don't think it's necessary to check spriv->usp_iobase here yet, but it's harmless here, and is needed after using comedi_spriv_alloc() in the patch 2, so it's okay.

+			release_region(spriv->usp_iobase, UNIOXX5_SIZE);
+		kfree(spriv);
  	}
  }

Reviewed-by: Ian Abbott <abbotti@xxxxxxxxx>

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux