* [PATCH 1/2] resource: Copy the whole res in resource_list_create_entry @ 2017-03-22 2:25 Jeffy Chen 2017-03-22 2:25 ` [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources Jeffy Chen 0 siblings, 1 reply; 8+ messages in thread From: Jeffy Chen @ 2017-03-22 2:25 UTC (permalink / raw) To: linux-kernel Cc: robh, toshi.kani, shawn.lin, briannorris, dianders, bhelgaas, dtor, Jeffy Chen We do this so the callers may not need worry about when to free the allocated resource struct. Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> --- kernel/resource.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index 9b5f044..f3594f8 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1595,7 +1595,9 @@ struct resource_entry *resource_list_create_entry(struct resource *res, entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL); if (entry) { INIT_LIST_HEAD(&entry->node); - entry->res = res ? res : &entry->__res; + entry->res = &entry->__res; + if (res) + entry->__res = *res; } return entry; -- 2.1.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources 2017-03-22 2:25 [PATCH 1/2] resource: Copy the whole res in resource_list_create_entry Jeffy Chen @ 2017-03-22 2:25 ` Jeffy Chen 2017-03-22 14:39 ` Rob Herring 0 siblings, 1 reply; 8+ messages in thread From: Jeffy Chen @ 2017-03-22 2:25 UTC (permalink / raw) To: linux-kernel Cc: robh, toshi.kani, shawn.lin, briannorris, dianders, bhelgaas, dtor, Jeffy Chen, Frank Rowand, devicetree, Rob Herring Currently we only free the allocated resource struct when error. This would cause memory leak after pci_free_resource_list. Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> --- drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 0ee42c3..269393bc 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, unsigned char busno, unsigned char bus_max, struct list_head *resources, resource_size_t *io_base) { - struct resource_entry *window; - struct resource *res; - struct resource *bus_range; + struct resource res; struct of_pci_range range; struct of_pci_range_parser parser; char range_type[4]; @@ -200,24 +198,19 @@ 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 (!bus_range) - return -ENOMEM; - pr_info("host bridge %s ranges:\n", dev->full_name); - err = of_pci_parse_bus_range(dev, bus_range); + err = of_pci_parse_bus_range(dev, &res); if (err) { - bus_range->start = busno; - bus_range->end = bus_max; - bus_range->flags = IORESOURCE_BUS; - pr_info(" No bus range found for %s, using %pR\n", - dev->full_name, bus_range); + res.start = busno; + res.end = bus_max; + res.flags = IORESOURCE_BUS; + pr_info(" No bus range found for %s\n", dev->full_name); } else { - if (bus_range->end > bus_range->start + bus_max) - bus_range->end = bus_range->start + bus_max; + if (res.end > res.start + bus_max) + res.end = res.start + bus_max; } - pci_add_resource(resources, bus_range); + pci_add_resource(resources, &res); /* Check for ranges property */ err = of_pci_range_parser_init(&parser, dev); @@ -244,24 +237,16 @@ 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 (!res) { - err = -ENOMEM; - goto parse_failed; - } - - err = of_pci_range_to_resource(&range, dev, res); - if (err) { - kfree(res); + err = of_pci_range_to_resource(&range, dev, &res); + if (err) continue; - } - if (resource_type(res) == IORESOURCE_IO) { + if (resource_type(&res) == IORESOURCE_IO) { if (!io_base) { pr_err("I/O range found for %s. Please provide an io_base pointer to save CPU base address\n", dev->full_name); err = -EINVAL; - goto conversion_failed; + goto parse_failed; } if (*io_base != (resource_size_t)OF_BAD_ADDR) pr_warn("More than one I/O resource converted for %s. CPU base address for old range lost!\n", @@ -269,16 +254,13 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, *io_base = range.cpu_addr; } - pci_add_resource_offset(resources, res, res->start - range.pci_addr); + pci_add_resource_offset(resources, &res, + res.start - range.pci_addr); } 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; } -- 2.1.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-22 14:39 ` Rob Herring 0 siblings, 0 replies; 8+ messages in thread From: Rob Herring @ 2017-03-22 14:39 UTC (permalink / raw) To: Jeffy Chen Cc: linux-kernel, toshi.kani, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas, Dmitry Torokhov, Frank Rowand, devicetree On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen@rock-chips.com> wrote: > Currently we only free the allocated resource struct when error. > This would cause memory leak after pci_free_resource_list. > > Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> > --- > > drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- > 1 file changed, 15 insertions(+), 33 deletions(-) > > diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c > index 0ee42c3..269393bc 100644 > --- a/drivers/of/of_pci.c > +++ b/drivers/of/of_pci.c > @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > unsigned char busno, unsigned char bus_max, > struct list_head *resources, resource_size_t *io_base) > { > - struct resource_entry *window; > - struct resource *res; > - struct resource *bus_range; > + struct resource res; > struct of_pci_range range; > struct of_pci_range_parser parser; > char range_type[4]; > @@ -200,24 +198,19 @@ 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 (!bus_range) > - return -ENOMEM; > - > pr_info("host bridge %s ranges:\n", dev->full_name); > > - err = of_pci_parse_bus_range(dev, bus_range); > + err = of_pci_parse_bus_range(dev, &res); > if (err) { > - bus_range->start = busno; > - bus_range->end = bus_max; > - bus_range->flags = IORESOURCE_BUS; > - pr_info(" No bus range found for %s, using %pR\n", > - dev->full_name, bus_range); > + res.start = busno; > + res.end = bus_max; > + res.flags = IORESOURCE_BUS; > + pr_info(" No bus range found for %s\n", dev->full_name); > } else { > - if (bus_range->end > bus_range->start + bus_max) > - bus_range->end = bus_range->start + bus_max; > + if (res.end > res.start + bus_max) > + res.end = res.start + bus_max; > } > - pci_add_resource(resources, bus_range); > + pci_add_resource(resources, &res); You are passing a stack variable to pci_add_resource and it doesn't make a copy of it. I assume the resource needs to live after you exit this function. If we have a leak, can't you just add a free in the correct spot? That would be a lot easier to review. Rob ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-22 14:39 ` Rob Herring 0 siblings, 0 replies; 8+ messages in thread From: Rob Herring @ 2017-03-22 14:39 UTC (permalink / raw) To: Jeffy Chen Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, toshi.kani-ZPxbGqLxI0U, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas-hpIqsD4AKlfQT0dZR+AlfA, Dmitry Torokhov, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> wrote: > Currently we only free the allocated resource struct when error. > This would cause memory leak after pci_free_resource_list. > > Signed-off-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> > --- > > drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- > 1 file changed, 15 insertions(+), 33 deletions(-) > > diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c > index 0ee42c3..269393bc 100644 > --- a/drivers/of/of_pci.c > +++ b/drivers/of/of_pci.c > @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, > unsigned char busno, unsigned char bus_max, > struct list_head *resources, resource_size_t *io_base) > { > - struct resource_entry *window; > - struct resource *res; > - struct resource *bus_range; > + struct resource res; > struct of_pci_range range; > struct of_pci_range_parser parser; > char range_type[4]; > @@ -200,24 +198,19 @@ 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 (!bus_range) > - return -ENOMEM; > - > pr_info("host bridge %s ranges:\n", dev->full_name); > > - err = of_pci_parse_bus_range(dev, bus_range); > + err = of_pci_parse_bus_range(dev, &res); > if (err) { > - bus_range->start = busno; > - bus_range->end = bus_max; > - bus_range->flags = IORESOURCE_BUS; > - pr_info(" No bus range found for %s, using %pR\n", > - dev->full_name, bus_range); > + res.start = busno; > + res.end = bus_max; > + res.flags = IORESOURCE_BUS; > + pr_info(" No bus range found for %s\n", dev->full_name); > } else { > - if (bus_range->end > bus_range->start + bus_max) > - bus_range->end = bus_range->start + bus_max; > + if (res.end > res.start + bus_max) > + res.end = res.start + bus_max; > } > - pci_add_resource(resources, bus_range); > + pci_add_resource(resources, &res); You are passing a stack variable to pci_add_resource and it doesn't make a copy of it. I assume the resource needs to live after you exit this function. If we have a leak, can't you just add a free in the correct spot? That would be a lot easier to review. Rob -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-22 14:55 ` Rob Herring 0 siblings, 0 replies; 8+ messages in thread From: Rob Herring @ 2017-03-22 14:55 UTC (permalink / raw) To: Jeffy Chen Cc: linux-kernel, toshi.kani, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas, Dmitry Torokhov, Frank Rowand, devicetree On Wed, Mar 22, 2017 at 9:39 AM, Rob Herring <robh@kernel.org> wrote: > On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen@rock-chips.com> wrote: >> Currently we only free the allocated resource struct when error. >> This would cause memory leak after pci_free_resource_list. >> >> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> >> --- >> >> drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- >> 1 file changed, 15 insertions(+), 33 deletions(-) >> >> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c >> index 0ee42c3..269393bc 100644 >> --- a/drivers/of/of_pci.c >> +++ b/drivers/of/of_pci.c >> @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, >> unsigned char busno, unsigned char bus_max, >> struct list_head *resources, resource_size_t *io_base) >> { >> - struct resource_entry *window; >> - struct resource *res; >> - struct resource *bus_range; >> + struct resource res; >> struct of_pci_range range; >> struct of_pci_range_parser parser; >> char range_type[4]; >> @@ -200,24 +198,19 @@ 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 (!bus_range) >> - return -ENOMEM; >> - >> pr_info("host bridge %s ranges:\n", dev->full_name); >> >> - err = of_pci_parse_bus_range(dev, bus_range); >> + err = of_pci_parse_bus_range(dev, &res); >> if (err) { >> - bus_range->start = busno; >> - bus_range->end = bus_max; >> - bus_range->flags = IORESOURCE_BUS; >> - pr_info(" No bus range found for %s, using %pR\n", >> - dev->full_name, bus_range); >> + res.start = busno; >> + res.end = bus_max; >> + res.flags = IORESOURCE_BUS; >> + pr_info(" No bus range found for %s\n", dev->full_name); >> } else { >> - if (bus_range->end > bus_range->start + bus_max) >> - bus_range->end = bus_range->start + bus_max; >> + if (res.end > res.start + bus_max) >> + res.end = res.start + bus_max; >> } >> - pci_add_resource(resources, bus_range); >> + pci_add_resource(resources, &res); > > You are passing a stack variable to pci_add_resource and it doesn't > make a copy of it. I assume the resource needs to live after you exit > this function. Ah, found your 1st patch changing the behavior. I'm surprised that change works without affecting anyone else. > If we have a leak, can't you just add a free in the correct spot? That > would be a lot easier to review. > > Rob ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-22 14:55 ` Rob Herring 0 siblings, 0 replies; 8+ messages in thread From: Rob Herring @ 2017-03-22 14:55 UTC (permalink / raw) To: Jeffy Chen Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, toshi.kani-ZPxbGqLxI0U, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas-hpIqsD4AKlfQT0dZR+AlfA, Dmitry Torokhov, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA On Wed, Mar 22, 2017 at 9:39 AM, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote: > On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> wrote: >> Currently we only free the allocated resource struct when error. >> This would cause memory leak after pci_free_resource_list. >> >> Signed-off-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> >> --- >> >> drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- >> 1 file changed, 15 insertions(+), 33 deletions(-) >> >> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c >> index 0ee42c3..269393bc 100644 >> --- a/drivers/of/of_pci.c >> +++ b/drivers/of/of_pci.c >> @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, >> unsigned char busno, unsigned char bus_max, >> struct list_head *resources, resource_size_t *io_base) >> { >> - struct resource_entry *window; >> - struct resource *res; >> - struct resource *bus_range; >> + struct resource res; >> struct of_pci_range range; >> struct of_pci_range_parser parser; >> char range_type[4]; >> @@ -200,24 +198,19 @@ 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 (!bus_range) >> - return -ENOMEM; >> - >> pr_info("host bridge %s ranges:\n", dev->full_name); >> >> - err = of_pci_parse_bus_range(dev, bus_range); >> + err = of_pci_parse_bus_range(dev, &res); >> if (err) { >> - bus_range->start = busno; >> - bus_range->end = bus_max; >> - bus_range->flags = IORESOURCE_BUS; >> - pr_info(" No bus range found for %s, using %pR\n", >> - dev->full_name, bus_range); >> + res.start = busno; >> + res.end = bus_max; >> + res.flags = IORESOURCE_BUS; >> + pr_info(" No bus range found for %s\n", dev->full_name); >> } else { >> - if (bus_range->end > bus_range->start + bus_max) >> - bus_range->end = bus_range->start + bus_max; >> + if (res.end > res.start + bus_max) >> + res.end = res.start + bus_max; >> } >> - pci_add_resource(resources, bus_range); >> + pci_add_resource(resources, &res); > > You are passing a stack variable to pci_add_resource and it doesn't > make a copy of it. I assume the resource needs to live after you exit > this function. Ah, found your 1st patch changing the behavior. I'm surprised that change works without affecting anyone else. > If we have a leak, can't you just add a free in the correct spot? That > would be a lot easier to review. > > Rob -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-23 8:22 ` jeffy 0 siblings, 0 replies; 8+ messages in thread From: jeffy @ 2017-03-23 8:22 UTC (permalink / raw) To: Rob Herring Cc: linux-kernel, toshi.kani, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas, Dmitry Torokhov, Frank Rowand, devicetree Hi Rob, On 03/22/2017 10:55 PM, Rob Herring wrote: > On Wed, Mar 22, 2017 at 9:39 AM, Rob Herring <robh@kernel.org> wrote: >> On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen@rock-chips.com> wrote: >>> Currently we only free the allocated resource struct when error. >>> This would cause memory leak after pci_free_resource_list. >>> >>> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> >>> --- >>> >>> drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- >>> 1 file changed, 15 insertions(+), 33 deletions(-) >>> >>> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c >>> index 0ee42c3..269393bc 100644 >>> --- a/drivers/of/of_pci.c >>> +++ b/drivers/of/of_pci.c >>> @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, >>> unsigned char busno, unsigned char bus_max, >>> struct list_head *resources, resource_size_t *io_base) >>> { >>> - struct resource_entry *window; >>> - struct resource *res; >>> - struct resource *bus_range; >>> + struct resource res; >>> struct of_pci_range range; >>> struct of_pci_range_parser parser; >>> char range_type[4]; >>> @@ -200,24 +198,19 @@ 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 (!bus_range) >>> - return -ENOMEM; >>> - >>> pr_info("host bridge %s ranges:\n", dev->full_name); >>> >>> - err = of_pci_parse_bus_range(dev, bus_range); >>> + err = of_pci_parse_bus_range(dev, &res); >>> if (err) { >>> - bus_range->start = busno; >>> - bus_range->end = bus_max; >>> - bus_range->flags = IORESOURCE_BUS; >>> - pr_info(" No bus range found for %s, using %pR\n", >>> - dev->full_name, bus_range); >>> + res.start = busno; >>> + res.end = bus_max; >>> + res.flags = IORESOURCE_BUS; >>> + pr_info(" No bus range found for %s\n", dev->full_name); >>> } else { >>> - if (bus_range->end > bus_range->start + bus_max) >>> - bus_range->end = bus_range->start + bus_max; >>> + if (res.end > res.start + bus_max) >>> + res.end = res.start + bus_max; >>> } >>> - pci_add_resource(resources, bus_range); >>> + pci_add_resource(resources, &res); >> >> You are passing a stack variable to pci_add_resource and it doesn't >> make a copy of it. I assume the resource needs to live after you exit >> this function. > > Ah, found your 1st patch changing the behavior. I'm surprised that > change works without affecting anyone else. sorry, i should add a cover-letter first. and you're right, that would affect others(for example the ioport_resource/iomem_resource). > >> If we have a leak, can't you just add a free in the correct spot? That >> would be a lot easier to review. it seems hard to tell which resources in the list need to be freed after all... >> >> Rob > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources @ 2017-03-23 8:22 ` jeffy 0 siblings, 0 replies; 8+ messages in thread From: jeffy @ 2017-03-23 8:22 UTC (permalink / raw) To: Rob Herring Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, toshi.kani-ZPxbGqLxI0U, Shawn Lin, Brian Norris, Doug Anderson, bhelgaas-hpIqsD4AKlfQT0dZR+AlfA, Dmitry Torokhov, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA Hi Rob, On 03/22/2017 10:55 PM, Rob Herring wrote: > On Wed, Mar 22, 2017 at 9:39 AM, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote: >> On Tue, Mar 21, 2017 at 9:25 PM, Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> wrote: >>> Currently we only free the allocated resource struct when error. >>> This would cause memory leak after pci_free_resource_list. >>> >>> Signed-off-by: Jeffy Chen <jeffy.chen-TNX95d0MmH7DzftRWevZcw@public.gmane.org> >>> --- >>> >>> drivers/of/of_pci.c | 48 +++++++++++++++--------------------------------- >>> 1 file changed, 15 insertions(+), 33 deletions(-) >>> >>> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c >>> index 0ee42c3..269393bc 100644 >>> --- a/drivers/of/of_pci.c >>> +++ b/drivers/of/of_pci.c >>> @@ -189,9 +189,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, >>> unsigned char busno, unsigned char bus_max, >>> struct list_head *resources, resource_size_t *io_base) >>> { >>> - struct resource_entry *window; >>> - struct resource *res; >>> - struct resource *bus_range; >>> + struct resource res; >>> struct of_pci_range range; >>> struct of_pci_range_parser parser; >>> char range_type[4]; >>> @@ -200,24 +198,19 @@ 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 (!bus_range) >>> - return -ENOMEM; >>> - >>> pr_info("host bridge %s ranges:\n", dev->full_name); >>> >>> - err = of_pci_parse_bus_range(dev, bus_range); >>> + err = of_pci_parse_bus_range(dev, &res); >>> if (err) { >>> - bus_range->start = busno; >>> - bus_range->end = bus_max; >>> - bus_range->flags = IORESOURCE_BUS; >>> - pr_info(" No bus range found for %s, using %pR\n", >>> - dev->full_name, bus_range); >>> + res.start = busno; >>> + res.end = bus_max; >>> + res.flags = IORESOURCE_BUS; >>> + pr_info(" No bus range found for %s\n", dev->full_name); >>> } else { >>> - if (bus_range->end > bus_range->start + bus_max) >>> - bus_range->end = bus_range->start + bus_max; >>> + if (res.end > res.start + bus_max) >>> + res.end = res.start + bus_max; >>> } >>> - pci_add_resource(resources, bus_range); >>> + pci_add_resource(resources, &res); >> >> You are passing a stack variable to pci_add_resource and it doesn't >> make a copy of it. I assume the resource needs to live after you exit >> this function. > > Ah, found your 1st patch changing the behavior. I'm surprised that > change works without affecting anyone else. sorry, i should add a cover-letter first. and you're right, that would affect others(for example the ioport_resource/iomem_resource). > >> If we have a leak, can't you just add a free in the correct spot? That >> would be a lot easier to review. it seems hard to tell which resources in the list need to be freed after all... >> >> Rob > > > -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-03-23 8:23 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-03-22 2:25 [PATCH 1/2] resource: Copy the whole res in resource_list_create_entry Jeffy Chen 2017-03-22 2:25 ` [PATCH 2/2] of/pci: Fix memory leak in of_pci_get_host_bridge_resources Jeffy Chen 2017-03-22 14:39 ` Rob Herring 2017-03-22 14:39 ` Rob Herring 2017-03-22 14:55 ` Rob Herring 2017-03-22 14:55 ` Rob Herring 2017-03-23 8:22 ` jeffy 2017-03-23 8:22 ` jeffy
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.