Skip to content

Commit

Permalink
staging: comedi: cleanup all the comedi_driver 'detach' functions
Browse files Browse the repository at this point in the history
1. Change the return type from int to void

All the detach functions, except for the comedi usb drivers, simply
return success (0). Plus, the return code is never checked in the
comedi core.

The comedi usb drivers do return error codes but the conditions can
never happen.

The first check is:

	if (!dev)
		return -EFAULT;

This checks that the passed comedi_device pointer is valid. The detach
function itself is called using this pointer so it MUST always be valid
or there is a bug in the core:

	if (dev->driver)
		dev->driver->detach(dev);

And the second check:

	usb = dev->private;
	if (!usb)
		return -EFAULT;

The dev->private pointer is setup in the attach function to point to the
probed usb device. This value could be NULL if the attach fails. But,
since the comedi core is going to unload the driver anyway and does not
check for errors there is no gain by returning one.

After removing these checks from the comedi usb drivers the detach
functions required a bit of cleanup.

2. Remove all the printk noise in the detach functions

All of the printk output is really just noise. The user did a rmmod to
unload the driver, we really don't need to tell them about it.

Also, some of the messages are output using:

	dev_dbg(dev->hw_dev, ...
or
	dev_info(dev->hw_dev, ...

Unfortunately the hw_dev value is only used by drivers that are doing
DMA. For most drivers this variable is going to be NULL so the output
is not going to work as expected.

3. Refactor a couple static 'free_resource' functions into the detach
   functions.

The 'free_resource' function is only being called by the detach and it
makes more sense to just absorb the code.

4. Remove a couple unnecessary braces for single statements.

5. Remove unnecessary comments.

Most of the comedi drivers appear to be based on the comedi skel driver
and have the comments from that driver included. These comments make
sense in the skel driver for reference but they don't need to be in any
of the actual drivers.

6. Remove all the extra whitespace.

It's not needed to make the functions any more readable.

7. Remove the now unused 'attached_successfully' variable in the
   cb_pcimdda driver.

This variable was only used to conditionally output some driver noise
during the detach. Since all the printk's have been removed this
variable is no longer necessary.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed May 19, 2012
1 parent e3f7e1a commit 484ecc9
Show file tree
Hide file tree
Showing 109 changed files with 236 additions and 993 deletions.
2 changes: 1 addition & 1 deletion drivers/staging/comedi/comedidev.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct comedi_driver {
const char *driver_name;
struct module *module;
int (*attach) (struct comedi_device *, struct comedi_devconfig *);
int (*detach) (struct comedi_device *);
void (*detach) (struct comedi_device *);
int (*attach_pci) (struct comedi_device *, struct pci_dev *);
int (*attach_usb) (struct comedi_device *, struct usb_interface *);

Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/8255.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,12 @@ static int dev_8255_attach(struct comedi_device *dev,
return 0;
}

static int dev_8255_detach(struct comedi_device *dev)
static void dev_8255_detach(struct comedi_device *dev)
{
int i;
unsigned long iobase;
struct comedi_subdevice *s;

printk(KERN_INFO "comedi%d: 8255: remove\n", dev->minor);

for (i = 0; i < dev->n_subdevices; i++) {
s = dev->subdevices + i;
if (s->type != COMEDI_SUBD_UNUSED) {
Expand All @@ -433,8 +431,6 @@ static int dev_8255_detach(struct comedi_device *dev)
}
subdev_8255_cleanup(dev, s);
}

return 0;
}

static struct comedi_driver dev_8255_driver = {
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/acl7225b.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@ static int acl7225b_attach(struct comedi_device *dev,
return 0;
}

static int acl7225b_detach(struct comedi_device *dev)
static void acl7225b_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: acl7225b: remove\n", dev->minor);

if (dev->iobase)
release_region(dev->iobase, this_board->io_range);

return 0;
}

static const struct boardtype boardtypes[] = {
Expand Down
48 changes: 7 additions & 41 deletions drivers/staging/comedi/drivers/addi-data/addi_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,71 +1839,37 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
return 0;
}

/*
+----------------------------------------------------------------------------+
| Function name : static int i_ADDI_Detach(struct comedi_device *dev) |
| |
| |
+----------------------------------------------------------------------------+
| Task : Deallocates resources of the addi_common driver |
| Free the DMA buffers, unregister irq. |
| |
+----------------------------------------------------------------------------+
| Input Parameters : struct comedi_device *dev |
| |
| |
+----------------------------------------------------------------------------+
| Return Value : 0 |
| |
+----------------------------------------------------------------------------+
*/

static int i_ADDI_Detach(struct comedi_device *dev)
static void i_ADDI_Detach(struct comedi_device *dev)
{

if (dev->private) {
if (devpriv->b_ValidDriver) {
if (devpriv->b_ValidDriver)
i_ADDI_Reset(dev);
}

if (dev->irq) {
if (dev->irq)
free_irq(dev->irq, dev);
}

if ((this_board->pc_EepromChip == NULL)
|| (strcmp(this_board->pc_EepromChip,
ADDIDATA_9054) != 0)) {
if (devpriv->allocated) {
if ((this_board->pc_EepromChip == NULL) ||
(strcmp(this_board->pc_EepromChip, ADDIDATA_9054) != 0)) {
if (devpriv->allocated)
i_pci_card_free(devpriv->amcc);
}

if (devpriv->ul_DmaBufferVirtual[0]) {
free_pages((unsigned long)devpriv->
ul_DmaBufferVirtual[0],
devpriv->ui_DmaBufferPages[0]);
}

if (devpriv->ul_DmaBufferVirtual[1]) {
free_pages((unsigned long)devpriv->
ul_DmaBufferVirtual[1],
devpriv->ui_DmaBufferPages[1]);
}
} else {
iounmap(devpriv->dw_AiBase);

if (devpriv->allocated) {
if (devpriv->allocated)
i_pci_card_free(devpriv->amcc);
}
}

if (pci_list_builded) {
/* v_pci_card_list_cleanup(PCI_VENDOR_ID_AMCC); */
v_pci_card_list_cleanup(this_board->i_VendorId);
pci_list_builded = 0;
}
}

return 0;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/comedi/drivers/addi-data/addi_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static unsigned short pci_list_builded; /* set to 1 when list of card is known *

/* Function declarations */
static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it);
static int i_ADDI_Detach(struct comedi_device *dev);
static void i_ADDI_Detach(struct comedi_device *dev);
static int i_ADDI_Reset(struct comedi_device *dev);

static irqreturn_t v_ADDI_Interrupt(int irq, void *d);
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/adl_pci6208.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,13 @@ static int pci6208_attach(struct comedi_device *dev,
return 1;
}

static int pci6208_detach(struct comedi_device *dev)
static void pci6208_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: pci6208: remove\n", dev->minor);

if (devpriv && devpriv->pci_dev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev);
}

return 0;
}

static struct comedi_driver adl_pci6208_driver = {
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/adl_pci7230.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,13 @@ static int adl_pci7230_attach(struct comedi_device *dev,
return 1;
}

static int adl_pci7230_detach(struct comedi_device *dev)
static void adl_pci7230_detach(struct comedi_device *dev)
{
printk(KERN_DEBUG "comedi%d: pci7230: remove\n", dev->minor);

if (devpriv && devpriv->pci_dev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev);
}

return 0;
}

static struct comedi_driver adl_pci7230_driver = {
Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/adl_pci7296.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,19 @@ static int adl_pci7296_attach(struct comedi_device *dev,
return -EIO;
}

static int adl_pci7296_detach(struct comedi_device *dev)
static void adl_pci7296_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);

if (devpriv && devpriv->pci_dev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev);
}
/* detach four 8255 digital io subdevices */
if (dev->subdevices) {
subdev_8255_cleanup(dev, dev->subdevices + 0);
subdev_8255_cleanup(dev, dev->subdevices + 1);
subdev_8255_cleanup(dev, dev->subdevices + 2);
subdev_8255_cleanup(dev, dev->subdevices + 3);

}

return 0;
}

static struct comedi_driver adl_pci7296_driver = {
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/adl_pci7432.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,13 @@ static int adl_pci7432_attach(struct comedi_device *dev,
return -EIO;
}

static int adl_pci7432_detach(struct comedi_device *dev)
static void adl_pci7432_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);

if (devpriv && devpriv->pci_dev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev);
}

return 0;
}

static struct comedi_driver adl_pci7432_driver = {
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/comedi/drivers/adl_pci8164.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,13 @@ static int adl_pci8164_attach(struct comedi_device *dev,
return -EIO;
}

static int adl_pci8164_detach(struct comedi_device *dev)
static void adl_pci8164_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: pci8164: remove\n", dev->minor);

if (devpriv && devpriv->pci_dev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev);
}

return 0;
}

static struct comedi_driver adl_pci8164_driver = {
Expand Down
12 changes: 1 addition & 11 deletions drivers/staging/comedi/drivers/adl_pci9111.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,29 +1382,19 @@ static int pci9111_attach(struct comedi_device *dev,
return 0;
}

/* Detach */

static int pci9111_detach(struct comedi_device *dev)
static void pci9111_detach(struct comedi_device *dev)
{
/* Reset device */

if (dev->private != NULL) {
if (dev_private->is_valid)
pci9111_reset(dev);

}
/* Release previously allocated irq */

if (dev->irq != 0)
free_irq(dev->irq, dev);

if (dev_private != NULL && dev_private->pci_device != NULL) {
if (dev->iobase)
comedi_pci_disable(dev_private->pci_device);
pci_dev_put(dev_private->pci_device);
}

return 0;
}

static struct comedi_driver adl_pci9111_driver = {
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/comedi/drivers/adl_pci9118.c
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ static int pci9118_attach(struct comedi_device *dev,
return 0;
}

static int pci9118_detach(struct comedi_device *dev)
static void pci9118_detach(struct comedi_device *dev)
{
if (dev->private) {
if (devpriv->valid)
Expand All @@ -2373,8 +2373,6 @@ static int pci9118_detach(struct comedi_device *dev)
free_pages((unsigned long)devpriv->dmabuf_virt[1],
devpriv->dmabuf_pages[1]);
}

return 0;
}

static const struct boardtype boardtypes[] = {
Expand Down
7 changes: 1 addition & 6 deletions drivers/staging/comedi/drivers/adq12b.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,11 @@ static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
return 0;
}

static int adq12b_detach(struct comedi_device *dev)
static void adq12b_detach(struct comedi_device *dev)
{
if (dev->iobase)
release_region(dev->iobase, ADQ12B_SIZE);

kfree(devpriv);

printk(KERN_INFO "comedi%d: adq12b: removed\n", dev->minor);

return 0;
}

static const struct adq12b_board adq12b_boards[] = {
Expand Down
5 changes: 1 addition & 4 deletions drivers/staging/comedi/drivers/adv_pci1710.c
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ static int pci1710_attach(struct comedi_device *dev,
return 0;
}

static int pci1710_detach(struct comedi_device *dev)
static void pci1710_detach(struct comedi_device *dev)
{
if (dev->private) {
if (devpriv->valid)
Expand All @@ -1561,12 +1561,9 @@ static int pci1710_detach(struct comedi_device *dev)
if (devpriv->pcidev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pcidev);

pci_dev_put(devpriv->pcidev);
}
}

return 0;
}

static struct comedi_driver adv_pci1710_driver = {
Expand Down
7 changes: 1 addition & 6 deletions drivers/staging/comedi/drivers/adv_pci1723.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,17 @@ static int pci1723_attach(struct comedi_device *dev,
return 0;
}

static int pci1723_detach(struct comedi_device *dev)
static void pci1723_detach(struct comedi_device *dev)
{
printk(KERN_ERR "comedi%d: pci1723: remove\n", dev->minor);

if (dev->private) {
if (devpriv->valid)
pci1723_reset(dev);

if (devpriv->pcidev) {
if (dev->iobase)
comedi_pci_disable(devpriv->pcidev);
pci_dev_put(devpriv->pcidev);
}
}

return 0;
}

static struct comedi_driver adv_pci1723_driver = {
Expand Down
Loading

0 comments on commit 484ecc9

Please sign in to comment.