Module Name:    src
Committed By:   riastradh
Date:           Mon Mar 28 12:42:54 UTC 2022

Modified Files:
        src/sys/dev/usb: ucycom.c uhid.c uhidev.c uhidev.h

Log Message:
uhidev(9): Partially fix uhidev_write aborting.

In my previous change, I intended to make uhidev_stop abort any
pending write -- but I forgot to initialize sc->sc_writereportid, so
it never did anything.

This changes the API and ABI of uhidev_write so it takes the struct
uhidev pointer, rather than the struct uhidev_softc pointer; this way
uhidev_write knows what the report id of the client is, so it can
arrange to have uhidev_stop abort only this one.

XXX Except it still doesn't actually work because we do this
unlocked, ugh, so the write might complete before we abort anything.
To be fixed some more in a later change.

XXX kernel ABI change to uhidev_write signature, used by uhidev
driver modules, requires bump


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/usb/ucycom.c
cvs rdiff -u -r1.120 -r1.121 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/usb/uhidev.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/usb/uhidev.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/ucycom.c
diff -u src/sys/dev/usb/ucycom.c:1.51 src/sys/dev/usb/ucycom.c:1.52
--- src/sys/dev/usb/ucycom.c:1.51	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/ucycom.c	Mon Mar 28 12:42:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucycom.c,v 1.51 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: ucycom.c,v 1.52 2022/03/28 12:42:54 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.51 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.52 2022/03/28 12:42:54 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1105,7 +1105,7 @@ ucycom_set_status(struct ucycom_softc *s
 	memset(sc->sc_obuf, 0, sc->sc_olen);
 	sc->sc_obuf[0] = sc->sc_mcr;
 
-	err = uhidev_write(sc->sc_hdev.sc_parent, sc->sc_obuf, sc->sc_olen);
+	err = uhidev_write(&sc->sc_hdev, sc->sc_obuf, sc->sc_olen);
 	if (err) {
 		DPRINTF(("ucycom_set_status: err=%d\n", err));
 	}

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.120 src/sys/dev/usb/uhid.c:1.121
--- src/sys/dev/usb/uhid.c:1.120	Mon Mar 28 12:42:45 2022
+++ src/sys/dev/usb/uhid.c	Mon Mar 28 12:42:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.120 2022/03/28 12:42:45 riastradh Exp $	*/
+/*	$NetBSD: uhid.c,v 1.121 2022/03/28 12:42:54 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.120 2022/03/28 12:42:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.121 2022/03/28 12:42:54 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -495,8 +495,7 @@ uhidwrite(dev_t dev, struct uio *uio, in
 #endif
 	if (!error) {
 		if (sc->sc_raw)
-			err = uhidev_write(sc->sc_hdev.sc_parent, sc->sc_obuf,
-			    size);
+			err = uhidev_write(&sc->sc_hdev, sc->sc_obuf, size);
 		else
 			err = uhidev_set_report(&sc->sc_hdev,
 			    UHID_OUTPUT_REPORT, sc->sc_obuf, size);

Index: src/sys/dev/usb/uhidev.c
diff -u src/sys/dev/usb/uhidev.c:1.82 src/sys/dev/usb/uhidev.c:1.83
--- src/sys/dev/usb/uhidev.c:1.82	Wed Feb  9 18:09:48 2022
+++ src/sys/dev/usb/uhidev.c	Mon Mar 28 12:42:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhidev.c,v 1.82 2022/02/09 18:09:48 jakllsch Exp $	*/
+/*	$NetBSD: uhidev.c,v 1.83 2022/03/28 12:42:54 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.82 2022/02/09 18:09:48 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.83 2022/03/28 12:42:54 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -909,7 +909,7 @@ uhidev_stop(struct uhidev *scd)
 		abort = true;
 	mutex_exit(&sc->sc_lock);
 
-	if (abort && sc->sc_opipe)
+	if (abort && sc->sc_opipe) /* XXX sc_opipe might go away */
 		usbd_abort_pipe(sc->sc_opipe);
 }
 
@@ -969,8 +969,9 @@ uhidev_get_report(struct uhidev *scd, in
 }
 
 usbd_status
-uhidev_write(struct uhidev_softc *sc, void *data, int len)
+uhidev_write(struct uhidev *scd, void *data, int len)
 {
+	struct uhidev_softc *sc = scd->sc_parent;
 	usbd_status err;
 
 	DPRINTF(("uhidev_write: data=%p, len=%d\n", data, len));
@@ -993,6 +994,7 @@ uhidev_write(struct uhidev_softc *sc, vo
 		}
 	}
 	sc->sc_writelock = curlwp;
+	sc->sc_writereportid = scd->sc_report_id;
 	mutex_exit(&sc->sc_lock);
 
 #ifdef UHIDEV_DEBUG
@@ -1014,6 +1016,10 @@ uhidev_write(struct uhidev_softc *sc, vo
 	KASSERT(sc->sc_refcnt);
 	KASSERTMSG(sc->sc_writelock == curlwp, "%s: migrated from %p to %p",
 	    device_xname(sc->sc_dev), curlwp, sc->sc_writelock);
+	KASSERTMSG(sc->sc_writereportid == scd->sc_report_id,
+	    "%s: changed write report ids from %d to %d",
+	    device_xname(sc->sc_dev), scd->sc_report_id, sc->sc_writereportid);
+	sc->sc_writereportid = -1;
 	sc->sc_writelock = NULL;
 	cv_broadcast(&sc->sc_cv);
 out:	mutex_exit(&sc->sc_lock);

Index: src/sys/dev/usb/uhidev.h
diff -u src/sys/dev/usb/uhidev.h:1.21 src/sys/dev/usb/uhidev.h:1.22
--- src/sys/dev/usb/uhidev.h:1.21	Sun Nov 29 22:54:51 2020
+++ src/sys/dev/usb/uhidev.h	Mon Mar 28 12:42:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhidev.h,v 1.21 2020/11/29 22:54:51 riastradh Exp $	*/
+/*	$NetBSD: uhidev.h,v 1.22 2022/03/28 12:42:54 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@ void uhidev_stop(struct uhidev *);
 void uhidev_close(struct uhidev *);
 usbd_status uhidev_set_report(struct uhidev *, int, void *, int);
 usbd_status uhidev_get_report(struct uhidev *, int, void *, int);
-usbd_status uhidev_write(struct uhidev_softc *, void *, int);
+usbd_status uhidev_write(struct uhidev *, void *, int);
 
 #define	UHIDEV_OSIZE	64
 

Reply via email to