linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci <linux-pci@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] pci: Convert pci_resource_<foo> macros to static inlines
Date: Tue, 18 Sep 2012 11:51:54 -0700	[thread overview]
Message-ID: <1347994314.9011.1.camel@joe2Laptop> (raw)

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




             reply	other threads:[~2012-09-18 18:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 18:51 Joe Perches [this message]
2012-11-05 22:28 ` [PATCH] pci: Convert pci_resource_<foo> macros to static inlines Bjorn Helgaas
2012-11-07 23:00   ` Bjorn Helgaas

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=1347994314.9011.1.camel@joe2Laptop \
    --to=joe@perches.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@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;
as well as URLs for NNTP newsgroup(s).