From patchwork Tue Sep 18 18:51:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 1474331 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id C857FDF24C for ; Tue, 18 Sep 2012 18:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753532Ab2IRSv6 (ORCPT ); Tue, 18 Sep 2012 14:51:58 -0400 Received: from perches-mx.perches.com ([206.117.179.246]:60422 "EHLO labridge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751658Ab2IRSv5 (ORCPT ); Tue, 18 Sep 2012 14:51:57 -0400 Received: from [98.149.132.134] (account joe@perches.com HELO [10.0.0.24]) by labridge.com (CommuniGate Pro SMTP 5.0.14) with ESMTPA id 19628457; Tue, 18 Sep 2012 11:51:55 -0700 Message-ID: <1347994314.9011.1.camel@joe2Laptop> Subject: [PATCH] pci: Convert pci_resource_ macros to static inlines From: Joe Perches To: Bjorn Helgaas Cc: linux-pci , LKML Date: Tue, 18 Sep 2012 11:51:54 -0700 X-Mailer: Evolution 3.2.2- Mime-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Get the compiler to verify the argument type of struct pci_dev *. Signed-off-by: Joe Perches --- Another possible improvement is to range check index. include/linux/pci.h | 36 ++++++++++++++++++++++++++---------- 1 files changed, 26 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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