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/cd734b2f8881
branches:  trunk
changeset: 987052:cd734b2f8881
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 97ed9ad2e2ce -r cd734b2f8881 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
@@ -437,6 +437,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??? */
@@ -631,11 +632,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");
 }
 
@@ -1135,6 +1138,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);
@@ -1558,7 +1563,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);
@@ -1583,7 +1588,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
@@ -1598,7 +1602,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);
@@ -1657,7 +1661,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