summaryrefslogtreecommitdiff
path: root/src/northbridge
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2015-02-21 23:56:07 +0200
committerKyösti Mälkki <kyosti.malkki@gmail.com>2015-03-09 05:59:47 +0100
commitc0ee937e92c901f30d38c10800012781db4a2b83 (patch)
tree828ea75a7d0e8d7072652f0891c4fbe3adbae7af /src/northbridge
parent11c79d7fc2c9e04828db8e54c199822e5fa749b8 (diff)
downloadcoreboot-c0ee937e92c901f30d38c10800012781db4a2b83.tar.xz
AMD K8: Fix allocation size for HyperTransport links
There is no requirement that in dev->link_list the last element would have the highest link->link_num. Also fix off-by-one error when allocating for more links. Change-Id: Id8a7db3ffb4111eb31e70ea14fd522b70368dd8c Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/8550 Tested-by: build bot (Jenkins) Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'src/northbridge')
-rw-r--r--src/northbridge/amd/amdk8/northbridge.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/northbridge/amd/amdk8/northbridge.c b/src/northbridge/amd/amdk8/northbridge.c
index 63f543e0a0..a17aa65a82 100644
--- a/src/northbridge/amd/amdk8/northbridge.c
+++ b/src/northbridge/amd/amdk8/northbridge.c
@@ -1165,14 +1165,16 @@ static struct device_operations pci_domain_ops = {
static void add_more_links(device_t dev, unsigned total_links)
{
struct bus *link, *last = NULL;
- int link_num;
+ int link_num = -1;
- for (link = dev->link_list; link; link = link->next)
+ for (link = dev->link_list; link; link = link->next) {
+ if (link_num < link->link_num)
+ link_num = link->link_num;
last = link;
+ }
if (last) {
- int links = total_links - last->link_num;
- link_num = last->link_num;
+ int links = total_links - (link_num + 1);
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
@@ -1182,7 +1184,6 @@ static void add_more_links(device_t dev, unsigned total_links)
}
}
else {
- link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;