Received: by 10.192.165.148 with SMTP id m20csp526866imm; Wed, 25 Apr 2018 03:41:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpemPxfClRPJ2kxGOysEgZdjd2nWRaEh5okhwP9QUWm7U3FJo9m5gy8lZFK6ZOzTcR/gyR5 X-Received: by 10.99.173.3 with SMTP id g3mr3141585pgf.188.1524652915307; Wed, 25 Apr 2018 03:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524652915; cv=none; d=google.com; s=arc-20160816; b=ksZx5OAG0HLhf/uvod6VOz/7pt7nvldjwCTu4I4E+Wj4/hC+prnJyRj5s00k9kwL+o o0aXfgDNHxJA86zAOAhqU/EXipsmBUoRzZgNAFaFv6vunFyblMJe+qK8NVD+eoFf0k09 XkOA4M56nOPjo29PM6KJ169vCzNur6a2WIjsTC+CqyX7L/BnQRXh+JUoEfjOTNgF6YMO uSIngcMG1St9as3DtLbNKxSe/vXlbSJV1I0Fwh1ZCsvS9Y393ZPGe0xZgJPYhgSD7jGX 7DXLATbS/tt+CZ96AYSJih60ZewAL00RH11QArtRX0uqILeOMZWO7dG/fBhaBTGqKQ7u hIIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:openpgp:references:to:from:subject :arc-authentication-results; bh=YzlR23unHSLQVfQwEVlpjEqoNdqrxyJpmejyo9fDgUg=; b=MJxfW4EZJhoSgRv+AT2z7hd8rnQjKDcTIv8ugN05HUexff2RcQIL75+6f5Di29EBKy HKz72or2NeU6o1pBJKQuZG7uYhqM7U31K0VRwmGKmpRU11rFNtVa3p7L49uzb6G4g6nl SOQ9UGas7/rmvoJm8jhsGJOddP7qrkGFwog6pDxLJk9+YyHlRgeUGULKfSy5t7AUai8c 9YSRI5m64tba89x+s+zjk+o4JWbALnjYnqgb0TOzkgYSdm3wyRRqdv5bzaMudzIC99oM HyjRaMsmmSDnwVH/WuQR2Sg3/F3YgD1XQ3Ev8rEZ2W4Yvf8qGGUcuFUyNc0x/y7BxmNa eyZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69-v6si3424833pli.391.2018.04.25.03.41.41; Wed, 25 Apr 2018 03:41:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753846AbeDYKkn (ORCPT + 99 others); Wed, 25 Apr 2018 06:40:43 -0400 Received: from david.siemens.de ([192.35.17.14]:49437 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753263AbeDYKk3 (ORCPT ); Wed, 25 Apr 2018 06:40:29 -0400 Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w3PAeB2Y016334 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Apr 2018 12:40:11 +0200 Received: from [139.25.68.37] (md1q0hnc.ad001.siemens.net [139.25.68.37] (may be forged)) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id w3PAeAKi023011; Wed, 25 Apr 2018 12:40:10 +0200 Subject: Re: [PATCH 3/6] PCI: Introduce devm_of_pci_get_host_bridge_resources From: Jan Kiszka To: Bjorn Helgaas , Linux Kernel Mailing List , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: Openpgp: preference=signencrypt Message-ID: <3920f35d-e667-4ff2-83e0-8f35ea078b23@siemens.com> Date: Wed, 25 Apr 2018 12:40:09 +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-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-04-24 17:13, Jan Kiszka wrote: > From: Jan Kiszka > > of_pci_get_host_bridge_resources allocates the resource structures it > fills dynamically, but none of its callers care to release them so far. > Rather than requiring everyone to do this explicitly, introduce a > managed version of that service. This differs API-wise only in taking a > reference to the associated device, rather than to the device tree node. > > As of_pci_get_host_bridge_resources is an exported interface, we cannot > simply drop it at this point. After converting all in-tree users to the > new API, we could phase out the unmanaged one over some grace period. > > Signed-off-by: Jan Kiszka > --- > drivers/pci/of.c | 89 ++++++++++++++++++++++++++++++++------------------ > include/linux/of_pci.h | 14 ++++++-- > 2 files changed, 70 insertions(+), 33 deletions(-) > > diff --git a/drivers/pci/of.c b/drivers/pci/of.c > index a28355c273ae..6eab0bde2ab3 100644 > --- a/drivers/pci/of.c > +++ b/drivers/pci/of.c > @@ -243,26 +243,8 @@ void of_pci_check_probe_only(void) > EXPORT_SYMBOL_GPL(of_pci_check_probe_only); > > #if defined(CONFIG_OF_ADDRESS) > -/** > - * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT > - * @dev: device node of the host bridge having the range property > - * @busno: bus number associated with the bridge root bus > - * @bus_max: maximum number of buses for this bridge > - * @resources: list where the range of resources will be added after DT parsing > - * @io_base: pointer to a variable that will contain on return the physical > - * address for the start of the I/O range. Can be NULL if the caller doesn't > - * expect I/O ranges to be present in the device tree. > - * > - * It is the caller's job to free the @resources list. > - * > - * This function will parse the "ranges" property of a PCI host bridge device > - * node and setup the resource mapping based on its content. It is expected > - * that the property conforms with the Power ePAPR document. > - * > - * It returns zero if the range parsing has been successful or a standard error > - * value if it failed. > - */ > -int of_pci_get_host_bridge_resources(struct device_node *dev, > +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) > { > @@ -277,19 +259,22 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > 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; > > - pr_info("host bridge %pOF ranges:\n", dev); > + pr_info("host bridge %pOF ranges:\n", dev_node); > > - err = of_pci_parse_bus_range(dev, bus_range); > + err = of_pci_parse_bus_range(dev_node, bus_range); > if (err) { > bus_range->start = busno; > bus_range->end = bus_max; > bus_range->flags = IORESOURCE_BUS; > pr_info(" No bus range found for %pOF, using %pR\n", > - dev, bus_range); > + dev_node, bus_range); > } else { > if (bus_range->end > bus_range->start + bus_max) > bus_range->end = bus_range->start + bus_max; > @@ -297,7 +282,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > pci_add_resource(resources, bus_range); > > /* Check for ranges property */ > - err = of_pci_range_parser_init(&parser, dev); > + err = of_pci_range_parser_init(&parser, dev_node); > if (err) > goto parse_failed; > > @@ -321,13 +306,17 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > 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; > } > > - err = of_pci_range_to_resource(&range, dev, res); > + err = of_pci_range_to_resource(&range, dev_node, res); > if (err) { > kfree(res); > continue; > @@ -336,13 +325,13 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > if (resource_type(res) == IORESOURCE_IO) { > if (!io_base) { > pr_err("I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n", > - dev); > + dev_node); > err = -EINVAL; > goto conversion_failed; > } > if (*io_base != (resource_size_t)OF_BAD_ADDR) > pr_warn("More than one I/O resource converted for %pOF. CPU base address for old range lost!\n", > - dev); > + dev_node); > *io_base = range.cpu_addr; > } > > @@ -354,12 +343,50 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > conversion_failed: > kfree(res); > parse_failed: > - resource_list_for_each_entry(window, resources) > - kfree(window->res); > + if (!dev); > + resource_list_for_each_entry(window, resources) > + kfree(window->res); > pci_free_resource_list(resources); > return err; > } > + > +/** > + * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT > + * @dev: device node of the host bridge having the range property > + * @busno: bus number associated with the bridge root bus > + * @bus_max: maximum number of buses for this bridge > + * @resources: list where the range of resources will be added after DT parsing > + * @io_base: pointer to a variable that will contain on return the physical > + * address for the start of the I/O range. Can be NULL if the caller doesn't > + * expect I/O ranges to be present in the device tree. > + * > + * It is the caller's job to free the @resources list. > + * > + * This function will parse the "ranges" property of a PCI host bridge device > + * node and setup the resource mapping based on its content. It is expected > + * that the property conforms with the Power ePAPR document. > + * > + * It returns zero if the range parsing has been successful or a standard error > + * value if it failed. > + */ > +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(NULL, dev_node, busno, > + bus_max, resources, io_base); > +} > EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); > + > +int devm_of_pci_get_host_bridge_resources(struct device *dev, > + unsigned char busno, unsigned char bus_max, > + struct list_head *resources, resource_size_t *io_base) > +{ > + return __of_pci_get_host_bridge_resources(dev, dev->of_node, busno, > + bus_max, resources, io_base); > +} > +EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources); > + > #endif /* CONFIG_OF_ADDRESS */ > > /** > diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h > index 091033a6b836..08b8f02426a5 100644 > --- a/include/linux/of_pci.h > +++ b/include/linux/of_pci.h > @@ -71,11 +71,21 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin) > #endif > > #if defined(CONFIG_OF_ADDRESS) > -int of_pci_get_host_bridge_resources(struct device_node *dev, > +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); > +int devm_of_pci_get_host_bridge_resources(struct device *dev, > unsigned char busno, unsigned char bus_max, > struct list_head *resources, resource_size_t *io_base); > #else > -static inline int of_pci_get_host_bridge_resources(struct device_node *dev, > +static inline 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 -EINVAL; > +} > + > +static inline int devm_of_pci_get_host_bridge_resources(struct device *dev, > unsigned char busno, unsigned char bus_max, > struct list_head *resources, resource_size_t *io_base) > { > I left a small reviewer exercise in this patch behind, just noticed during a backport. Will resolved it via some v2, just waiting in case there will be further comments. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux