Skip to content

Commit

Permalink
staging: comedi: unioxx5: use comedi_alloc_spriv()
Browse files Browse the repository at this point in the history
Use the helper function to allocate the memory and set the subdevice
private pointer. This allows the core to automatically free the
memory during the detach so the driver doesn't need to deal with it.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jun 24, 2013
1 parent 7f5ac6f commit fbd8833
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions drivers/staging/comedi/drivers/unioxx5.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,13 @@ static int __unioxx5_subdev_init(struct comedi_device *dev,
int i, to, ndef_flag = 0;
int ret;

usp = kzalloc(sizeof(*usp), GFP_KERNEL);
if (usp == NULL)
usp = comedi_alloc_spriv(s, sizeof(*usp));
if (!usp)
return -ENOMEM;

ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE);
if (ret) {
kfree(usp);
if (ret)
return ret;
}
usp->usp_iobase = iobase;

/* defining modules types */
Expand Down Expand Up @@ -413,7 +411,6 @@ static int __unioxx5_subdev_init(struct comedi_device *dev,

/* initial subdevice for digital or analog i/o */
s->type = COMEDI_SUBD_DIO;
s->private = usp;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = UNIOXX5_NUM_OF_CHANS;
s->maxdata = 0xFFF;
Expand Down Expand Up @@ -483,7 +480,6 @@ static void unioxx5_detach(struct comedi_device *dev)
spriv = s->private;
if (spriv && spriv->usp_iobase)
release_region(spriv->usp_iobase, UNIOXX5_SIZE);
kfree(spriv);
}
}

Expand Down

0 comments on commit fbd8833

Please sign in to comment.