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/0ca59174bbad
branches:  trunk
changeset: 370220:0ca59174bbad
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 516d38f0307b -r 0ca59174bbad 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
@@ -439,6 +439,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??? */
@@ -633,11 +634,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");
 }
 
@@ -1137,6 +1140,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);
@@ -1560,7 +1565,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);
@@ -1585,7 +1590,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
@@ -1600,7 +1604,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);
@@ -1659,7 +1663,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