[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180605204407.GA226399@bhelgaas-glaptop.roam.corp.google.com>
Date: Tue, 5 Jun 2018 15:44:07 -0500
From: Bjorn Helgaas <helgaas@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Jan Kiszka <jan.kiszka@...mens.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-pci@...r.kernel.org,
linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>,
Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>,
Jingoo Han <jingoohan1@...il.com>,
Joao Pinto <Joao.Pinto@...opsys.com>,
Lorenzo Pieralisi <lorenzo.pieralisi@....com>
Subject: Re: [PATCH] PCI: Clean up resource allocation in
devm_of_pci_get_host_bridge_resources()
On Tue, Jun 05, 2018 at 07:26:57PM +0300, Andy Shevchenko wrote:
> On Wed, May 16, 2018 at 3:31 PM, Jan Kiszka <jan.kiszka@...mens.com> wrote:
> > 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.
> >
>
> Bjorn, any comments on this?
I'm trying to finish up the v4.18 changes now, but I'll look at this later.
If it's urgent, let me know and I can look sooner.
> > Suggested-by: Andy Shevchenko <andy.shevchenko@...il.com>
> > Signed-off-by: Jan Kiszka <jan.kiszka@...mens.com>
> > ---
> > 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,
> > --
> > 2.13.6
>
>
>
> --
> With Best Regards,
> Andy Shevchenko
Powered by blists - more mailing lists