diff options
author | Jacob Garber <jgarber1@ualberta.ca> | 2019-07-17 11:47:19 -0600 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-08-20 15:30:47 +0000 |
commit | 293e6a96a9e19812f17bf6f925415e115612f607 (patch) | |
tree | 16c898c77d69b32bbfa8c56ba8d2cefecf539572 /src/northbridge/amd/pi | |
parent | 4f387e1240dc05d4eff59ae973ab4516cd588e1f (diff) | |
download | coreboot-293e6a96a9e19812f17bf6f925415e115612f607.tar.xz |
nb/amd/pi,sb/amd/sr5650: Remove unnecessary allocation
add_ivrs_device_entries() is a recursive function, and each recursive
call is passed a pointer to a root_level variable declared outside the
function. In an attempt to make the function self-contained, the initial
call is made with the root_level pointer set to NULL, and then the
function attempts to detect this and allocate a root_level variable for
the rest of the calls. This makes memory management very tricky - for
example, the pi code incorrectly attempts to free the root_level
variable at the end of *each* recursive call, which only avoids being a
double-free because free() in coreboot is currently a no-op. Let's
keep life simple and declare root_level as a local variable outside the
first function call instead.
Change-Id: Ifd63ee368fb89345b9b42ccb86cebcca64f32ac8
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Found-by: Coverity CID 1362811
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34387
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/northbridge/amd/pi')
-rw-r--r-- | src/northbridge/amd/pi/00730F01/northbridge.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/northbridge/amd/pi/00730F01/northbridge.c b/src/northbridge/amd/pi/00730F01/northbridge.c index 377d91eeae..ba17c614e5 100644 --- a/src/northbridge/amd/pi/00730F01/northbridge.c +++ b/src/northbridge/amd/pi/00730F01/northbridge.c @@ -491,11 +491,6 @@ static void add_ivrs_device_entries(struct device *parent, struct device *dev, unsigned int header_type; unsigned int is_pcie; - if (!root_level) { - root_level = malloc(sizeof(int8_t)); - *root_level = -1; - } - if (dev->path.type == DEVICE_PATH_PCI) { if ((dev->bus->secondary == 0x0) && @@ -536,8 +531,6 @@ static void add_ivrs_device_entries(struct device *parent, struct device *dev, sibling->sibling) add_ivrs_device_entries(dev, sibling, depth + 1, depth, root_level, current, length); - - free(root_level); } unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current) @@ -643,7 +636,8 @@ static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current) current += 8; /* Describe PCI devices */ - add_ivrs_device_entries(NULL, all_devices, 0, -1, NULL, ¤t, + int8_t root_level = -1; + add_ivrs_device_entries(NULL, all_devices, 0, -1, &root_level, ¤t, &ivrs->ivhd.length); /* Describe IOAPICs */ |