Source-Changes-HG archive

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

[src/nick-nhusb]: src/sys/dev/usb Fix usb_block_allocmem locking



details:   https://anonhg.NetBSD.org/src/rev/7c2eef4d79de
branches:  nick-nhusb
changeset: 334363:7c2eef4d79de
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Jan 05 06:05:11 2016 +0000

description:
Fix usb_block_allocmem locking

diffstat:

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

diffs (54 lines):

diff -r 2c50389033e4 -r 7c2eef4d79de sys/dev/usb/usb_mem.c
--- a/sys/dev/usb/usb_mem.c     Tue Jan 05 05:53:38 2016 +0000
+++ b/sys/dev/usb/usb_mem.c     Tue Jan 05 06:05:11 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_mem.c,v 1.65.2.11 2015/11/10 13:41:49 skrll Exp $  */
+/*     $NetBSD: usb_mem.c,v 1.65.2.12 2016/01/05 06:05:11 skrll 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.65.2.11 2015/11/10 13:41:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.65.2.12 2016/01/05 06:05:11 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -140,12 +140,14 @@
        mutex_exit(&usb_blk_lock);
 
        b = kmem_zalloc(sizeof(*b), KM_SLEEP);
-       if (b == NULL)
-               return USBD_NOMEM;
+       if (b == NULL) {
+               goto fail;
+       }
 
        b->tag = tag;
        b->size = size;
        b->align = align;
+ free:
 
        if (!multiseg)
                /* Caller wants one segment */
@@ -156,7 +158,7 @@
        b->segs = kmem_alloc(b->nsegs * sizeof(*b->segs), KM_SLEEP);
        if (b->segs == NULL) {
                kmem_free(b, sizeof(*b));
-               return USBD_NOMEM;
+               goto fail;
        }
        b->nsegs_alloc = b->nsegs;
 
@@ -198,6 +200,9 @@
  free0:
        kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs));
        kmem_free(b, sizeof(*b));
+ fail:
+       mutex_enter(&usb_blk_lock);
+
        return USBD_NOMEM;
 }
 



Home | Main Index | Thread Index | Old Index