aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH Hartley Sweeten <[email protected]>2016-03-22 11:10:45 -0700
committerGreg Kroah-Hartman <[email protected]>2016-03-28 07:30:36 -0700
commitf229594a327720c0761e7307a5472aea780268c3 (patch)
treef9bdb4f7f13edb694fd2c8b1dcf584305ddd9569
parent2363cbf073225537016aceb6bf122bbee6a0caa0 (diff)
staging: comedi: ni_660x: allocate counters early in (*auto_attach)
The ni_gpct_device_construct() could fail allocating the memory for device and its counters. For aesthetics, call the function before initializing the subdevices. Signed-off-by: H Hartley Sweeten <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index afe62bf2de8b..636630380100 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -914,6 +914,16 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_init_tio_chips(dev, board->n_chips);
+ n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
+ gpct_dev = ni_gpct_device_construct(dev,
+ ni_660x_gpct_write,
+ ni_660x_gpct_read,
+ ni_gpct_variant_660x,
+ n_counters);
+ if (!gpct_dev)
+ return -ENOMEM;
+ devpriv->counter_dev = gpct_dev;
+
ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
@@ -986,16 +996,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits = ni_660x_dio_insn_bits;
s->insn_config = ni_660x_dio_insn_config;
- n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
- gpct_dev = ni_gpct_device_construct(dev,
- ni_660x_gpct_write,
- ni_660x_gpct_read,
- ni_gpct_variant_660x,
- n_counters);
- if (!gpct_dev)
- return -ENOMEM;
- devpriv->counter_dev = gpct_dev;
-
/* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];