From patchwork Sun May 13 18:22:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 10396351 X-Patchwork-Delegate: bhelgaas@google.com 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 A516860215 for ; Sun, 13 May 2018 18:22:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 938FE28ECE for ; Sun, 13 May 2018 18:22:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8835429074; Sun, 13 May 2018 18:22:21 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5E528ECE for ; Sun, 13 May 2018 18:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752015AbeEMSWU (ORCPT ); Sun, 13 May 2018 14:22:20 -0400 Received: from thoth.sbs.de ([192.35.17.2]:51766 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752014AbeEMSWT (ORCPT ); Sun, 13 May 2018 14:22:19 -0400 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id w4DIM64g024731 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 May 2018 20:22:06 +0200 Received: from [167.87.29.52] ([167.87.29.52]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w4DIM5X2005901; Sun, 13 May 2018 20:22:06 +0200 Subject: [PATCH] PCI: Fix error cleanup paths in devm_of_pci_get_host_bridge_resources() To: Bjorn Helgaas Cc: Julia Lawall , linux-pci@vger.kernel.org, kbuild-all@01.org References: <3b005d1f-ee86-722b-d5ba-d543c044a941@siemens.com> <4720dc4c-9055-2616-c58b-d40895b9477c@siemens.com> <20180511222750.GA211882@bhelgaas-glaptop.roam.corp.google.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+41oV7T5vNAzA/QL/UMJyTnu5jiOXcyn5iFQw535lXkwKsqeXzCowLho HICZ2jITJPdTT/+9pGWwMQqST/SS35Tx4EnS3z2BWsNMCLuXCPkxF1elaMJqMfMJxFD8rAgS 9GK6zP6fJlsA1wq/UvKSL8v4QPOnTNCVOsyqJVasGV0ZPcDfcj+ClNO4zR5KYW4gS2lzemth IDxqYW4ua2lzemthQHdlYi5kZT7CYwQTEQIAIwIbIwYLCQgHAwIEFQIIAwQWAgMBAh4BAheA BQJOpoNtAhkBAAoJEIrUrG965ecUOPUAoK+Rh12KgCjplHAS0AoiGKwGOuq7AKDEVnBtRAoy VRvp3lOlOx+P2Ay56M7BTQRKtIvEEAgA2/PlX6oyi7dToH0CJCHq0eKmZaa7CmGaVnxyeepK vIfiM8n8Td76AbG64fjREMwgSpb4F/UytF3z/03tj4e49W/zKjbBRB2/wmFRlZBC9crg22Q+ bgvMOsxnC6uHXaWN8fL+jVei/5OoHOoFqaMsX8EvploitlI/BPj+VgW26jksf3YZyk1hncls Z/IYhXzgRmVJo4RiTW/YLQAkwndwc+fKPa/IYLEDW1Jc4kNLoK0P90b45zju0hpl0C00pVOR TOtzFK9G5Ha7qOAWJfAVJORHKAkkvwftf3hkpPdLyvZUWRHXvUexmA61fLvDBAFhRxYGD8t5 gz88SF5Tzq+0ywADBQf/YSkaYrEslPWiCA2wU6EW0yaqBQAobFsOMvsufJ6o2ntq5Ncq37VI 3KCT67eHPE9x+zPcENoZWsRrC9S9PCf1LOsi7ybZsR13AJqDFlRzJZ4klh9QwgwFZxUBzOdI vttwzG1QkzHx06RKZluFYpPF3DRduSMukdIJ2wmWCU+ohB+mYefe65JGjYQfHVs8mgYVFOPx bRea9VJACCMuspoZWpj43UdR1lLLyIUFYz+jqcPW7Hd/GTIw4N67pYl0dwPDmFd4ohJ5g4Zp q61toNysBGEuEm5GCcn0VmGtQpSYnR5cVm5b2yPz4bIuFOSuZUo/l7vitdY0iy0/wvKbBC+N K8JJBBgRAgAJBQJKtIvEAhsMAAoJEIrUrG965ecULvAAoKGvxs5T3IhyQT8I8sMsyAvCE4wH AJ46S16yab+OxNkvOeoOEX0EnHVHaA== Message-ID: <294ff38c-f8df-f89b-3bac-604e79fe6cfe@siemens.com> Date: Sun, 13 May 2018 20:22:05 +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: <20180511222750.GA211882@bhelgaas-glaptop.roam.corp.google.com> Content-Language: en-US Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fallouts from the conversion to devm_kzalloc: In case the function fails, we no longer need to clean up managed allocations. In fact, we must not. Only one case requires explicit freeing, and that is when of_pci_range_to_resource() fails and we simply skip over the related resource entry. Reported-by: Julia Lawall Fixes: 07adab611304 ("PCI: Add dev parameter to __of_pci_get_host_bridge_resources()") Signed-off-by: Jan Kiszka --- drivers/pci/of.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 38469ffd1d7e..ad8cc1d677f3 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -266,7 +266,6 @@ 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_entry *window; struct resource *res; struct resource *bus_range; struct of_pci_range range; @@ -299,7 +298,7 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, /* Check for ranges property */ err = of_pci_range_parser_init(&parser, dev_node); if (err) - goto parse_failed; + return err; dev_dbg(dev, "Parsing ranges property...\n"); for_each_of_pci_range(&parser, &range) { @@ -322,14 +321,12 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, continue; res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL); - if (!res) { - err = -ENOMEM; - goto parse_failed; - } + if (!res) + return -ENOMEM; err = of_pci_range_to_resource(&range, dev_node, res); if (err) { - kfree(res); + devm_kfree(dev, res); continue; } @@ -338,8 +335,7 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, dev_err(dev, "I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n", dev_node); - err = -EINVAL; - goto conversion_failed; + return -EINVAL; } if (*io_base != (resource_size_t)OF_BAD_ADDR) dev_warn(dev, @@ -352,14 +348,6 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev, } return 0; - -conversion_failed: - kfree(res); -parse_failed: - resource_list_for_each_entry(window, resources) - kfree(window->res); - pci_free_resource_list(resources); - return err; } EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources); #endif /* CONFIG_OF_ADDRESS */