From patchwork Fri Aug 28 06:34:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 11742207 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF3EF739 for ; Fri, 28 Aug 2020 06:35:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E145C2098B for ; Fri, 28 Aug 2020 06:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbgH1Gey (ORCPT ); Fri, 28 Aug 2020 02:34:54 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:10292 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726924AbgH1Gew (ORCPT ); Fri, 28 Aug 2020 02:34:52 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9122B3DE697E466C2F45; Fri, 28 Aug 2020 14:34:46 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 28 Aug 2020 14:34:40 +0800 From: Yang Yingliang To: , CC: , , Subject: [PATCH 1/2] iomap: move some definitions to include/linux/io.h Date: Fri, 28 Aug 2020 14:34:02 +0800 Message-ID: <20200828063403.3995421-2-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200828063403.3995421-1-yangyingliang@huawei.com> References: <20200828063403.3995421-1-yangyingliang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Move some IO macros and bad_io_access() to include/linux/io.h This prepares for moving pci_iounmap() to lib/pci_iomap.c. Signed-off-by: Yang Yingliang --- include/linux/io.h | 36 ++++++++++++++++++++++++++++++++++++ lib/iomap.c | 36 ------------------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index 8394c56babc26..fa040f8114eaa 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -13,6 +13,42 @@ #include #include +#ifndef HAVE_ARCH_PIO_SIZE +/* + * We encode the physical PIO addresses (0-0xffff) into the + * pointer by offsetting them with a constant (0x10000) and + * assuming that all the low addresses are always PIO. That means + * we can do some sanity checks on the low bits, and don't + * need to just take things for granted. + */ +#define PIO_OFFSET 0x10000UL +#define PIO_MASK 0x0ffffUL +#define PIO_RESERVED 0x40000UL +#endif + +static inline void bad_io_access(unsigned long port, const char *access) +{ + static int count = 10; + if (count) { + count--; + WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access); + } +} + +/* + * Ugly macros are a way of life. + */ +#define IO_COND(addr, is_pio, is_mmio) do { \ + unsigned long port = (unsigned long __force)addr; \ + if (port >= PIO_RESERVED) { \ + is_mmio; \ + } else if (port > PIO_OFFSET) { \ + port &= PIO_MASK; \ + is_pio; \ + } else \ + bad_io_access(port, #is_pio); \ +} while (0) + struct device; struct resource; diff --git a/lib/iomap.c b/lib/iomap.c index fbaa3e8f19d6c..d40bc6f662540 100644 --- a/lib/iomap.c +++ b/lib/iomap.c @@ -23,42 +23,6 @@ * implementation and should do their own copy. */ -#ifndef HAVE_ARCH_PIO_SIZE -/* - * We encode the physical PIO addresses (0-0xffff) into the - * pointer by offsetting them with a constant (0x10000) and - * assuming that all the low addresses are always PIO. That means - * we can do some sanity checks on the low bits, and don't - * need to just take things for granted. - */ -#define PIO_OFFSET 0x10000UL -#define PIO_MASK 0x0ffffUL -#define PIO_RESERVED 0x40000UL -#endif - -static void bad_io_access(unsigned long port, const char *access) -{ - static int count = 10; - if (count) { - count--; - WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access); - } -} - -/* - * Ugly macros are a way of life. - */ -#define IO_COND(addr, is_pio, is_mmio) do { \ - unsigned long port = (unsigned long __force)addr; \ - if (port >= PIO_RESERVED) { \ - is_mmio; \ - } else if (port > PIO_OFFSET) { \ - port &= PIO_MASK; \ - is_pio; \ - } else \ - bad_io_access(port, #is_pio ); \ -} while (0) - #ifndef pio_read16be #define pio_read16be(port) swab16(inw(port)) #define pio_read32be(port) swab32(inl(port)) From patchwork Fri Aug 28 06:34:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 11742205 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC6F3739 for ; Fri, 28 Aug 2020 06:35:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB14F2098B for ; Fri, 28 Aug 2020 06:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbgH1Gez (ORCPT ); Fri, 28 Aug 2020 02:34:55 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:53614 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725858AbgH1Gey (ORCPT ); Fri, 28 Aug 2020 02:34:54 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9AC45A4D203992BB1321; Fri, 28 Aug 2020 14:34:51 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 28 Aug 2020 14:34:41 +0800 From: Yang Yingliang To: , CC: , , Subject: [PATCH 2/2] pci: fix memleak when calling pci_iomap/unmap() Date: Fri, 28 Aug 2020 14:34:03 +0800 Message-ID: <20200828063403.3995421-3-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200828063403.3995421-1-yangyingliang@huawei.com> References: <20200828063403.3995421-1-yangyingliang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org config GENERIC_IOMAP is disabled on some archs(e.g. arm64), so pci_iounmap() does nothing, when we using pci_iomap/pci_iounmap(), it will lead to memory leak. Move pci_iounmap() to lib/pci_map.c to fix this. Signed-off-by: Yang Yingliang Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: kernel test robot --- include/asm-generic/pci_iomap.h | 2 ++ lib/iomap.c | 10 ---------- lib/pci_iomap.c | 8 ++++++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/asm-generic/pci_iomap.h b/include/asm-generic/pci_iomap.h index d4f16dcc2ed79..d6a04d2462238 100644 --- a/include/asm-generic/pci_iomap.h +++ b/include/asm-generic/pci_iomap.h @@ -18,6 +18,8 @@ extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar, extern void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar, unsigned long offset, unsigned long maxlen); +#define pci_iounmap pci_iounmap +extern void pci_iounmap(struct pci_dev *dev, void __iomem * addr); /* Create a virtual mapping cookie for a port on a given PCI device. * Do not call this directly, it exists to make it easier for architectures * to override */ diff --git a/lib/iomap.c b/lib/iomap.c index d40bc6f662540..df0b3c5fa2065 100644 --- a/lib/iomap.c +++ b/lib/iomap.c @@ -337,13 +337,3 @@ void ioport_unmap(void __iomem *addr) EXPORT_SYMBOL(ioport_map); EXPORT_SYMBOL(ioport_unmap); #endif /* CONFIG_HAS_IOPORT_MAP */ - -#ifdef CONFIG_PCI -/* Hide the details if this is a MMIO or PIO address space and just do what - * you expect in the correct way. */ -void pci_iounmap(struct pci_dev *dev, void __iomem * addr) -{ - IO_COND(addr, /* nothing */, iounmap(addr)); -} -EXPORT_SYMBOL(pci_iounmap); -#endif /* CONFIG_PCI */ diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c index 2d3eb1cb73b8f..833b702771ecd 100644 --- a/lib/pci_iomap.c +++ b/lib/pci_iomap.c @@ -134,4 +134,12 @@ void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen) return pci_iomap_wc_range(dev, bar, 0, maxlen); } EXPORT_SYMBOL_GPL(pci_iomap_wc); + +/* Hide the details if this is a MMIO or PIO address space and just do what + * you expect in the correct way. */ +void pci_iounmap(struct pci_dev *dev, void __iomem * addr) +{ + IO_COND(addr, /* nothing */, iounmap(addr)); +} +EXPORT_SYMBOL(pci_iounmap); #endif /* CONFIG_PCI */