Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Avoid crashes if we fail to allocate a transfer ...



details:   https://anonhg.NetBSD.org/src/rev/17e696f69340
branches:  trunk
changeset: 1008780:17e696f69340
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Apr 03 06:05:00 2020 +0000

description:
Avoid crashes if we fail to allocate a transfer buffer and avoid an
unnecessary usbd_free_buffer before usbd_free_xfer

Worked out by Riastradh

diffstat:

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

diffs (47 lines):

diff -r 8daaba9488c7 -r 17e696f69340 sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c       Fri Apr 03 06:02:51 2020 +0000
+++ b/sys/dev/usb/usbdi.c       Fri Apr 03 06:05:00 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.c,v 1.198 2020/03/14 02:35:33 christos Exp $     */
+/*     $NetBSD: usbdi.c,v 1.199 2020/04/03 06:05:00 skrll Exp $        */
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.198 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.199 2020/04/03 06:05:00 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -593,6 +593,11 @@
        if (xfer == NULL)
                return ENOMEM;
 
+       xfer->ux_pipe = pipe;
+       xfer->ux_flags = flags;
+       xfer->ux_nframes = nframes;
+       xfer->ux_methods = pipe->up_methods;
+
        if (len) {
                buf = usbd_alloc_buffer(xfer, len);
                if (!buf) {
@@ -600,16 +605,10 @@
                        return ENOMEM;
                }
        }
-       xfer->ux_pipe = pipe;
-       xfer->ux_flags = flags;
-       xfer->ux_nframes = nframes;
-       xfer->ux_methods = pipe->up_methods;
 
        if (xfer->ux_methods->upm_init) {
                int err = xfer->ux_methods->upm_init(xfer);
                if (err) {
-                       if (buf)
-                               usbd_free_buffer(xfer);
                        usbd_free_xfer(xfer);
                        return err;
                }



Home | Main Index | Thread Index | Old Index