Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb kmem_alloc doesn't support allocating 0 bytes.



details:   https://anonhg.NetBSD.org/src/rev/9289110b4b02
branches:  trunk
changeset: 815269:9289110b4b02
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Mon May 09 04:55:34 2016 +0000

description:
kmem_alloc doesn't support allocating 0 bytes.

diffstat:

 sys/dev/usb/uhid.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (49 lines):

diff -r 340f1d07e8b9 -r 9289110b4b02 sys/dev/usb/uhid.c
--- a/sys/dev/usb/uhid.c        Sun May 08 20:15:00 2016 +0000
+++ b/sys/dev/usb/uhid.c        Mon May 09 04:55:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhid.c,v 1.96 2016/04/27 19:35:17 jakllsch Exp $       */
+/*     $NetBSD: uhid.c,v 1.97 2016/05/09 04:55:34 mlelstv Exp $        */
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.96 2016/04/27 19:35:17 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.97 2016/05/09 04:55:34 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -340,7 +340,10 @@
        }
        mutex_exit(&sc->sc_access_lock);
 
-       sc->sc_obuf = kmem_alloc(sc->sc_osize, KM_SLEEP);
+       if (sc->sc_osize > 0)
+               sc->sc_obuf = kmem_alloc(sc->sc_osize, KM_SLEEP);
+       else
+               sc->sc_obuf = NULL;
        sc->sc_state &= ~UHID_IMMED;
 
        mutex_enter(proc_lock);
@@ -368,7 +371,8 @@
        uhidev_stop(&sc->sc_hdev);
 
        clfree(&sc->sc_q);
-       kmem_free(sc->sc_obuf, sc->sc_osize);
+       if (sc->sc_osize > 0)
+               kmem_free(sc->sc_obuf, sc->sc_osize);
 
        uhidev_close(&sc->sc_hdev);
 
@@ -473,7 +477,7 @@
 
        size = sc->sc_osize;
        error = 0;
-       if (uio->uio_resid != size)
+       if (uio->uio_resid != size || size == 0)
                return EINVAL;
        error = uiomove(sc->sc_obuf, size, uio);
        if (!error) {



Home | Main Index | Thread Index | Old Index