All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device
@ 2012-07-19  1:39 H Hartley Sweeten
  2012-07-19 10:30 ` Ian Abbott
  0 siblings, 1 reply; 3+ messages in thread
From: H Hartley Sweeten @ 2012-07-19  1:39 UTC (permalink / raw)
  To: Linux Kernel; +Cc: devel, abbotti, gregkh

Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev is no longer held in the provate data, we can
also cleanup the detach a bit. Remove the IS_ENABLED() tests in
the detach. If the pci_dev is non NULL it's a PCI device otherwise
it's an ISA device. Using IS_ENABLED() to omit the code paths
makes the code a bit confusing and doesn't save much.

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/amplc_pc236.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c
index 3eee7f3..aabba98 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -131,8 +131,6 @@ static const struct pc236_board pc236_boards[] = {
    feel free to suggest moving the variable to the struct comedi_device struct.
  */
 struct pc236_private {
-	/* PCI device */
-	struct pci_dev *pci_dev;
 	unsigned long lcr_iobase; /* PLX PCI9052 config registers in PCIBAR1 */
 	int enable_irq;
 };
@@ -412,6 +410,7 @@ static irqreturn_t pc236_interrupt(int irq, void *d)
 static void pc236_report_attach(struct comedi_device *dev, unsigned int irq)
 {
 	const struct pc236_board *thisboard = comedi_board(dev);
+	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	char tmpbuf[60];
 	int tmplen;
 
@@ -421,10 +420,8 @@ static void pc236_report_attach(struct comedi_device *dev, unsigned int irq)
 				   "(base %#lx) ", dev->iobase);
 	else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_PCI) &&
 		 thisboard->bustype == pci_bustype) {
-		struct pc236_private *devpriv = dev->private;
-		struct pci_dev *pci_dev = devpriv->pci_dev;
 		tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-				   "(pci %s) ", pci_name(pci_dev));
+				   "(pci %s) ", pci_name(pcidev));
 	} else
 		tmplen = 0;
 	if (irq)
@@ -489,7 +486,8 @@ static int pc236_pci_common_attach(struct comedi_device *dev,
 	unsigned long iobase;
 	int ret;
 
-	devpriv->pci_dev = pci_dev;
+	comedi_set_hw_dev(dev, &pci_dev->dev);
+
 	ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME);
 	if (ret < 0) {
 		dev_err(dev->class_dev,
@@ -573,6 +571,7 @@ static int __devinit pc236_attach_pci(struct comedi_device *dev,
 static void pc236_detach(struct comedi_device *dev)
 {
 	struct pc236_private *devpriv = dev->private;
+	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
 	if (devpriv)
 		pc236_intr_disable(dev);
@@ -580,16 +579,13 @@ static void pc236_detach(struct comedi_device *dev)
 		free_irq(dev->irq, dev);
 	if (dev->subdevices)
 		subdev_8255_cleanup(dev, dev->subdevices + 0);
-	if (devpriv) {
-		if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_PCI) &&
-		    devpriv->pci_dev) {
-			if (dev->iobase)
-				comedi_pci_disable(devpriv->pci_dev);
-			pci_dev_put(devpriv->pci_dev);
-		} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_ISA)) {
-			if (dev->iobase)
-				release_region(dev->iobase, PC236_IO_SIZE);
-		}
+	if (pcidev) {
+		if (dev->iobase)
+			comedi_pci_disable(pcidev);
+		pci_dev_put(pcidev);
+	} else {
+		if (dev->iobase)
+			release_region(dev->iobase, PC236_IO_SIZE);
 	}
 }
 
-- 
1.7.11


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device
  2012-07-19  1:39 [PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device H Hartley Sweeten
@ 2012-07-19 10:30 ` Ian Abbott
  2012-07-19 10:39   ` Ian Abbott
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Abbott @ 2012-07-19 10:30 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, devel, Ian Abbott, gregkh

On 2012-07-19 02:39, H Hartley Sweeten wrote:
> Use the hw_dev pointer in the comedi_device struct to hold the
> pci_dev instead of carrying it in the private data.
>
> Since the pci_dev is no longer held in the provate data, we can
> also cleanup the detach a bit. Remove the IS_ENABLED() tests in
> the detach. If the pci_dev is non NULL it's a PCI device otherwise
> it's an ISA device. Using IS_ENABLED() to omit the code paths
> makes the code a bit confusing and doesn't save much.

The detach() routine should really check thisboard->bustype for 
robustness, as NULL hw_dev doesn't necessarily mean its a PCI device. 
The original code should have checked thisboard->bustype too although it 
works by accident because dev->iobase is 0.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device
  2012-07-19 10:30 ` Ian Abbott
@ 2012-07-19 10:39   ` Ian Abbott
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2012-07-19 10:39 UTC (permalink / raw)
  To: Ian Abbott; +Cc: H Hartley Sweeten, Linux Kernel, devel, gregkh

On 2012-07-19 11:30, Ian Abbott wrote:
> On 2012-07-19 02:39, H Hartley Sweeten wrote:
>> Use the hw_dev pointer in the comedi_device struct to hold the
>> pci_dev instead of carrying it in the private data.
>>
>> Since the pci_dev is no longer held in the provate data, we can
>> also cleanup the detach a bit. Remove the IS_ENABLED() tests in
>> the detach. If the pci_dev is non NULL it's a PCI device otherwise
>> it's an ISA device. Using IS_ENABLED() to omit the code paths
>> makes the code a bit confusing and doesn't save much.
>
> The detach() routine should really check thisboard->bustype for
> robustness, as NULL hw_dev doesn't necessarily mean its a PCI device.
> The original code should have checked thisboard->bustype too although it
> works by accident because dev->iobase is 0.

I can submit a patch to add thisboard->bustype checks in the detach 
routine after your patch is applied.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-19 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19  1:39 [PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device H Hartley Sweeten
2012-07-19 10:30 ` Ian Abbott
2012-07-19 10:39   ` Ian Abbott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.