Module Name: src Committed By: mlelstv Date: Sun May 26 04:52:07 UTC 2019
Modified Files: src/sys/dev/usb: if_mue.c if_muevar.h Log Message: usbd_transfer may sleep, add a mutex to prevent a race in mue_start. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/sys/dev/usb/if_mue.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/usb/if_muevar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/if_mue.c diff -u src/sys/dev/usb/if_mue.c:1.45 src/sys/dev/usb/if_mue.c:1.46 --- src/sys/dev/usb/if_mue.c:1.45 Thu May 23 13:10:52 2019 +++ src/sys/dev/usb/if_mue.c Sun May 26 04:52:07 2019 @@ -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 @@ mue_attach(device_t parent, device_t sel 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 @@ mue_start(struct ifnet *ifp) 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 @@ mue_start(struct ifnet *ifp) bpf_mtap(ifp, m, BPF_D_OUT); m_freem(m); - idx = (idx + 1) % sc->mue_tx_list_cnt; cd->mue_tx_cnt++; - + idx = (idx + 1) % sc->mue_tx_list_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; } Index: src/sys/dev/usb/if_muevar.h diff -u src/sys/dev/usb/if_muevar.h:1.7 src/sys/dev/usb/if_muevar.h:1.8 --- src/sys/dev/usb/if_muevar.h:1.7 Wed Feb 6 08:28:11 2019 +++ src/sys/dev/usb/if_muevar.h Sun May 26 04:52:07 2019 @@ -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 @@ struct mue_softc { unsigned mue_rx_list_cnt; unsigned mue_tx_list_cnt; + + kmutex_t mue_usb_lock; }; #endif /* _IF_MUEVAR_H_ */