summaryrefslogtreecommitdiff
path: root/src/drivers/usb/hub
diff options
context:
space:
mode:
authorArthur Heymans <arthur@aheymans.xyz>2022-05-13 17:30:47 +0200
committerFelix Held <felix-coreboot@felixheld.de>2022-09-16 13:05:19 +0000
commit5d8fe86db2de0036b190e164e5926262404afcb8 (patch)
tree12f8f6cb7e4a72bf84acb0ed0e38d59e77f11697 /src/drivers/usb/hub
parent4d9748f87c500376ce015413c660e4ad58d4eef8 (diff)
drivers/usb/hub/acpi.c: Don't use heap for ACPI name
Using malloc would increase the heap use each time this function is called. Instead allocate a per struct device buffer inside the chip_info struct. Found by coverity scan, CID 1488815. Change-Id: Ie24870b34338624b3bf3a6f420debdd24a68ffbd Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/c/coreboot/+/64338 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'src/drivers/usb/hub')
-rw-r--r--src/drivers/usb/hub/acpi.c12
-rw-r--r--src/drivers/usb/hub/chip.h3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/drivers/usb/hub/acpi.c b/src/drivers/usb/hub/acpi.c
index 347e25e5c3..10e38fb61d 100644
--- a/src/drivers/usb/hub/acpi.c
+++ b/src/drivers/usb/hub/acpi.c
@@ -8,8 +8,11 @@
static const char *usb_hub_acpi_name(const struct device *dev)
{
- char *name;
const char *pattern;
+ struct drivers_usb_hub_config *config = dev->chip_info;
+
+ if (config->acpi_name[0] != 0)
+ return config->acpi_name;
/* USB ACPI driver does not have acpi_name operation defined. Hence return
the ACPI name for both the hub and any downstream facing ports. */
@@ -26,11 +29,10 @@ static const char *usb_hub_acpi_name(const struct device *dev)
return NULL;
}
- name = malloc(ACPI_NAME_BUFFER_SIZE);
- snprintf(name, ACPI_NAME_BUFFER_SIZE, pattern, dev->path.usb.port_id + 1);
- name[4] = '\0';
+ snprintf(config->acpi_name, sizeof(config->acpi_name), pattern,
+ dev->path.usb.port_id + 1);
- return name;
+ return config->acpi_name;
}
static void usb_hub_add_ports(const struct device *dev)
diff --git a/src/drivers/usb/hub/chip.h b/src/drivers/usb/hub/chip.h
index d735f112f9..4c5e380d5d 100644
--- a/src/drivers/usb/hub/chip.h
+++ b/src/drivers/usb/hub/chip.h
@@ -3,10 +3,13 @@
#ifndef __DRIVERS_USB_HUB_CHIP_H__
#define __DRIVERS_USB_HUB_CHIP_H__
+#include <acpi/acpi.h>
+
struct drivers_usb_hub_config {
const char *name;
const char *desc;
unsigned int port_count; /* Number of Super-speed or High-speed ports */
+ char acpi_name[ACPI_NAME_BUFFER_SIZE]; /* Set by the acpi_name ops */
};
#endif /* __DRIVERS_USB_HUB_CHIP_H__ */