diff options
Diffstat (limited to 'drivers/staging/comedi/drivers.c')
-rw-r--r-- | drivers/staging/comedi/drivers.c | 82 |
1 files changed, 45 insertions, 37 deletions
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 2359151af7e..1db6bfdbf13 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -71,7 +71,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) dev->n_subdevices = num_subdevices; for (i = 0; i < num_subdevices; ++i) { - s = dev->subdevices + i; + s = &dev->subdevices[i]; s->device = dev; s->async_dma_dir = DMA_NONE; spin_lock_init(&s->spin_lock); @@ -88,7 +88,7 @@ static void cleanup_device(struct comedi_device *dev) if (dev->subdevices) { for (i = 0; i < dev->n_subdevices; i++) { - s = dev->subdevices + i; + s = &dev->subdevices[i]; comedi_free_subdevice_minor(s); if (s->async) { comedi_buf_alloc(dev, s, 0); @@ -119,8 +119,8 @@ static void __comedi_device_detach(struct comedi_device *dev) if (dev->driver) dev->driver->detach(dev); else - printk(KERN_WARNING - "BUG: dev->driver=NULL in comedi_device_detach()\n"); + dev_warn(dev->class_dev, + "BUG: dev->driver=NULL in comedi_device_detach()\n"); cleanup_device(dev); } @@ -142,8 +142,7 @@ static int comedi_device_postconfig(struct comedi_device *dev) return ret; } if (!dev->board_name) { - printk(KERN_WARNING "BUG: dev->board_name=<%p>\n", - dev->board_name); + dev_warn(dev->class_dev, "BUG: dev->board_name=NULL\n"); dev->board_name = "BUG"; } smp_wmb(); @@ -160,10 +159,8 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) return -EBUSY; for (driv = comedi_drivers; driv; driv = driv->next) { - if (!try_module_get(driv->module)) { - printk(KERN_INFO "comedi: failed to increment module count, skipping\n"); + if (!try_module_get(driv->module)) continue; - } if (driv->num_names) { dev->board_ptr = comedi_recognize(driv, it->board_name); if (dev->board_ptr) @@ -176,16 +173,21 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) /* recognize has failed if we get here */ /* report valid board names before returning error */ for (driv = comedi_drivers; driv; driv = driv->next) { - if (!try_module_get(driv->module)) { - printk(KERN_INFO - "comedi: failed to increment module count\n"); + if (!try_module_get(driv->module)) continue; - } comedi_report_boards(driv); module_put(driv->module); } return -EIO; } + if (driv->attach == NULL) { + /* driver does not support manual configuration */ + dev_warn(dev->class_dev, + "driver '%s' does not support attach using comedi_config\n", + driv->driver_name); + module_put(driv->module); + return -ENOSYS; + } /* initialize dev->driver here so * comedi_error() can be called from attach */ dev->driver = driv; @@ -225,8 +227,9 @@ int comedi_driver_unregister(struct comedi_driver *driver) mutex_lock(&dev->mutex); if (dev->attached && dev->driver == driver) { if (dev->use_count) - printk(KERN_WARNING "BUG! detaching device with use_count=%d\n", - dev->use_count); + dev_warn(dev->class_dev, + "BUG! detaching device with use_count=%d\n", + dev->use_count); comedi_device_detach(dev); } mutex_unlock(&dev->mutex); @@ -255,7 +258,7 @@ static int postconfig(struct comedi_device *dev) int ret; for (i = 0; i < dev->n_subdevices; i++) { - s = dev->subdevices + i; + s = &dev->subdevices[i]; if (s->type == COMEDI_SUBD_UNUSED) continue; @@ -273,8 +276,8 @@ static int postconfig(struct comedi_device *dev) async = kzalloc(sizeof(struct comedi_async), GFP_KERNEL); if (async == NULL) { - printk(KERN_INFO - "failed to allocate async struct\n"); + dev_warn(dev->class_dev, + "failed to allocate async struct\n"); return -ENOMEM; } init_waitqueue_head(&async->wait_head); @@ -290,7 +293,8 @@ static int postconfig(struct comedi_device *dev) async->prealloc_buf = NULL; async->prealloc_bufsz = 0; if (comedi_buf_alloc(dev, s, buf_size) < 0) { - printk(KERN_INFO "Buffer allocation failed\n"); + dev_warn(dev->class_dev, + "Buffer allocation failed\n"); return -ENOMEM; } if (s->buf_change) { @@ -370,17 +374,17 @@ static void comedi_report_boards(struct comedi_driver *driv) unsigned int i; const char *const *name_ptr; - printk(KERN_INFO "comedi: valid board names for %s driver are:\n", - driv->driver_name); + pr_info("comedi: valid board names for %s driver are:\n", + driv->driver_name); name_ptr = driv->board_name; for (i = 0; i < driv->num_names; i++) { - printk(KERN_INFO " %s\n", *name_ptr); + pr_info(" %s\n", *name_ptr); name_ptr = (const char **)((char *)name_ptr + driv->offset); } if (driv->num_names == 0) - printk(KERN_INFO " %s\n", driv->driver_name); + pr_info(" %s\n", driv->driver_name); } static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s) @@ -411,7 +415,6 @@ static int insn_rw_emulate_bits(struct comedi_device *dev, new_insn.insn = INSN_BITS; new_insn.chanspec = base_bitfield_channel; new_insn.n = 2; - new_insn.data = new_data; new_insn.subdev = insn->subdev; if (insn->insn == INSN_WRITE) { @@ -584,9 +587,9 @@ static unsigned int comedi_buf_munge(struct comedi_async *async, block_size = num_bytes - count; if (block_size < 0) { - printk(KERN_WARNING - "%s: %s: bug! block_size is negative\n", - __FILE__, __func__); + dev_warn(s->device->class_dev, + "%s: %s: bug! block_size is negative\n", + __FILE__, __func__); break; } if ((int)(async->munge_ptr + block_size - @@ -667,7 +670,8 @@ unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes) { if ((int)(async->buf_write_count + nbytes - async->buf_write_alloc_count) > 0) { - printk(KERN_INFO "comedi: attempted to write-free more bytes than have been write-allocated.\n"); + dev_info(async->subdevice->device->class_dev, + "attempted to write-free more bytes than have been write-allocated.\n"); nbytes = async->buf_write_alloc_count - async->buf_write_count; } async->buf_write_count += nbytes; @@ -703,8 +707,8 @@ unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes) smp_mb(); if ((int)(async->buf_read_count + nbytes - async->buf_read_alloc_count) > 0) { - printk(KERN_INFO - "comedi: attempted to read-free more bytes than have been read-allocated.\n"); + dev_info(async->subdevice->device->class_dev, + "attempted to read-free more bytes than have been read-allocated.\n"); nbytes = async->buf_read_alloc_count - async->buf_read_count; } async->buf_read_count += nbytes; @@ -853,10 +857,9 @@ comedi_auto_config_helper(struct device *hardware_device, mutex_lock(&comedi_dev->mutex); if (comedi_dev->attached) ret = -EBUSY; - else if (!try_module_get(driver->module)) { - printk(KERN_INFO "comedi: failed to increment module count\n"); + else if (!try_module_get(driver->module)) ret = -EIO; - } else { + else { /* set comedi_dev->driver here for attach wrapper */ comedi_dev->driver = driver; ret = (*attach_wrapper)(comedi_dev, context); @@ -884,14 +887,19 @@ static int comedi_auto_config_wrapper(struct comedi_device *dev, void *context) * has already been copied to it->board_name */ dev->board_ptr = comedi_recognize(driv, it->board_name); if (dev->board_ptr == NULL) { - printk(KERN_WARNING - "comedi: auto config failed to find board entry" - " '%s' for driver '%s'\n", it->board_name, - driv->driver_name); + dev_warn(dev->class_dev, + "auto config failed to find board entry '%s' for driver '%s'\n", + it->board_name, driv->driver_name); comedi_report_boards(driv); return -EINVAL; } } + if (!driv->attach) { + dev_warn(dev->class_dev, + "BUG! driver '%s' using old-style auto config but has no attach handler\n", + driv->driver_name); + return -EINVAL; + } return driv->attach(dev, it); } |