Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 484ecc95 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi: cleanup all the comedi_driver 'detach' functions



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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e3f7e1a5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -189,7 +189,7 @@ struct comedi_driver {
	const char *driver_name;
	const char *driver_name;
	struct module *module;
	struct module *module;
	int (*attach) (struct comedi_device *, struct comedi_devconfig *);
	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_pci) (struct comedi_device *, struct pci_dev *);
	int (*attach_usb) (struct comedi_device *, struct usb_interface *);
	int (*attach_usb) (struct comedi_device *, struct usb_interface *);


+1 −5
Original line number Original line Diff line number Diff line
@@ -417,14 +417,12 @@ static int dev_8255_attach(struct comedi_device *dev,
	return 0;
	return 0;
}
}


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


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

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

	return 0;
}
}


static struct comedi_driver dev_8255_driver = {
static struct comedi_driver dev_8255_driver = {
+1 −5
Original line number Original line Diff line number Diff line
@@ -119,14 +119,10 @@ static int acl7225b_attach(struct comedi_device *dev,
	return 0;
	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)
	if (dev->iobase)
		release_region(dev->iobase, this_board->io_range);
		release_region(dev->iobase, this_board->io_range);

	return 0;
}
}


static const struct boardtype boardtypes[] = {
static const struct boardtype boardtypes[] = {
+7 −41
Original line number Original line Diff line number Diff line
@@ -1839,50 +1839,22 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
	return 0;
	return 0;
}
}


/*
static void i_ADDI_Detach(struct comedi_device *dev)
+----------------------------------------------------------------------------+
| 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)
{
{

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

		if (dev->irq) {
			free_irq(dev->irq, dev);
			free_irq(dev->irq, dev);
		}
		if ((this_board->pc_EepromChip == NULL) ||

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

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

			if (devpriv->ul_DmaBufferVirtual[1]) {
			if (devpriv->ul_DmaBufferVirtual[1]) {
				free_pages((unsigned long)devpriv->
				free_pages((unsigned long)devpriv->
					ul_DmaBufferVirtual[1],
					ul_DmaBufferVirtual[1],
@@ -1890,20 +1862,14 @@ static int i_ADDI_Detach(struct comedi_device *dev)
			}
			}
		} else {
		} else {
			iounmap(devpriv->dw_AiBase);
			iounmap(devpriv->dw_AiBase);

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

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

	return 0;
}
}


/*
/*
+1 −1
Original line number Original line Diff line number Diff line
@@ -416,7 +416,7 @@ static unsigned short pci_list_builded; /* set to 1 when list of card is known *


/* Function declarations */
/* Function declarations */
static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it);
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 int i_ADDI_Reset(struct comedi_device *dev);


static irqreturn_t v_ADDI_Interrupt(int irq, void *d);
static irqreturn_t v_ADDI_Interrupt(int irq, void *d);
Loading