int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
{
+ struct comedi_subdevice *s;
int i;
if (num_subdevices < 1)
return -EINVAL;
- dev->subdevices =
- kcalloc(num_subdevices, sizeof(struct comedi_subdevice),
- GFP_KERNEL);
- if (!dev->subdevices)
+
+ s = kcalloc(num_subdevices, sizeof(*s), GFP_KERNEL);
+ if (!s)
return -ENOMEM;
+ dev->subdevices = s;
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;
- spin_lock_init(&dev->subdevices[i].spin_lock);
- dev->subdevices[i].minor = -1;
+ s = dev->subdevices + i;
+ s->device = dev;
+ s->async_dma_dir = DMA_NONE;
+ spin_lock_init(&s->spin_lock);
+ s->minor = -1;
}
return 0;
}