Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb in usbnet_detach(), check both that the private ...



details:   https://anonhg.NetBSD.org/src/rev/20640b3d041c
branches:  trunk
changeset: 463528:20640b3d041c
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Aug 28 06:07:21 2019 +0000

description:
in usbnet_detach(), check both that the private pointer has
been allocated and that unp_attached is true before trying
to access anything else.

fixes a detach problem noticed by maxv when, eg, the call
to usbd_set_config_no() fails and attach bails early.

diffstat:

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

diffs (43 lines):

diff -r e2b749620dfd -r 20640b3d041c sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Wed Aug 28 01:44:39 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Wed Aug 28 06:07:21 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.23 2019/08/23 04:29:28 mrg Exp $  */
+/*     $NetBSD: usbnet.c,v 1.24 2019/08/28 06:07:21 mrg Exp $  */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.23 2019/08/23 04:29:28 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.24 2019/08/28 06:07:21 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1457,18 +1457,19 @@
 {
        USBNETHIST_FUNC(); USBNETHIST_CALLED();
        struct usbnet * const un = device_private(self);
+       struct usbnet_private * const unp = un->un_pri;
+
+       /* Detached before attached finished, so just bail out. */
+       if (unp == NULL || !unp->unp_attached)
+               return 0;
+
        struct ifnet * const ifp = usbnet_ifp(un);
        struct mii_data * const mii = usbnet_mii(un);
-       struct usbnet_private * const unp = un->un_pri;
 
        mutex_enter(&unp->unp_lock);
        unp->unp_dying = true;
        mutex_exit(&unp->unp_lock);
 
-       /* Detached before attached finished, so just bail out. */
-       if (!unp->unp_attached)
-               return 0;
-
        callout_halt(&unp->unp_stat_ch, NULL);
        usb_rem_task_wait(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER, NULL);
 



Home | Main Index | Thread Index | Old Index