Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb More less kmem_zalloc(0).



details:   https://anonhg.NetBSD.org/src/rev/bdf2868c9305
branches:  trunk
changeset: 965819:bdf2868c9305
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Oct 03 05:16:16 2019 +0000

description:
More less kmem_zalloc(0).

diffstat:

 sys/dev/usb/umidi.c |  15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diffs (43 lines):

diff -r 42ef1410db1e -r bdf2868c9305 sys/dev/usb/umidi.c
--- a/sys/dev/usb/umidi.c       Thu Oct 03 05:13:23 2019 +0000
+++ b/sys/dev/usb/umidi.c       Thu Oct 03 05:16:16 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umidi.c,v 1.79 2019/09/15 09:18:17 maxv Exp $  */
+/*     $NetBSD: umidi.c,v 1.80 2019/10/03 05:16:16 maxv Exp $  */
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.79 2019/09/15 09:18:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.80 2019/10/03 05:16:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1081,9 +1081,10 @@
                cn_spec = NULL;
 
        /* allocate/initialize structures */
-       sc->sc_jacks =
-           kmem_zalloc(sizeof(*sc->sc_out_jacks)*(sc->sc_in_num_jacks
-                   + sc->sc_out_num_jacks), KM_SLEEP);
+       if (sc->sc_in_num_jacks == 0 && sc->sc_out_num_jacks == 0)
+               return USBD_INVAL;
+       sc->sc_jacks = kmem_zalloc(sizeof(*sc->sc_out_jacks) *
+           (sc->sc_in_num_jacks + sc->sc_out_num_jacks), KM_SLEEP);
        if (!sc->sc_jacks)
                return USBD_NOMEM;
        sc->sc_out_jacks =
@@ -1154,8 +1155,8 @@
 
        mutex_enter(&sc->sc_lock);
        jacks = sc->sc_jacks;
-       len = sizeof(*sc->sc_out_jacks)
-           * (sc->sc_in_num_jacks + sc->sc_out_num_jacks);
+       len = sizeof(*sc->sc_out_jacks) *
+           (sc->sc_in_num_jacks + sc->sc_out_num_jacks);
        sc->sc_jacks = sc->sc_in_jacks = sc->sc_out_jacks = NULL;
        mutex_exit(&sc->sc_lock);
 



Home | Main Index | Thread Index | Old Index