mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
@ 2012-07-19  1:37 H Hartley Sweeten
  2012-07-19 10:10 ` Ian Abbott
  0 siblings, 1 reply; 6+ messages in thread
From: H Hartley Sweeten @ 2012-07-19  1:37 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_dio200.c | 31 +++++++++++----------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c
index ca9d4f2..6c81e377 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -424,7 +424,6 @@ static const struct dio200_layout_struct dio200_layouts[] = {
    feel free to suggest moving the variable to the struct comedi_device struct.
  */
 struct dio200_private {
-	struct pci_dev *pci_dev;	/* PCI device */
 	int intr_sd;
 };
 
@@ -1225,7 +1224,7 @@ dio200_subdev_8254_cleanup(struct comedi_device *dev,
 static void dio200_report_attach(struct comedi_device *dev, unsigned int irq)
 {
 	const struct dio200_board *thisboard = comedi_board(dev);
-	struct dio200_private *devpriv = dev->private;
+	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	char tmpbuf[60];
 	int tmplen;
 
@@ -1236,7 +1235,7 @@ static void dio200_report_attach(struct comedi_device *dev, unsigned int irq)
 	else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI) &&
 		 thisboard->bustype == pci_bustype)
 		tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-				   "(pci %s) ", pci_name(devpriv->pci_dev));
+				   "(pci %s) ", pci_name(pcidev));
 	else
 		tmplen = 0;
 	if (irq)
@@ -1327,11 +1326,11 @@ static int dio200_common_attach(struct comedi_device *dev, unsigned long iobase,
 static int dio200_pci_common_attach(struct comedi_device *dev,
 				    struct pci_dev *pci_dev)
 {
-	struct dio200_private *devpriv = dev->private;
 	unsigned long iobase;
 	int ret;
 
-	devpriv->pci_dev = pci_dev;
+	comedi_set_hw_dev(dev, &pci_dev->dev);
+
 	ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
 	if (ret < 0) {
 		dev_err(dev->class_dev,
@@ -1419,7 +1418,7 @@ static int __devinit dio200_attach_pci(struct comedi_device *dev,
 static void dio200_detach(struct comedi_device *dev)
 {
 	const struct dio200_board *thisboard = comedi_board(dev);
-	struct dio200_private *devpriv = dev->private;
+	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	const struct dio200_layout_struct *layout;
 	unsigned n;
 
@@ -1444,19 +1443,13 @@ static void dio200_detach(struct comedi_device *dev)
 			}
 		}
 	}
-	if (devpriv) {
-		if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI) &&
-		    thisboard->bustype == pci_bustype) {
-			if (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_DIO200_ISA) &&
-			   thisboard->bustype == isa_bustype) {
-			if (dev->iobase)
-				release_region(dev->iobase, DIO200_IO_SIZE);
-		}
+	if (pcidev) {
+		if (dev->iobase)
+			comedi_pci_disable(pcidev);
+		pci_dev_put(pcidev);
+	} else {
+		if (dev->iobase)
+			release_region(dev->iobase, DIO200_IO_SIZE);
 	}
 }
 
-- 
1.7.11


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

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

On 2012-07-19 02:37, 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.

No, you really need to check thisboard->bustype in the detach() because 
hw_dev might be NULL for a PCI board if the attach() failed.

-- 
-=( 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] 6+ messages in thread

* Re: [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
  2012-07-19 10:10 ` Ian Abbott
@ 2012-07-19 10:27   ` Ian Abbott
  2012-07-19 10:38     ` Ian Abbott
  2012-07-19 17:20     ` H Hartley Sweeten
  2012-07-19 17:14   ` H Hartley Sweeten
  1 sibling, 2 replies; 6+ messages in thread
From: Ian Abbott @ 2012-07-19 10:27 UTC (permalink / raw)
  To: Ian Abbott; +Cc: H Hartley Sweeten, Linux Kernel, devel, gregkh

On 2012-07-19 11:10, Ian Abbott wrote:
> On 2012-07-19 02:37, 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.
>
> No, you really need to check thisboard->bustype in the detach() because
> hw_dev might be NULL for a PCI board if the attach() failed.

Actually, your patch wouldn't do any harm as dev->iobase would be 0.  It 
would just go through the "failed ISA device" path instead of the 
"failed PCI device" path.  It would be more robust to check 
thisboard->bustype though.

-- 
-=( 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] 6+ messages in thread

* Re: [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
  2012-07-19 10:27   ` Ian Abbott
@ 2012-07-19 10:38     ` Ian Abbott
  2012-07-19 17:20     ` H Hartley Sweeten
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Abbott @ 2012-07-19 10:38 UTC (permalink / raw)
  To: Ian Abbott; +Cc: H Hartley Sweeten, Linux Kernel, devel, gregkh

On 2012-07-19 11:27, Ian Abbott wrote:
> On 2012-07-19 11:10, Ian Abbott wrote:
>> On 2012-07-19 02:37, 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.
>>
>> No, you really need to check thisboard->bustype in the detach() because
>> hw_dev might be NULL for a PCI board if the attach() failed.
>
> Actually, your patch wouldn't do any harm as dev->iobase would be 0.  It
> would just go through the "failed ISA device" path instead of the
> "failed PCI device" path.  It would be more robust to check
> thisboard->bustype though.

I don't mind if your original patch is applied as it does no harm.  If 
so, I'll submit a patch afterwards to check the bus type in the detach().

-- 
-=( 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] 6+ messages in thread

* RE: [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
  2012-07-19 10:10 ` Ian Abbott
  2012-07-19 10:27   ` Ian Abbott
@ 2012-07-19 17:14   ` H Hartley Sweeten
  1 sibling, 0 replies; 6+ messages in thread
From: H Hartley Sweeten @ 2012-07-19 17:14 UTC (permalink / raw)
  To: Ian Abbott; +Cc: Linux Kernel, devel, Ian Abbott, gregkh

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1002 bytes --]

On Thursday, July 19, 2012 3:11 AM, Ian Abbott wrote:
> On 2012-07-19 02:37, 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.
>
> No, you really need to check thisboard->bustype in the detach() because 
> hw_dev might be NULL for a PCI board if the attach() failed.

Ah, overlooked that.

I still think the IS_ENABLED() stuff should be removed where possible. It
just looks confusing in the if().

Regards,
Hartley

ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* RE: [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
  2012-07-19 10:27   ` Ian Abbott
  2012-07-19 10:38     ` Ian Abbott
@ 2012-07-19 17:20     ` H Hartley Sweeten
  1 sibling, 0 replies; 6+ messages in thread
From: H Hartley Sweeten @ 2012-07-19 17:20 UTC (permalink / raw)
  To: Ian Abbott, Ian Abbott; +Cc: Linux Kernel, devel, gregkh

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1457 bytes --]

On Thursday, July 19, 2012 3:27 AM, Ian Abbott wrote:
> On 2012-07-19 11:10, Ian Abbott wrote:
>> On 2012-07-19 02:37, 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.
>>
>> No, you really need to check thisboard->bustype in the detach() because
>> hw_dev might be NULL for a PCI board if the attach() failed.
>
> Actually, your patch wouldn't do any harm as dev->iobase would be 0.  It 
> would just go through the "failed ISA device" path instead of the 
> "failed PCI device" path.  It would be more robust to check 
> thisboard->bustype though.

Would this be cleaner:

	If (dev->iobase) {
		If (pcidev)
			comedi_pci_disable(pcidev);
		else
			release_region(dev->iobase, DIO200_IO_SIZE);
	}
	If (pcidev)
		pci_dev_put(pcidev);

Same number of lines but the i/o disable/release and the put of the pcidev
would then be distinctly separate.

Regards,
Hartley

ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19  1:37 [PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device H Hartley Sweeten
2012-07-19 10:10 ` Ian Abbott
2012-07-19 10:27   ` Ian Abbott
2012-07-19 10:38     ` Ian Abbott
2012-07-19 17:20     ` H Hartley Sweeten
2012-07-19 17:14   ` H Hartley Sweeten

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