Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb usbd_transfer may sleep, add a mutex to prevent ...



details:   https://anonhg.NetBSD.org/src/rev/4c8d171ec380
branches:  trunk
changeset: 841620:4c8d171ec380
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun May 26 04:52:07 2019 +0000

description:
usbd_transfer may sleep, add a mutex to prevent a race in mue_start.

diffstat:

 sys/dev/usb/if_mue.c    |  12 ++++++++----
 sys/dev/usb/if_muevar.h |   4 +++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diffs (72 lines):

diff -r 95d5fef34981 -r 4c8d171ec380 sys/dev/usb/if_mue.c
--- a/sys/dev/usb/if_mue.c      Sun May 26 02:49:34 2019 +0000
+++ b/sys/dev/usb/if_mue.c      Sun May 26 04:52:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mue.c,v 1.45 2019/05/23 13:10:52 msaitoh Exp $      */
+/*     $NetBSD: if_mue.c,v 1.46 2019/05/26 04:52:07 mlelstv Exp $      */
 /*     $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $  */
 
 /*
@@ -20,7 +20,7 @@
 /* Driver for Microchip LAN7500/LAN7800 chipsets. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.45 2019/05/23 13:10:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.46 2019/05/26 04:52:07 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -958,6 +958,7 @@
                sc->mue_tx_list_cnt = MUE_TX_LIST_CNT;
        }
        sc->mue_txbufsz = MUE_TX_BUFSIZE;
+       mutex_init(&sc->mue_usb_lock, MUTEX_DEFAULT, IPL_NET);
 
        /* Find endpoints. */
        id = usbd_get_interface_descriptor(sc->mue_iface);
@@ -1819,6 +1820,8 @@
                return;
        }
 
+       mutex_enter(&sc->mue_usb_lock);
+
        idx = cd->mue_tx_prod;
        while (cd->mue_tx_cnt < (int)sc->mue_tx_list_cnt) {
                IFQ_POLL(&ifp->if_snd, m);
@@ -1834,15 +1837,16 @@
                bpf_mtap(ifp, m, BPF_D_OUT);
                m_freem(m);
 
+               cd->mue_tx_cnt++;
                idx = (idx + 1) % sc->mue_tx_list_cnt;
-               cd->mue_tx_cnt++;
-
        }
        cd->mue_tx_prod = idx;
 
        if (cd->mue_tx_cnt >= (int)sc->mue_tx_list_cnt)
                ifp->if_flags |= IFF_OACTIVE;
 
+       mutex_exit(&sc->mue_usb_lock);
+
        /* Set a timeout in case the chip goes out to lunch. */
        ifp->if_timer = 5;
 }
diff -r 95d5fef34981 -r 4c8d171ec380 sys/dev/usb/if_muevar.h
--- a/sys/dev/usb/if_muevar.h   Sun May 26 02:49:34 2019 +0000
+++ b/sys/dev/usb/if_muevar.h   Sun May 26 04:52:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_muevar.h,v 1.7 2019/02/06 08:28:11 rin Exp $        */
+/*     $NetBSD: if_muevar.h,v 1.8 2019/05/26 04:52:07 mlelstv Exp $    */
 /*     $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $     */
 
 /*
@@ -121,6 +121,8 @@
 
        unsigned                mue_rx_list_cnt;
        unsigned                mue_tx_list_cnt;
+
+       kmutex_t                mue_usb_lock;
 };
 
 #endif /* _IF_MUEVAR_H_ */



Home | Main Index | Thread Index | Old Index