Blame SOURCES/seabios-ahci-add-missing-check-for-allocation-failure.patch

867c1e
From 48c296e7b9851c07ef277d7d37a05e20da3ef76d Mon Sep 17 00:00:00 2001
867c1e
From: Gerd Hoffmann <kraxel@redhat.com>
867c1e
Date: Tue, 17 Sep 2013 09:42:30 +0200
867c1e
Subject: [PATCH 5/5] ahci: add missing check for allocation failure
867c1e
867c1e
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
867c1e
Message-id: <1379410950-22494-2-git-send-email-kraxel@redhat.com>
867c1e
Patchwork-id: 54411
867c1e
O-Subject: [RHEL-7 seabios PATCH 1/1] ahci: add missing check for allocation failure
867c1e
Bugzilla: 1005747
867c1e
RH-Acked-by: Bandan Das <bsd@redhat.com>
867c1e
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
867c1e
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
867c1e
867c1e
Triggerable by creating a virtual machine with
867c1e
*lots* of ahci controllers and disks.
867c1e
867c1e
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
867c1e
(cherry picked from commit ce12eaf2044d6aae08795403ecbb888d2b6527ff)
867c1e
---
867c1e
 src/ahci.c | 25 ++++++++++++++++---------
867c1e
 1 file changed, 16 insertions(+), 9 deletions(-)
867c1e
867c1e
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
867c1e
---
867c1e
 src/ahci.c |   25 ++++++++++++++++---------
867c1e
 1 files changed, 16 insertions(+), 9 deletions(-)
867c1e
867c1e
diff --git a/src/ahci.c b/src/ahci.c
867c1e
index 4a8eafb..056d894 100644
867c1e
--- a/src/ahci.c
867c1e
+++ b/src/ahci.c
867c1e
@@ -381,12 +381,26 @@ ahci_port_alloc(struct ahci_ctrl_s *ctrl, u32 pnr)
867c1e
     return port;
867c1e
 }
867c1e
 
867c1e
+static void ahci_port_release(struct ahci_port_s *port)
867c1e
+{
867c1e
+    ahci_port_reset(port->ctrl, port->pnr);
867c1e
+    free(port->list);
867c1e
+    free(port->fis);
867c1e
+    free(port->cmd);
867c1e
+    free(port);
867c1e
+}
867c1e
+
867c1e
 static struct ahci_port_s* ahci_port_realloc(struct ahci_port_s *port)
867c1e
 {
867c1e
     struct ahci_port_s *tmp;
867c1e
     u32 cmd;
867c1e
 
867c1e
     tmp = malloc_fseg(sizeof(*port));
867c1e
+    if (!tmp) {
867c1e
+        warn_noalloc();
867c1e
+        ahci_port_release(port);
867c1e
+        return NULL;
867c1e
+    }
867c1e
     *tmp = *port;
867c1e
     free(port);
867c1e
     port = tmp;
867c1e
@@ -410,15 +424,6 @@ static struct ahci_port_s* ahci_port_realloc(struct ahci_port_s *port)
867c1e
     return port;
867c1e
 }
867c1e
 
867c1e
-static void ahci_port_release(struct ahci_port_s *port)
867c1e
-{
867c1e
-    ahci_port_reset(port->ctrl, port->pnr);
867c1e
-    free(port->list);
867c1e
-    free(port->fis);
867c1e
-    free(port->cmd);
867c1e
-    free(port);
867c1e
-}
867c1e
-
867c1e
 #define MAXMODEL 40
867c1e
 
867c1e
 /* See ahci spec chapter 10.1 "Software Initialization of HBA" */
867c1e
@@ -554,6 +559,8 @@ ahci_port_detect(void *data)
867c1e
         ahci_port_release(port);
867c1e
     else {
867c1e
         port = ahci_port_realloc(port);
867c1e
+        if (port == NULL)
867c1e
+            return;
867c1e
         dprintf(1, "AHCI/%d: registering: \"%s\"\n", port->pnr, port->desc);
867c1e
         if (!port->atapi) {
867c1e
             // Register with bcv system.
867c1e
-- 
867c1e
1.7.1
867c1e