Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/34387 )
Change subject: nb/amd/pi,sr5650: Remove unnecessary memory allocation ......................................................................
nb/amd/pi,sr5650: Remove unnecessary memory 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 dispense with this memory weirdness 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 --- M src/northbridge/amd/pi/00730F01/northbridge.c M src/southbridge/amd/sr5650/sr5650.c 2 files changed, 4 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/34387/1
diff --git a/src/northbridge/amd/pi/00730F01/northbridge.c b/src/northbridge/amd/pi/00730F01/northbridge.c index 377d91e..ba17c61 100644 --- a/src/northbridge/amd/pi/00730F01/northbridge.c +++ b/src/northbridge/amd/pi/00730F01/northbridge.c @@ -491,11 +491,6 @@ 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 @@ 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 @@ 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 */ diff --git a/src/southbridge/amd/sr5650/sr5650.c b/src/southbridge/amd/sr5650/sr5650.c index 90ca564..8131e77 100644 --- a/src/southbridge/amd/sr5650/sr5650.c +++ b/src/southbridge/amd/sr5650/sr5650.c @@ -725,13 +725,6 @@ struct device *sibling; struct bus *link;
- if (!root_level) { - root_level = malloc(sizeof(int8_t)); - if (root_level == NULL) - die("Error: Could not allocate a byte!\n"); - *root_level = -1; - } - if ((dev->path.type == DEVICE_PATH_PCI) && (dev->bus->secondary == 0x0) && (dev->path.pci.devfn == 0x0)) *root_level = depth; @@ -798,9 +791,6 @@ sibling = sibling->sibling) add_ivrs_device_entries(dev, sibling, depth + 1, depth, root_level, current, length); - - if (depth == 0) - free(root_level); }
unsigned long acpi_fill_mcfg(unsigned long current) @@ -879,7 +869,8 @@ 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 */
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34387
to look at the new patch set (#2).
Change subject: nb/amd/pi,sr5650: Remove unnecessary memory allocation ......................................................................
nb/amd/pi,sr5650: Remove unnecessary memory 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 --- M src/northbridge/amd/pi/00730F01/northbridge.c M src/southbridge/amd/sr5650/sr5650.c 2 files changed, 4 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/34387/2
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34387
to look at the new patch set (#3).
Change subject: nb/amd/pi,sb/amd/sr5650: Remove unnecessary allocation ......................................................................
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 --- M src/northbridge/amd/pi/00730F01/northbridge.c M src/southbridge/amd/sr5650/sr5650.c 2 files changed, 4 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/34387/3
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34387 )
Change subject: nb/amd/pi,sb/amd/sr5650: Remove unnecessary allocation ......................................................................
Patch Set 3: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/34387 )
Change subject: nb/amd/pi,sb/amd/sr5650: Remove unnecessary allocation ......................................................................
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 --- M src/northbridge/amd/pi/00730F01/northbridge.c M src/southbridge/amd/sr5650/sr5650.c 2 files changed, 4 insertions(+), 19 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Georgi: Looks good to me, approved
diff --git a/src/northbridge/amd/pi/00730F01/northbridge.c b/src/northbridge/amd/pi/00730F01/northbridge.c index 377d91e..ba17c61 100644 --- a/src/northbridge/amd/pi/00730F01/northbridge.c +++ b/src/northbridge/amd/pi/00730F01/northbridge.c @@ -491,11 +491,6 @@ 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 @@ 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 @@ 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 */ diff --git a/src/southbridge/amd/sr5650/sr5650.c b/src/southbridge/amd/sr5650/sr5650.c index 90ca564..8131e77 100644 --- a/src/southbridge/amd/sr5650/sr5650.c +++ b/src/southbridge/amd/sr5650/sr5650.c @@ -725,13 +725,6 @@ struct device *sibling; struct bus *link;
- if (!root_level) { - root_level = malloc(sizeof(int8_t)); - if (root_level == NULL) - die("Error: Could not allocate a byte!\n"); - *root_level = -1; - } - if ((dev->path.type == DEVICE_PATH_PCI) && (dev->bus->secondary == 0x0) && (dev->path.pci.devfn == 0x0)) *root_level = depth; @@ -798,9 +791,6 @@ sibling = sibling->sibling) add_ivrs_device_entries(dev, sibling, depth + 1, depth, root_level, current, length); - - if (depth == 0) - free(root_level); }
unsigned long acpi_fill_mcfg(unsigned long current) @@ -879,7 +869,8 @@ 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 */