All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
@ 2012-07-19  1:24 H Hartley Sweeten
  2012-07-19  9:22 ` Ian Abbott
  0 siblings, 1 reply; 5+ messages in thread
From: H Hartley Sweeten @ 2012-07-19  1:24 UTC (permalink / raw)
  To: Linux Kernel; +Cc: devel, abbotti, gregkh

Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
to store the pci_dev pointer in the comedi_device hw_dev variable and
retrieve it easily.

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/comedidev.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index de8c99c..620222d 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct comedi_device *dev,
 	}
 }
 
+static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
+{
+	return to_pci_dev(dev->hw_dev);
+}
+
 int comedi_buf_put(struct comedi_async *async, short x);
 int comedi_buf_get(struct comedi_async *async, short *x);
 
-- 
1.7.11


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

* Re: [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
  2012-07-19  1:24 [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper H Hartley Sweeten
@ 2012-07-19  9:22 ` Ian Abbott
  2012-07-19 16:20   ` H Hartley Sweeten
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Abbott @ 2012-07-19  9:22 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, devel, Ian Abbott, gregkh

On 2012-07-19 02:24, H Hartley Sweeten wrote:
> Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
> to store the pci_dev pointer in the comedi_device hw_dev variable and
> retrieve it easily.
>
> 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/comedidev.h | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
> index de8c99c..620222d 100644
> --- a/drivers/staging/comedi/comedidev.h
> +++ b/drivers/staging/comedi/comedidev.h
> @@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct comedi_device *dev,
>   	}
>   }
>
> +static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
> +{
> +	return to_pci_dev(dev->hw_dev);
> +}
> +

That needs to be something like:

	return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;

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

* RE: [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
  2012-07-19  9:22 ` Ian Abbott
@ 2012-07-19 16:20   ` H Hartley Sweeten
  2012-07-19 16:32     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: H Hartley Sweeten @ 2012-07-19 16:20 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: 1539 bytes --]

On Thursday, July 19, 2012 2:23 AM, Ian Abbott wrote:
> On 2012-07-19 02:24, H Hartley Sweeten wrote:
>> Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
>> to store the pci_dev pointer in the comedi_device hw_dev variable and
>> retrieve it easily.
>>
>> 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/comedidev.h | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
>> index de8c99c..620222d 100644
>> --- a/drivers/staging/comedi/comedidev.h
>> +++ b/drivers/staging/comedi/comedidev.h
>> @@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct comedi_device *dev,
>>   	}
>>   }
>>
>> +static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
>> +{
>> +	return to_pci_dev(dev->hw_dev);
>> +}
>> +
>
> That needs to be something like:
>
>	return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;

Hmm.. I'm not really sure.

I assumed that the container_of() macro would return NULL if the ptr passed to
it was NULL. But, I'm not sure how this actually unwinds for that case.

Greg, do you know if the NULL check is needed? It's is possible that the dev->hw_dev
pointer could be NULL.

Thanks,
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] 5+ messages in thread

* Re: [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
  2012-07-19 16:20   ` H Hartley Sweeten
@ 2012-07-19 16:32     ` Dan Carpenter
  2012-07-19 17:27       ` H Hartley Sweeten
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-07-19 16:32 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Ian Abbott, devel, gregkh, Ian Abbott, Linux Kernel

On Thu, Jul 19, 2012 at 11:20:52AM -0500, H Hartley Sweeten wrote:
> On Thursday, July 19, 2012 2:23 AM, Ian Abbott wrote:
> > On 2012-07-19 02:24, H Hartley Sweeten wrote:
> >> Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
> >> to store the pci_dev pointer in the comedi_device hw_dev variable and
> >> retrieve it easily.
> >>
> >> 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/comedidev.h | 5 +++++
> >>   1 file changed, 5 insertions(+)
> >>
> >> diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
> >> index de8c99c..620222d 100644
> >> --- a/drivers/staging/comedi/comedidev.h
> >> +++ b/drivers/staging/comedi/comedidev.h
> >> @@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct comedi_device *dev,
> >>   	}
> >>   }
> >>
> >> +static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
> >> +{
> >> +	return to_pci_dev(dev->hw_dev);
> >> +}
> >> +
> >
> > That needs to be something like:
> >
> >	return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
> 
> Hmm.. I'm not really sure.
> 
> I assumed that the container_of() macro would return NULL if the ptr passed to
> it was NULL. But, I'm not sure how this actually unwinds for that case.
> 
> Greg, do you know if the NULL check is needed? It's is possible that the dev->hw_dev
> pointer could be NULL.
> 

container_of() just does pointer math with the offset.  Since
->hw_dev is not the first member of the pci_dev struct then
to_pci_dev() never returns NULL.  If you give it a NULL pointer it
returns a bogus pointer back.

regards,
dan carpenter


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

* RE: [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
  2012-07-19 16:32     ` Dan Carpenter
@ 2012-07-19 17:27       ` H Hartley Sweeten
  0 siblings, 0 replies; 5+ messages in thread
From: H Hartley Sweeten @ 2012-07-19 17:27 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Ian Abbott, devel, gregkh, Ian Abbott, Linux Kernel

On Thursday, July 19, 2012 9:32 AM, Dan Carpenter wrote:
> On Thu, Jul 19, 2012 at 11:20:52AM -0500, H Hartley Sweeten wrote:
>> On Thursday, July 19, 2012 2:23 AM, Ian Abbott wrote:
>>> That needs to be something like:
>>>
>>>	return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
>> 
>> Hmm.. I'm not really sure.
>> 
>> I assumed that the container_of() macro would return NULL if the ptr passed to
>> it was NULL. But, I'm not sure how this actually unwinds for that case.
>> 
>> Greg, do you know if the NULL check is needed? It's is possible that the dev->hw_dev
>> pointer could be NULL.
>> 
>
> container_of() just does pointer math with the offset.  Since
> ->hw_dev is not the first member of the pci_dev struct then
> to_pci_dev() never returns NULL.  If you give it a NULL pointer it
> returns a bogus pointer back.

Thanks for the information.

I'll update PATCH 01/90 and repost it as v2.

Thanks,
Hartley


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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19  1:24 [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper H Hartley Sweeten
2012-07-19  9:22 ` Ian Abbott
2012-07-19 16:20   ` H Hartley Sweeten
2012-07-19 16:32     ` Dan Carpenter
2012-07-19 17:27       ` H Hartley Sweeten

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.