From af12a9e4d223b9a7783edd370e8b2f7c198a22bd Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Wed, 24 Mar 2010 11:53:09 +0000 Subject: [PATCH] The 'open' method in struct comedi_device_struct now returns 0 on success and a negative errno on failure. The 'open' method must clean up after itself on failure as the 'close' method won't be called. A failure causes the 'open' file operation for the comedi device to fail. The dt9812 and serial2002 drivers now make use of the ability to return an error. --- comedi/comedi_fops.c | 9 ++++++++- comedi/drivers/dt9812.c | 6 +++++- comedi/drivers/jr3_pci.c | 3 ++- comedi/drivers/serial2002.c | 9 ++++++--- include/linux/comedidev.h | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 19295728..9a5e0ea2 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1837,7 +1837,14 @@ ok: } if (dev->attached && dev->use_count == 0 && dev->open) { - dev->open(dev); + int rc = dev->open(dev); + + if (rc < 0) { + module_put(dev->driver->module); + module_put(THIS_MODULE); + mutex_unlock(&dev->mutex); + return rc; + } } dev->use_count++; diff --git a/comedi/drivers/dt9812.c b/comedi/drivers/dt9812.c index 8afb9cb9..7d69a161 100644 --- a/comedi/drivers/dt9812.c +++ b/comedi/drivers/dt9812.c @@ -685,8 +685,10 @@ static struct usb_driver dt9812_usb_driver = { * Comedi functions */ -static void dt9812_comedi_open(comedi_device * dev) +static int dt9812_comedi_open(comedi_device * dev) { + int result = -ENODEV; + down(&devpriv->slot->mutex); if (devpriv->slot->usb) { // We have an attached device, fill in current range info @@ -729,8 +731,10 @@ static void dt9812_comedi_open(comedi_device * dev) } break; } + result = 0; } up(&devpriv->slot->mutex); + return result; } static int dt9812_di_rinsn(comedi_device * dev, comedi_subdevice * s, diff --git a/comedi/drivers/jr3_pci.c b/comedi/drivers/jr3_pci.c index 0482a3fb..220e585c 100644 --- a/comedi/drivers/jr3_pci.c +++ b/comedi/drivers/jr3_pci.c @@ -372,7 +372,7 @@ static int jr3_pci_ai_insn_read(comedi_device * dev, comedi_subdevice * s, return result; } -static void jr3_pci_open(comedi_device * dev) +static int jr3_pci_open(comedi_device * dev) { int i; jr3_pci_dev_private *devpriv = dev->private; @@ -387,6 +387,7 @@ static void jr3_pci_open(comedi_device * dev) p->channel_no); } } + return 0; } int read_idm_word(const u8 * data, size_t size, int *pos, unsigned int *val) diff --git a/comedi/drivers/serial2002.c b/comedi/drivers/serial2002.c index b0e285e8..974f0a1c 100644 --- a/comedi/drivers/serial2002.c +++ b/comedi/drivers/serial2002.c @@ -390,15 +390,16 @@ static void serial_write(struct file *f, struct serial_data data) } } -static void serial_2002_open(comedi_device * dev) +static int serial_2002_open(comedi_device * dev) { + int result; char port[20]; sprintf(port, "/dev/ttyS%d", devpriv->port); devpriv->tty = filp_open(port, 0, O_RDWR); if (IS_ERR(devpriv->tty)) { - printk("serial_2002: file open error = %ld\n", - PTR_ERR(devpriv->tty)); + result = (int)PTR_ERR(devpriv->tty); + printk("serial_2002: file open error = %d\n", result); } else { typedef struct { short int kind; @@ -651,7 +652,9 @@ static void serial_2002_open(comedi_device * dev) } } } + result = 0; } + return result; } static void serial_2002_close(comedi_device * dev) diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index b8db1380..6672d6e3 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -286,7 +286,7 @@ struct comedi_device_struct { struct fasync_struct *async_queue; - void (*open) (comedi_device * dev); + int (*open) (comedi_device * dev); void (*close) (comedi_device * dev); }; -- 2.26.2