]> xenbits.xensource.com Git - seabios.git/commitdiff
ahci: add missing check for allocation failure
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 9 Sep 2013 14:33:06 +0000 (16:33 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 16 Sep 2013 09:02:31 +0000 (11:02 +0200)
Triggerable by creating a virtual machine with
*lots* of ahci controllers and disks.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit ce12eaf2044d6aae08795403ecbb888d2b6527ff)

src/ahci.c

index 879a9915c3146b40fede1132fd9533a70271fc65..f2cc71bf9eb37cccca66d28fd54238e7fbdbcb25 100644 (file)
@@ -381,12 +381,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;
@@ -410,15 +424,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" */
@@ -554,6 +559,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.