Source-Changes-HG archive

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

[src-draft/trunk]: src/sys/dev/usb Fix locking botch.



details:   https://anonhg.NetBSD.org/src-all/rev/d2cba445c8db
branches:  trunk
changeset: 1025206:d2cba445c8db
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Wed May 06 05:42:20 2020 +1000

description:
Fix locking botch.
Introduce the use of sc_write mutex to serialize reads as well.

diffstat:

 sys/dev/usb/if_urtwn.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (68 lines):

diff -r 1de5f87c7a33 -r d2cba445c8db sys/dev/usb/if_urtwn.c
--- a/sys/dev/usb/if_urtwn.c    Sun May 03 23:31:50 2020 +1000
+++ b/sys/dev/usb/if_urtwn.c    Wed May 06 05:42:20 2020 +1000
@@ -438,6 +438,7 @@
        mutex_init(&sc->sc_fwcmd_mtx, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&sc->sc_write_mtx, MUTEX_DEFAULT, IPL_NONE);
 
+       mutex_enter(&sc->sc_write_mtx);
        usb_init_task(&sc->sc_task, urtwn_task, sc, 0);
 
 /* NNN make these callouts use a vap ... in vap create??? */
@@ -632,11 +633,13 @@
                }
                mutex_exit(&sc->sc_rx_mtx);
        }
+       mutex_exit(&sc->sc_write_mtx);
 
        return;
 
  fail:
        sc->sc_dying = 1;
+       mutex_exit(&sc->sc_write_mtx);
        aprint_error_dev(self, "attach failed\n");
 }
 
@@ -1136,6 +1139,8 @@
        usb_device_request_t req;
        usbd_status error;
 
+       KASSERT(mutex_owned(&sc->sc_write_mtx));
+
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
        req.bRequest = R92C_REQ_REGS;
        USETW(req.wValue, addr);
@@ -1559,7 +1564,7 @@
 
        DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
-       mutex_enter(&sc->sc_write_mtx);
+       KASSERT(mutex_owned(&sc->sc_write_mtx));
 
        /* Read full ROM image. */
        urtwn_efuse_read(sc);
@@ -1584,7 +1589,6 @@
        sc->sc_power_on = urtwn_r92c_power_on;
        sc->sc_dma_init = urtwn_r92c_dma_init;
 
-       mutex_exit(&sc->sc_write_mtx);
 }
 
 static void
@@ -1599,7 +1603,7 @@
 
        DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
-       mutex_enter(&sc->sc_write_mtx);
+       KASSERT(mutex_owned(&sc->sc_write_mtx));
 
        off = 0;
        urtwn_efuse_switch_power(sc);
@@ -1658,7 +1662,6 @@
        }
        sc->sc_dma_init = urtwn_r88e_dma_init;
 
-       mutex_exit(&sc->sc_write_mtx);
 }
 
 /*  NNN  Do we need to do something with this?  */



Home | Main Index | Thread Index | Old Index