From patchwork Mon Apr 30 05:48:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 10370841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C71FE60384 for ; Mon, 30 Apr 2018 05:52:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B49C2286BC for ; Mon, 30 Apr 2018 05:52:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A85EF28A28; Mon, 30 Apr 2018 05:52:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 28321286BC for ; Mon, 30 Apr 2018 05:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yQCRN3IEscbdRbV7jcmPe+9F4aCYauYxliFpJKZ/hsk=; b=N/R/JctJxB7i6s Qp6+cYYpMkxcpTUt09K6vkXsaEmgwE+Ez2GRPOMNE/GsuZX4GojG9H8RDGD6fyBvF+TAAivXJFCa2 yo1b36Jfno13zDmty+6ukWmpSzgC51i9julVLtxTSTN6VZHJ0Xo8sUhN+Cv1mbBC2U+uC5CFlBaMB anZB/imAzC1/lJJ+bInOjtYt2tSo0+zqQR2aQU4huSyaHMIva5AnVM7Qa0URV1BwmTqoao7owkC9p CVB6teCw/CqdFUH1gw3neAJvozEoaYzgkY4mMLvB64CILDdbP+NR0xACCqOv+Rg8V4/UW90u9LEFZ MAYa+aiVYZcQxFI+5SXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fD1jg-0005Ja-Hr; Mon, 30 Apr 2018 05:52:28 +0000 Received: from goliath.siemens.de ([192.35.17.28]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fD1gP-0002j8-Af for linux-arm-kernel@lists.infradead.org; Mon, 30 Apr 2018 05:49:10 +0000 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id w3U5ml40016809 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Apr 2018 07:48:47 +0200 Received: from md1f2u6c.ww002.siemens.net ([167.87.54.87]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w3U5mj6u003250; Mon, 30 Apr 2018 07:48:47 +0200 From: Jan Kiszka To: Bjorn Helgaas , Linux Kernel Mailing List , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 04/10] PCI: Add dev parameter to __of_pci_get_host_bridge_resources() Date: Mon, 30 Apr 2018 07:48:38 +0200 Message-Id: X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180429_224905_717544_594A5B0D X-CRM114-Status: GOOD ( 11.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Kiszka When non-NULL, use the new dev parameter of __of_pci_get_host_bridge_resources() to allocate the resource data structures via devm_kzalloc. That allows to release them automatically during device destruction. Signed-off-by: Jan Kiszka Reviewed-by: Vladimir Zapolskiy Tested-by: Vladimir Zapolskiy --- drivers/pci/of.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 375de447a58e..bfa282b538d5 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -243,7 +243,7 @@ void of_pci_check_probe_only(void) EXPORT_SYMBOL_GPL(of_pci_check_probe_only); #if defined(CONFIG_OF_ADDRESS) -static int __of_pci_get_host_bridge_resources( +static int __of_pci_get_host_bridge_resources(struct device *dev, struct device_node *dev_node, unsigned char busno, unsigned char bus_max, struct list_head *resources, resource_size_t *io_base) @@ -259,7 +259,10 @@ static int __of_pci_get_host_bridge_resources( if (io_base) *io_base = (resource_size_t)OF_BAD_ADDR; - bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL); + if (dev) + bus_range = devm_kzalloc(dev,sizeof(*bus_range), GFP_KERNEL); + else + bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL); if (!bus_range) return -ENOMEM; @@ -303,7 +306,11 @@ static int __of_pci_get_host_bridge_resources( if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) continue; - res = kzalloc(sizeof(struct resource), GFP_KERNEL); + if (dev) + res = devm_kzalloc(dev, sizeof(struct resource), + GFP_KERNEL); + else + res = kzalloc(sizeof(struct resource), GFP_KERNEL); if (!res) { err = -ENOMEM; goto parse_failed; @@ -365,7 +372,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev_node, unsigned char busno, unsigned char bus_max, struct list_head *resources, resource_size_t *io_base) { - return __of_pci_get_host_bridge_resources(dev_node, busno, + return __of_pci_get_host_bridge_resources(NULL, dev_node, busno, bus_max, resources, io_base); } EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);