git: a41a9e01c3cd - stable/13 - uslcom(4): Clear stall at every open.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Sat, 12 Nov 2022 12:41:53 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=a41a9e01c3cde8962bc48299a4e6894ad31a38bf

commit a41a9e01c3cde8962bc48299a4e6894ad31a38bf
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-10-05 14:45:21 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-11-12 12:00:16 +0000

    uslcom(4): Clear stall at every open.
    
    To avoid data loss, make sure both the receive and transmit data toggles
    get reset, before trying to read or write any data.
    
    Sponsored by:   NVIDIA Networking
    
    (cherry picked from commit 9e0edafe92ad9fc6745ee4c4c58e45a49b9e7ed1)
---
 sys/dev/usb/serial/uslcom.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/sys/dev/usb/serial/uslcom.c b/sys/dev/usb/serial/uslcom.c
index fec18d2a5631..891137175dcb 100644
--- a/sys/dev/usb/serial/uslcom.c
+++ b/sys/dev/usb/serial/uslcom.c
@@ -441,12 +441,6 @@ uslcom_attach(device_t dev)
 		    "error=%s\n", usbd_errstr(error));
 		goto detach;
 	}
-	/* clear stall at first run */
-	mtx_lock(&sc->sc_mtx);
-	usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
-	usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
-	mtx_unlock(&sc->sc_mtx);
-
 	sc->sc_partnum = uslcom_get_partnum(sc);
 
 	error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@@ -516,6 +510,10 @@ uslcom_cfg_open(struct ucom_softc *ucom)
 		DPRINTF("UART enable failed (ignored)\n");
 	}
 
+	/* clear stall */
+	usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
+	usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
+
 	/* start polling status */
 	uslcom_watchdog(sc);
 }