lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 16 Aug 2012 19:44:35 -0700
From:	H Hartley Sweeten <hartleys@...ionengravers.com>
To:	Linux Kernel <linux-kernel@...r.kernel.org>
CC:	<devel@...verdev.osuosl.org>, <abbotti@....co.uk>,
	<gregkh@...uxfoundation.org>
Subject: [PATCH 07/35] staging: comedi: cb_pcidio: use attach_pci callback

Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an 'attach_pci' callback function. Since the
driver does not require any external configuration options, and
the legacy 'attach' callback is now optional, remove it.

Signed-off-by: H Hartley Sweeten <hsweeten@...ionengravers.com>
Cc: Ian Abbott <abbotti@....co.uk>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 97 +++++++++++++-----------------
 1 file changed, 41 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c b/drivers/staging/comedi/drivers/cb_pcidio.c
index c377beb..52c6379 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -30,13 +30,7 @@ Status: experimental
 
 This driver has been modified from skel.c of comedi-0.7.70.
 
-Configuration Options:
-  [0] - PCI bus of device (optional)
-  [1] - PCI slot of device (optional)
-  If bus/slot is not specified, the first available PCI device will
-  be used.
-
-Passing a zero for an option is the same as leaving it unspecified.
+Configuration Options: not applicable, uses PCI auto config
 */
 
 /*------------------------------ HEADER FILES ---------------------------------*/
@@ -85,90 +79,81 @@ static const struct pcidio_board pcidio_boards[] = {
 	 },
 };
 
-static struct pci_dev *pcidio_find_pci_dev(struct comedi_device *dev,
-					   struct comedi_devconfig *it)
+static const void *pcidio_find_boardinfo(struct comedi_device *dev,
+					 struct pci_dev *pcidev)
 {
-	struct pci_dev *pcidev = NULL;
-	int bus = it->options[0];
-	int slot = it->options[1];
+	const struct pcidio_board *board;
 	int i;
 
-	for_each_pci_dev(pcidev) {
-		if (bus || slot) {
-			if (bus != pcidev->bus->number ||
-				slot != PCI_SLOT(pcidev->devfn))
-				continue;
-		}
-		if (pcidev->vendor != PCI_VENDOR_ID_CB)
-			continue;
-		for (i = 0; i < ARRAY_SIZE(pcidio_boards); i++) {
-			if (pcidio_boards[i].dev_id != pcidev->device)
-				continue;
-
-			dev->board_ptr = pcidio_boards + i;
-			return pcidev;
-		}
+	for (i = 0; i < ARRAY_SIZE(pcidio_boards); i++) {
+		board = &pcidio_boards[i];
+		if (board->dev_id == pcidev->device)
+			return board;
 	}
-	dev_err(dev->class_dev,
-		"No supported board found! (req. bus %d, slot %d)\n",
-		bus, slot);
 	return NULL;
 }
 
-static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+static int pcidio_attach_pci(struct comedi_device *dev,
+			     struct pci_dev *pcidev)
 {
-	const struct pcidio_board *thisboard;
-	struct pci_dev *pcidev;
+	const struct pcidio_board *board;
+	struct comedi_subdevice *s;
 	int i;
 	int ret;
 
-	pcidev = pcidio_find_pci_dev(dev, it);
-	if (!pcidev)
-		return -EIO;
 	comedi_set_hw_dev(dev, &pcidev->dev);
-	thisboard = comedi_board(dev);
-	dev->board_name = thisboard->name;
 
-	if (comedi_pci_enable(pcidev, thisboard->name))
-		return -EIO;
+	board = pcidio_find_boardinfo(dev, pcidev);
+	if (!board)
+		return -ENODEV;
+	dev->board_ptr = board;
+	dev->board_name = board->name;
 
-	dev->iobase = pci_resource_start(pcidev, thisboard->dioregs_badrindex);
+	ret = comedi_pci_enable(pcidev, dev->board_name);
+	if (ret)
+		return ret;
+	dev->iobase = pci_resource_start(pcidev, board->dioregs_badrindex);
 
-	ret = comedi_alloc_subdevices(dev, thisboard->n_8255);
+	ret = comedi_alloc_subdevices(dev, board->n_8255);
 	if (ret)
 		return ret;
 
-	for (i = 0; i < thisboard->n_8255; i++) {
-		subdev_8255_init(dev, dev->subdevices + i,
-				 NULL, dev->iobase + i * 4);
-		dev_dbg(dev->class_dev, "subdev %d: base = 0x%lx\n", i,
-			dev->iobase + i * 4);
+	for (i = 0; i < board->n_8255; i++) {
+		s = dev->subdevices + i;
+		ret = subdev_8255_init(dev, s, NULL, dev->iobase + i * 4);
+		if (ret)
+			return ret;
 	}
 
-	return 1;
+	dev_info(dev->class_dev, "%s attached (%d digital i/o channels)\n",
+		dev->board_name, board->n_8255 * 24);
+
+	return 0;
 }
 
 static void pcidio_detach(struct comedi_device *dev)
 {
-	const struct pcidio_board *thisboard = comedi_board(dev);
+	const struct pcidio_board *board = comedi_board(dev);
 	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+	struct comedi_subdevice *s;
+	int i;
 
+	if (dev->subdevices) {
+		for (i = 0; i < board->n_8255; i++) {
+			s = dev->subdevices + i;
+			subdev_8255_cleanup(dev, s);
+		}
+	}
 	if (pcidev) {
 		if (dev->iobase)
 			comedi_pci_disable(pcidev);
-		pci_dev_put(pcidev);
-	}
-	if (dev->subdevices) {
-		int i;
-		for (i = 0; i < thisboard->n_8255; i++)
-			subdev_8255_cleanup(dev, dev->subdevices + i);
 	}
 }
 
 static struct comedi_driver cb_pcidio_driver = {
 	.driver_name	= "cb_pcidio",
 	.module		= THIS_MODULE,
-	.attach		= pcidio_attach,
+	.attach_pci	= pcidio_attach_pci,
 	.detach		= pcidio_detach,
 };
 
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists