Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb handle memory shortage correctly.



details:   https://anonhg.NetBSD.org/src/rev/aa8e6a65b235
branches:  trunk
changeset: 784672:aa8e6a65b235
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 05 13:39:28 2013 +0000

description:
handle memory shortage correctly.

diffstat:

 sys/dev/usb/usb_mem.c |  30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diffs (69 lines):

diff -r c73f11175251 -r aa8e6a65b235 sys/dev/usb/usb_mem.c
--- a/sys/dev/usb/usb_mem.c     Tue Feb 05 13:36:59 2013 +0000
+++ b/sys/dev/usb/usb_mem.c     Tue Feb 05 13:39:28 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_mem.c,v 1.61 2013/02/05 00:41:51 christos Exp $    */
+/*     $NetBSD: usb_mem.c,v 1.62 2013/02/05 13:39:28 christos Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.61 2013/02/05 00:41:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.62 2013/02/05 13:39:28 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -439,25 +439,28 @@
                return USBD_NOMEM;
 
        dma->block = kmem_zalloc(sizeof *dma->block, KM_SLEEP);
-       if (dma->block == NULL)
-               return USBD_NOMEM;
+       if (dma->block == NULL) {
+               aprint_error_dev(rs->dv, "%s: failed allocating dma block",
+                   __func__);
+               goto out0;
+       }
 
        dma->block->nsegs = 1;
        dma->block->segs = kmem_alloc(dma->block->nsegs *
            sizeof(*dma->block->segs), KM_SLEEP);
        if (dma->block->segs == NULL) {
-               kmem_free(dma->block, sizeof *dma->block);
-               return USBD_NOMEM;
+               aprint_error_dev(rs->dv, "%s: failed allocating 1 dma segment",
+                   __func__);
+               goto out1;
        }
 
        error = extent_alloc(rs->extent, size, PAGE_SIZE, 0,
            EX_NOWAIT, &start);
 
        if (error != 0) {
-               aprint_error_dev(rs->dv,
-                   "usb_reserve_allocm of size %u failed (error %d)\n",
-                   size, error);
-               return USBD_NOMEM;
+               aprint_error_dev(rs->dv, "%s: extent_alloc size %u failed "
+                   "(error %d)", __func__, size, error);
+               goto out2;
        }
 
        baddr = start;
@@ -471,6 +474,13 @@
        dma->block->tag = rs->dtag;
 
        return USBD_NORMAL_COMPLETION;
+out2:
+       kmem_free(dma->block->segs, dma->block->nsegs *
+           sizeof(*dma->block->segs));
+out1:
+       kmem_free(dma->block, sizeof *dma->block);
+out0:
+       return USBD_NOMEM;
 }
 
 void



Home | Main Index | Thread Index | Old Index