aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2013-09-09 16:33:06 +0200
committerGerd Hoffmann <kraxel@redhat.com>2013-09-16 10:40:24 +0200
commitce12eaf2044d6aae08795403ecbb888d2b6527ff (patch)
tree596663b0df4623cc9d75c3f47ffb620019c64881
parent1c787118255111376fdb6ad9769a31d4e613fe5d (diff)
downloadseabios-ce12eaf2044d6aae08795403ecbb888d2b6527ff.tar.gz
ahci: add missing check for allocation failure
Triggerable by creating a virtual machine with *lots* of ahci controllers and disks. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r--src/hw/ahci.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/hw/ahci.c b/src/hw/ahci.c
index 0e99d14..e2729a9 100644
--- a/src/hw/ahci.c
+++ b/src/hw/ahci.c
@@ -379,12 +379,26 @@ ahci_port_alloc(struct ahci_ctrl_s *ctrl, u32 pnr)
return port;
}
+static void ahci_port_release(struct ahci_port_s *port)
+{
+ ahci_port_reset(port->ctrl, port->pnr);
+ free(port->list);
+ free(port->fis);
+ free(port->cmd);
+ free(port);
+}
+
static struct ahci_port_s* ahci_port_realloc(struct ahci_port_s *port)
{
struct ahci_port_s *tmp;
u32 cmd;
tmp = malloc_fseg(sizeof(*port));
+ if (!tmp) {
+ warn_noalloc();
+ ahci_port_release(port);
+ return NULL;
+ }
*tmp = *port;
free(port);
port = tmp;
@@ -408,15 +422,6 @@ static struct ahci_port_s* ahci_port_realloc(struct ahci_port_s *port)
return port;
}
-static void ahci_port_release(struct ahci_port_s *port)
-{
- ahci_port_reset(port->ctrl, port->pnr);
- free(port->list);
- free(port->fis);
- free(port->cmd);
- free(port);
-}
-
#define MAXMODEL 40
/* See ahci spec chapter 10.1 "Software Initialization of HBA" */
@@ -551,6 +556,8 @@ ahci_port_detect(void *data)
ahci_port_release(port);
else {
port = ahci_port_realloc(port);
+ if (port == NULL)
+ return;
dprintf(1, "AHCI/%d: registering: \"%s\"\n", port->pnr, port->desc);
if (!port->atapi) {
// Register with bcv system.