From patchwork Wed May 16 12:31:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 10403809 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 0AE61601F9 for ; Wed, 16 May 2018 12:47:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECA93284CE for ; Wed, 16 May 2018 12:47:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E14F328522; Wed, 16 May 2018 12:47:48 +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=ham 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 60927284CE for ; Wed, 16 May 2018 12:47:48 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=12Ok8kFXCfbXDQk/ZmOKA3dQoKrqUPgaNxJOJtNNiqk=; b=IGHq4Y8IXNN2Yr 1RVYmWzVQTKEQeEIRkHBGMikzhnTUpDnjIxAYYPpqfRZMb2eVImIDCfMH7UoygNMVNTtdp/tl6KAY SYkgO8fm2y/ErbwhxNN6R6/16FIOeR26eEOWpKndm2L8IXFShwPG8T372hGfHW98OO/M/JNde3XQw jb/t7ccbecB3IM3sVeIXX5znB+dQ7EGWMhAmtEolEYLjb5Bqlp/2sLm+bwXMQDK8lV19yfeWFhqSN G1PzesaG3c7KY0O+ha7u2YQT4TGOD0vBbZ5zansSNqXCUwehwFAvtWi3xX5o1wt83POdkOUQvXogx /UfPiS/1GXKzKd9td5eQ==; 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 1fIvqA-0002w3-8x; Wed, 16 May 2018 12:47:34 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIvpV-0002XC-SO for linux-arm-kernel@bombadil.infradead.org; Wed, 16 May 2018 12:46:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8oaBDQh+7HTalm4zyvKwyJVVbZDymH1VLxK3MHTtZ+w=; b=Rf+stLA6UhGs6Ha44cKFO33L4Z DVt2/d9EkwJ6uNw5laS/tGIoxCghl8KYseZk/Lp873qjGDpkxIDnoIDJm7/ZCs9JpbguUVVvHX718 0VvEQ/EbuJO/XDJeFAL1QHKcDXX1HXU24VKXpl5jMAw2132dCgssVrrtfVOHYOIbo8UcKMlG+2Dg6 f/tSDHvv5SQ7JH0Y7oqlp4nlqqXV4/y0Cm11stcblN/in2p4H76IjiTt2iu518IH/QaBuZVCD37xf luK/S6HQ8a4bl4Y8g7BnCBwLGDX1sv+/4XbBv+Hxg0EU9oKVwGOdreB8Pr6sLjOm37xm3+zPVQLss iHCmFzvQ==; Received: from goliath.siemens.de ([192.35.17.28]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIvdw-00089B-Qj for linux-arm-kernel@lists.infradead.org; Wed, 16 May 2018 12:34:58 +0000 Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id w4GCW2we008195 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 May 2018 14:32:03 +0200 Received: from [167.87.141.171] ([167.87.141.171]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id w4GCVlOE019618; Wed, 16 May 2018 14:31:55 +0200 Subject: [PATCH] PCI: Clean up resource allocation in devm_of_pci_get_host_bridge_resources() To: Bjorn Helgaas , Linux Kernel Mailing List References: <3aeb2ed038cbce8fe744b614dc19d414555a7e8f.1526375226.git.jan.kiszka@siemens.com> From: Jan Kiszka Openpgp: preference=signencrypt Autocrypt: addr=jan.kiszka@siemens.com; prefer-encrypt=mutual; keydata= xsDhBEq0i8QRBAD2wOxlC9m/8t/vqjm1U9yQCT6OJ2Wbv/qys9DYM0CvcOTDMWQwmV1/VsZj KR5YgB5NPt+To7X6x5cjz15AGnx5Fb8Wnrq8EF9ZfHMwb7YMx1LdPYPDnXr37wE3XupFmkHB Mes4htyX7Dz8LvKDLnli4IsAmWG+kV1JI6LWKXLpSwCg8JRq4SWoB4VCQxbH3GjntgvwNc8D /2q5Dj0urJ7s7sdXhrH0hcFkpSFRmU5Yd6MCwcbFHm2paL5gqVjNNUUwDBKAL9eZaQVIHKwC 44BvNGO2gcQ26R3AuCHUQ+pZHg34tok1JCNZ6IEZccb+33Qq0qbcDMJJiDYp7ppp6ozifvc4 YaqJECX48IydxfE9+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JKtIvEAhsMAAoJEIrUrG965ecULvAAoKGvxs5T3IhyQT8I8sMsyAvCE4wH AJ46S16yab+OxNkvOeoOEX0EnHVHaA== Message-ID: Date: Wed, 16 May 2018 14:31:44 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180516_133456_920398_C28B42B6 X-CRM114-Status: GOOD ( 14.23 ) 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: , Cc: Joao Pinto , linux-pci@vger.kernel.org, Andy Shevchenko , Lorenzo Pieralisi , linux-arm Mailing List , Jingoo Han , Vladimir Zapolskiy 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 Instead of first allocating and then freeing memory for struct resource in case we cannot parse a PCI resource from the device tree, work against a local struct and kmemdup it when we decide to go with it. Suggested-by: Andy Shevchenko Signed-off-by: Jan Kiszka Reviewed-by: Vladimir Zapolskiy --- drivers/pci/of.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index b06585a1da75..fc0f906c5c25 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -266,7 +266,7 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, struct list_head *resources, resource_size_t *io_base) { struct device_node *dev_node = dev->of_node; - struct resource *res; + struct resource *res, tmp_res; struct resource *bus_range; struct of_pci_range range; struct of_pci_range_parser parser; @@ -320,18 +320,16 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) continue; - res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL); + err = of_pci_range_to_resource(&range, dev_node, &tmp_res); + if (err) + continue; + + res = devm_kmemdup(dev, &tmp_res, sizeof(tmp_res), GFP_KERNEL); if (!res) { err = -ENOMEM; goto failed; } - err = of_pci_range_to_resource(&range, dev_node, res); - if (err) { - devm_kfree(dev, res); - continue; - } - if (resource_type(res) == IORESOURCE_IO) { if (!io_base) { dev_err(dev,