]> xenbits.xensource.com Git - seabios.git/commitdiff
Make sure all code checks for malloc failures
authorKevin O'Connor <kevin@koconnor.net>
Tue, 30 Jun 2015 15:10:41 +0000 (11:10 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 4 Jul 2015 18:23:01 +0000 (14:23 -0400)
This is the result of an audit of callers of the malloc_XXX() and
memalign_XXX() calls.  All callers need to check if these functions
return NULL.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/cdrom.c
src/hw/ahci.c
src/hw/megasas.c
src/hw/ramdisk.c
src/hw/usb-xhci.c
src/hw/usb.c

index 7ee36d9a3ab765765a369001e75f30f9c8e81ba4..ba0234057cfd4ff34efe2ef96df0e29f79cae483 100644 (file)
@@ -123,7 +123,6 @@ cdrom_prepboot(void)
     struct drive_s *drive = malloc_fseg(sizeof(*drive));
     if (!drive) {
         warn_noalloc();
-        free(drive);
         return;
     }
     cdemu_drive_gf = drive;
index 3193d81a6610634d850511140a724b6c2e9a372c..0d71cc409a42d29c882417714dfa8d7d9b769ce4 100644 (file)
@@ -405,6 +405,14 @@ static struct ahci_port_s* ahci_port_realloc(struct ahci_port_s *port)
     port->list = memalign_high(1024, 1024);
     port->fis = memalign_high(256, 256);
     port->cmd = memalign_high(256, 256);
+    if (!port->list || !port->fis || !port->cmd) {
+        warn_noalloc();
+        free(port->list);
+        free(port->fis);
+        free(port->cmd);
+        free(port);
+        return NULL;
+    }
 
     ahci_port_writel(port->ctrl, port->pnr, PORT_LST_ADDR, (u32)port->list);
     ahci_port_writel(port->ctrl, port->pnr, PORT_FIS_ADDR, (u32)port->fis);
index b2a65e48bac792e62338286f44f3b3778354e710..66779778819eb797553484b0801e5ffc69297341 100644 (file)
@@ -241,7 +241,10 @@ static void megasas_scan_target(struct pci_device *pci, u32 iobase)
 {
     struct mfi_ld_list_s ld_list;
     struct megasas_cmd_frame *frame = memalign_tmp(256, sizeof(*frame));
-    int i;
+    if (!frame) {
+        warn_noalloc();
+        return;
+    }
 
     memset(&ld_list, 0, sizeof(ld_list));
     memset_fl(frame, 0, sizeof(*frame));
@@ -258,6 +261,7 @@ static void megasas_scan_target(struct pci_device *pci, u32 iobase)
 
     if (megasas_fire_cmd(pci->device, iobase, frame) == 0) {
         dprintf(2, "%d LD found\n", ld_list.count);
+        int i;
         for (i = 0; i < ld_list.count; i++) {
             dprintf(2, "LD %d:%d state 0x%x\n",
                     ld_list.lds[i].target, ld_list.lds[i].lun,
index 1177bc00a21a6217026e2ee55613d79524d4336e..6b44c8378fee9dcba38e876ed567844c082ea59a 100644 (file)
@@ -7,7 +7,7 @@
 #include "biosvar.h" // GET_GLOBALFLAT
 #include "block.h" // struct drive_s
 #include "bregs.h" // struct bregs
-#include "malloc.h" // malloc_fseg
+#include "malloc.h" // memalign_tmphigh
 #include "memmap.h" // add_e820
 #include "output.h" // dprintf
 #include "romfile.h" // romfile_findprefix
index fd58334dc94b050e0aa23471beee2137a0d70af9..41a6a3f3e91c982eb4a6c722096ae91bc4939007 100644 (file)
@@ -921,8 +921,14 @@ xhci_alloc_pipe(struct usbdevice_s *usbdev
     usb_desc2pipe(&pipe->pipe, usbdev, epdesc);
     pipe->epid = epid;
     pipe->reqs.cs = 1;
-    if (eptype == USB_ENDPOINT_XFER_INT)
+    if (eptype == USB_ENDPOINT_XFER_INT) {
         pipe->buf = malloc_high(pipe->pipe.maxpacket);
+        if (!pipe->buf) {
+            warn_noalloc();
+            free(pipe);
+            return NULL;
+        }
+    }
 
     // Allocate input context and initialize endpoint info.
     struct xhci_inctx *in = xhci_alloc_inctx(usbdev, epid);
@@ -988,6 +994,7 @@ xhci_alloc_pipe(struct usbdevice_s *usbdev
     return &pipe->pipe;
 
 fail:
+    free(pipe->buf);
     free(pipe);
     free(in);
     return NULL;
index 1b4ea8beda5d9ab206f06c6e1c38d6dea414f18c..2d5c2240986a55cd31754426ffbc1507485da2e3 100644 (file)
@@ -249,8 +249,10 @@ get_device_config(struct usb_pipe *pipe)
         return NULL;
 
     void *config = malloc_tmphigh(cfg.wTotalLength);
-    if (!config)
+    if (!config) {
+        warn_noalloc();
         return NULL;
+    }
     req.wLength = cfg.wTotalLength;
     ret = usb_send_default_control(pipe, &req, config);
     if (ret) {