summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/device/device_util.c21
-rw-r--r--src/include/device/device.h2
2 files changed, 17 insertions, 6 deletions
diff --git a/src/device/device_util.c b/src/device/device_util.c
index e2370a1cce..11954a1982 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -654,7 +654,13 @@ bool dev_is_active_bridge(struct device *dev)
return 0;
}
-void add_more_links(struct device *dev, unsigned total_links)
+/**
+ * Ensure the device has a minimum number of bus links.
+ *
+ * @param dev The device to add links to.
+ * @param total_links The minimum number of links to have.
+ */
+void add_more_links(struct device *dev, unsigned int total_links)
{
struct bus *link, *last = NULL;
int link_num = -1;
@@ -668,15 +674,20 @@ void add_more_links(struct device *dev, unsigned total_links)
if (last) {
int links = total_links - (link_num + 1);
if (links > 0) {
- link = malloc(links*sizeof(*link));
+ link = malloc(links * sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
- memset(link, 0, links*sizeof(*link));
+ memset(link, 0, links * sizeof(*link));
last->next = link;
+ } else {
+ /* No more links to add */
+ return;
}
} else {
- link = malloc(total_links*sizeof(*link));
- memset(link, 0, total_links*sizeof(*link));
+ link = malloc(total_links * sizeof(*link));
+ if (!link)
+ die("Couldn't allocate more links!\n");
+ memset(link, 0, total_links * sizeof(*link));
dev->link_list = link;
}
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 52635e1bd2..8e9454c4e1 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -191,7 +191,7 @@ const char *bus_path(struct bus *bus);
void dev_set_enabled(struct device *dev, int enable);
void disable_children(struct bus *bus);
bool dev_is_active_bridge(struct device *dev);
-void add_more_links(struct device *dev, unsigned total_links);
+void add_more_links(struct device *dev, unsigned int total_links);
/* Option ROM helper functions */
void run_bios(struct device *dev, unsigned long addr);