* [PATCH] pci: Convert pci_resource_<foo> macros to static inlines
@ 2012-09-18 18:51 Joe Perches
2012-11-05 22:28 ` Bjorn Helgaas
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2012-09-18 18:51 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, LKML
Get the compiler to verify the argument type of struct pci_dev *.
Signed-off-by: Joe Perches <joe@perches.com>
---
Another possible improvement is to range check index.
include/linux/pci.h | 36 ++++++++++++++++++++++++++----------
1 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 5faa831..971d0e9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1396,16 +1396,32 @@ static inline struct pci_dev *pci_dev_get(struct pci_dev *dev)
/* these helpers provide future and backwards compatibility
* for accessing popular PCI BAR info */
-#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
-#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
-#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
-#define pci_resource_len(dev,bar) \
- ((pci_resource_start((dev), (bar)) == 0 && \
- pci_resource_end((dev), (bar)) == \
- pci_resource_start((dev), (bar))) ? 0 : \
- \
- (pci_resource_end((dev), (bar)) - \
- pci_resource_start((dev), (bar)) + 1))
+static inline resource_size_t
+pci_resource_start(const struct pci_dev *dev, int index)
+{
+ return dev->resource[index].start;
+}
+
+static inline resource_size_t
+pci_resource_end(const struct pci_dev *dev, int index)
+{
+ return dev->resource[index].end;
+}
+
+static inline unsigned long
+pci_resource_flags(const struct pci_dev *dev, int index)
+{
+ return dev->resource[index].flags;
+}
+
+static inline resource_size_t
+pci_resource_len(const struct pci_dev *dev, int index)
+{
+ if (pci_resource_start(dev, index) == 0 &&
+ pci_resource_end(dev, index) == 0)
+ return 0;
+ return resource_size(&dev->resource[index]);
+}
/* Similar to the helpers above, these manipulate per-pci_dev
* driver-specific data. They are really just a wrapper around
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pci: Convert pci_resource_<foo> macros to static inlines
2012-09-18 18:51 [PATCH] pci: Convert pci_resource_<foo> macros to static inlines Joe Perches
@ 2012-11-05 22:28 ` Bjorn Helgaas
2012-11-07 23:00 ` Bjorn Helgaas
0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Helgaas @ 2012-11-05 22:28 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-pci, LKML
On Tue, Sep 18, 2012 at 12:51 PM, Joe Perches <joe@perches.com> wrote:
> Get the compiler to verify the argument type of struct pci_dev *.
>
> Signed-off-by: Joe Perches <joe@perches.com>
I applied this to my pci/misc branch as v3.8 material. Thanks!
> ---
>
> Another possible improvement is to range check index.
>
> include/linux/pci.h | 36 ++++++++++++++++++++++++++----------
> 1 files changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 5faa831..971d0e9 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1396,16 +1396,32 @@ static inline struct pci_dev *pci_dev_get(struct pci_dev *dev)
>
> /* these helpers provide future and backwards compatibility
> * for accessing popular PCI BAR info */
> -#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
> -#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
> -#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
> -#define pci_resource_len(dev,bar) \
> - ((pci_resource_start((dev), (bar)) == 0 && \
> - pci_resource_end((dev), (bar)) == \
> - pci_resource_start((dev), (bar))) ? 0 : \
> - \
> - (pci_resource_end((dev), (bar)) - \
> - pci_resource_start((dev), (bar)) + 1))
> +static inline resource_size_t
> +pci_resource_start(const struct pci_dev *dev, int index)
> +{
> + return dev->resource[index].start;
> +}
> +
> +static inline resource_size_t
> +pci_resource_end(const struct pci_dev *dev, int index)
> +{
> + return dev->resource[index].end;
> +}
> +
> +static inline unsigned long
> +pci_resource_flags(const struct pci_dev *dev, int index)
> +{
> + return dev->resource[index].flags;
> +}
> +
> +static inline resource_size_t
> +pci_resource_len(const struct pci_dev *dev, int index)
> +{
> + if (pci_resource_start(dev, index) == 0 &&
> + pci_resource_end(dev, index) == 0)
> + return 0;
> + return resource_size(&dev->resource[index]);
> +}
>
> /* Similar to the helpers above, these manipulate per-pci_dev
> * driver-specific data. They are really just a wrapper around
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pci: Convert pci_resource_<foo> macros to static inlines
2012-11-05 22:28 ` Bjorn Helgaas
@ 2012-11-07 23:00 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2012-11-07 23:00 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-pci, LKML
On Mon, Nov 5, 2012 at 3:28 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> On Tue, Sep 18, 2012 at 12:51 PM, Joe Perches <joe@perches.com> wrote:
>> Get the compiler to verify the argument type of struct pci_dev *.
>>
>> Signed-off-by: Joe Perches <joe@perches.com>
>
> I applied this to my pci/misc branch as v3.8 material. Thanks!
I dropped this for now because of these build failures:
drivers/staging/telephony/ixj.c: In function 'ixj_probe_pci':
drivers/staging/telephony/ixj.c:7732:13: warning: assignment makes
integer from pointer without a cast [enabled by default]
drivers/staging/telephony/ixj.c:7732:38: error: expected ';' before
'pci_resource_start'
drivers/scsi/gdth.c: In function 'gdth_init_pci':
drivers/scsi/gdth.c:1111:34: error: lvalue required as left operand of
assignment
I posted a fix for the gdth.c problem, and ixj.c is apparently being
deleted. When those happen, we can try again.
Bjorn
>> ---
>>
>> Another possible improvement is to range check index.
>>
>> include/linux/pci.h | 36 ++++++++++++++++++++++++++----------
>> 1 files changed, 26 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>> index 5faa831..971d0e9 100644
>> --- a/include/linux/pci.h
>> +++ b/include/linux/pci.h
>> @@ -1396,16 +1396,32 @@ static inline struct pci_dev *pci_dev_get(struct pci_dev *dev)
>>
>> /* these helpers provide future and backwards compatibility
>> * for accessing popular PCI BAR info */
>> -#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
>> -#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
>> -#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
>> -#define pci_resource_len(dev,bar) \
>> - ((pci_resource_start((dev), (bar)) == 0 && \
>> - pci_resource_end((dev), (bar)) == \
>> - pci_resource_start((dev), (bar))) ? 0 : \
>> - \
>> - (pci_resource_end((dev), (bar)) - \
>> - pci_resource_start((dev), (bar)) + 1))
>> +static inline resource_size_t
>> +pci_resource_start(const struct pci_dev *dev, int index)
>> +{
>> + return dev->resource[index].start;
>> +}
>> +
>> +static inline resource_size_t
>> +pci_resource_end(const struct pci_dev *dev, int index)
>> +{
>> + return dev->resource[index].end;
>> +}
>> +
>> +static inline unsigned long
>> +pci_resource_flags(const struct pci_dev *dev, int index)
>> +{
>> + return dev->resource[index].flags;
>> +}
>> +
>> +static inline resource_size_t
>> +pci_resource_len(const struct pci_dev *dev, int index)
>> +{
>> + if (pci_resource_start(dev, index) == 0 &&
>> + pci_resource_end(dev, index) == 0)
>> + return 0;
>> + return resource_size(&dev->resource[index]);
>> +}
>>
>> /* Similar to the helpers above, these manipulate per-pci_dev
>> * driver-specific data. They are really just a wrapper around
>>
>>
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-07 23:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-18 18:51 [PATCH] pci: Convert pci_resource_<foo> macros to static inlines Joe Perches
2012-11-05 22:28 ` Bjorn Helgaas
2012-11-07 23:00 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).