It's possible for the kcalloc in comedi_alloc_subdevices to fail.
Only set the dev->n_subdevices variable if the allocation is
successful.
Since the core sets dev->n_subdevices, remove all the places in the
drivers where this variable was getting set.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbott@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
if (num_subdevices < 1)
return -EINVAL;
- dev->n_subdevices = num_subdevices;
dev->subdevices =
kcalloc(num_subdevices, sizeof(struct comedi_subdevice),
GFP_KERNEL);
if (!dev->subdevices)
return -ENOMEM;
+ dev->n_subdevices = num_subdevices;
for (i = 0; i < num_subdevices; ++i) {
dev->subdevices[i].device = dev;
dev->subdevices[i].async_dma_dir = DMA_NONE;
devpriv->uvolt_amplitude = amplitude;
devpriv->usec_period = period;
- dev->n_subdevices = 2;
- if (comedi_alloc_subdevices(dev, dev->n_subdevices) < 0)
+ if (comedi_alloc_subdevices(dev, 2) < 0)
return -ENOMEM;
s = dev->subdevices + 0;
printk(KERN_INFO " %s ", dev->board_name);
- dev->n_subdevices = 2 + NI_660X_MAX_NUM_COUNTERS;
-
- if (comedi_alloc_subdevices(dev, dev->n_subdevices) < 0)
+ if (comedi_alloc_subdevices(dev, 2 + NI_660X_MAX_NUM_COUNTERS) < 0)
return -ENOMEM;
s = dev->subdevices + 0;
* Allocate the subdevice structures. alloc_subdevice() is a
* convenient macro defined in comedidev.h.
*/
- dev->n_subdevices = 4;
- if (comedi_alloc_subdevices(dev, dev->n_subdevices) < 0)
+ if (comedi_alloc_subdevices(dev, 4) < 0)
return -ENOMEM;
s = dev->subdevices + 0;
{
int ret;
struct comedi_subdevice *s = NULL;
+ int n_subdevs;
down(&udev->sem);
/* pointer back to the corresponding comedi device */
/* set number of subdevices */
if (udev->high_speed) {
/* with pwm */
- dev->n_subdevices = 5;
+ n_subdevs = 5;
} else {
/* without pwm */
- dev->n_subdevices = 4;
+ n_subdevs = 4;
}
/* allocate space for the subdevices */
- ret = comedi_alloc_subdevices(dev, dev->n_subdevices);
+ ret = comedi_alloc_subdevices(dev, n_subdevs);
if (ret < 0) {
dev_err(&udev->interface->dev,
"comedi%d: error alloc space for subdev\n", dev->minor);
*/
#define NUMUSBDUXFAST 16
-/*
- * number of subdevices
- */
-#define N_SUBDEVICES 1
-
/*
* analogue in subdevice
*/
dev->board_name = BOARDNAME;
- /* set number of subdevices */
- dev->n_subdevices = N_SUBDEVICES;
-
/* allocate space for the subdevices */
- ret = comedi_alloc_subdevices(dev, N_SUBDEVICES);
+ ret = comedi_alloc_subdevices(dev, 1);
if (ret < 0) {
printk(KERN_ERR "comedi%d: usbduxfast: error alloc space for "
"subdev\n", dev->minor);
int index;
int i;
struct usbduxsub *udev;
+ int n_subdevs;
int offset;
/* set number of subdevices */
if (udev->high_speed) {
/* with pwm */
- dev->n_subdevices = 4;
+ n_subdevs = 4;
} else {
/* without pwm */
- dev->n_subdevices = 3;
+ n_subdevs = 3;
}
/* allocate space for the subdevices */
- ret = comedi_alloc_subdevices(dev, dev->n_subdevices);
+ ret = comedi_alloc_subdevices(dev, n_subdevs);
if (ret < 0) {
dev_err(&udev->interface->dev,
"comedi%d: no space for subdev\n", dev->minor);