From: H Hartley Sweeten <hartleys@visionengravers.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Cc: <devel@driverdev.osuosl.org>, <abbotti@mev.co.uk>,
<gregkh@linuxfoundation.org>
Subject: [PATCH 17/90] staging: comedi: adv_pci1710: factor out the "find pci device" code
Date: Wed, 18 Jul 2012 18:31:26 -0700 [thread overview]
Message-ID: <201207181831.26341.hartleys@visionengravers.com> (raw)
Factor the "find pci device" code out of the attach function.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/staging/comedi/drivers/adv_pci1710.c | 42 ++++++++++++++++++----------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 0ed1ff9..0823a36 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -1333,29 +1333,21 @@ static int pci1710_reset(struct comedi_device *dev)
DPRINTK("adv_pci1710 EDBG: END: pci1710_reset(...)\n");
}
-static int pci1710_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+static struct pci_dev *pci1710_find_pci_dev(struct comedi_device *dev,
+ struct comedi_devconfig *it)
{
- struct comedi_subdevice *s;
- int ret, subdev, n_subdevices;
- unsigned int irq;
- unsigned long iobase;
struct pci_dev *pcidev;
int opt_bus, opt_slot;
const char *errstr;
unsigned char pci_bus, pci_slot, pci_func;
int i;
int board_index;
-
- dev_info(dev->class_dev, DRV_NAME ": attach\n");
+ unsigned int irq;
+ unsigned long iobase;
opt_bus = it->options[0];
opt_slot = it->options[1];
- ret = alloc_private(dev, sizeof(struct pci1710_private));
- if (ret < 0)
- return -ENOMEM;
-
/* Look for matching PCI device */
errstr = "not found!";
pcidev = NULL;
@@ -1404,7 +1396,7 @@ static int pci1710_attach(struct comedi_device *dev,
} else {
dev_err(dev->class_dev, "- Card %s\n", errstr);
}
- return -EIO;
+ return NULL;
}
pci_bus = pcidev->bus->number;
@@ -1416,10 +1408,30 @@ static int pci1710_attach(struct comedi_device *dev,
dev_dbg(dev->class_dev, "b:s:f=%d:%d:%d, io=0x%4lx\n",
pci_bus, pci_slot, pci_func, iobase);
- dev->iobase = iobase;
+ return pcidev;
+}
+
+static int pci1710_attach(struct comedi_device *dev,
+ struct comedi_devconfig *it)
+{
+ struct comedi_subdevice *s;
+ int ret, subdev, n_subdevices;
+ unsigned int irq;
+
+ dev_info(dev->class_dev, DRV_NAME ": attach\n");
+
+ ret = alloc_private(dev, sizeof(struct pci1710_private));
+ if (ret < 0)
+ return -ENOMEM;
+
+ devpriv->pcidev = pci1710_find_pci_dev(dev, it);
+ if (!devpriv->pcidev)
+ return -EIO;
+
+ dev->iobase = pci_resource_start(devpriv->pcidev, 2);
+ irq = devpriv->pcidev->irq;
dev->board_name = this_board->name;
- devpriv->pcidev = pcidev;
n_subdevices = 0;
if (this_board->n_aichan)
--
1.7.11
reply other threads:[~2012-07-19 1:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201207181831.26341.hartleys@visionengravers.com \
--to=hartleys@visionengravers.com \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome