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/2f89c12d16a1
branches:  trunk
changeset: 940797:2f89c12d16a1
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 4bd661710731 -r 2f89c12d16a1 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
@@ -435,6 +435,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??? */
@@ -629,11 +630,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");
 }
 
@@ -1131,6 +1134,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);
@@ -1554,7 +1559,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);
@@ -1579,7 +1584,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
@@ -1594,7 +1598,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);
@@ -1653,7 +1657,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