summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-06-26 22:49:09 +0000
committerriastradh <riastradh@NetBSD.org>2022-06-26 22:49:09 +0000
commitbbad64b1ef7105ceb1592b45cabf7574bfc645c0 (patch)
tree20fe2bd150eff6cd649dfddfc1cbab83af11578b /sys
parentbdea235f0e4187f6dad9acd324684bbb98123bf6 (diff)
emdtv(4): More attach/detach bugs.
Reported-by: syzbot+9bbfb743349929e2c8c3@syzkaller.appspotmail.com
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/usb/emdtv.c11
-rw-r--r--sys/dev/usb/emdtv_ir.c22
-rw-r--r--sys/dev/usb/emdtvvar.h4
3 files changed, 22 insertions, 15 deletions
diff --git a/sys/dev/usb/emdtv.c b/sys/dev/usb/emdtv.c
index 7e538a76fd0..1c2696d6558 100644
--- a/sys/dev/usb/emdtv.c
+++ b/sys/dev/usb/emdtv.c
@@ -1,4 +1,4 @@
-/* $NetBSD: emdtv.c,v 1.17 2022/03/29 09:08:44 riastradh Exp $ */
+/* $NetBSD: emdtv.c,v 1.18 2022/06/26 22:49:09 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2011 Jared D. McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emdtv.c,v 1.17 2022/03/29 09:08:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emdtv.c,v 1.18 2022/06/26 22:49:09 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -148,6 +148,7 @@ emdtv_attach(device_t parent, device_t self, void *opaque)
emdtv_dtv_attach(sc);
emdtv_ir_attach(sc);
+ sc->sc_subdevs_attached = true;
}
static int
@@ -163,8 +164,10 @@ emdtv_detach(device_t self, int flags)
if (error)
return error;
- emdtv_ir_detach(sc, flags);
- emdtv_dtv_detach(sc, flags);
+ if (sc->sc_subdevs_attached) {
+ emdtv_ir_detach(sc, flags);
+ emdtv_dtv_detach(sc, flags);
+ }
if (sc->sc_iface != NULL) {
status = usbd_set_interface(sc->sc_iface, 0);
diff --git a/sys/dev/usb/emdtv_ir.c b/sys/dev/usb/emdtv_ir.c
index e7557c34ed0..e3103931c03 100644
--- a/sys/dev/usb/emdtv_ir.c
+++ b/sys/dev/usb/emdtv_ir.c
@@ -1,4 +1,4 @@
-/* $NetBSD: emdtv_ir.c,v 1.5 2022/03/29 09:08:44 riastradh Exp $ */
+/* $NetBSD: emdtv_ir.c,v 1.6 2022/06/26 22:49:09 riastradh Exp $ */
/*-
* Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emdtv_ir.c,v 1.5 2022/03/29 09:08:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emdtv_ir.c,v 1.6 2022/06/26 22:49:09 riastradh Exp $");
#include <sys/select.h>
#include <sys/param.h>
@@ -75,10 +75,20 @@ emdtv_ir_attach(struct emdtv_softc *sc)
usbd_status status;
int err;
+ mutex_init(&sc->sc_ir_mutex, MUTEX_DEFAULT, IPL_VM);
+
ed = usbd_interface2endpoint_descriptor(sc->sc_iface, 0);
if (ed == NULL)
return;
+ err = workqueue_create(&sc->sc_ir_wq, "emdtvir",
+ emdtv_ir_worker, sc, PRI_NONE, IPL_VM, 0);
+ if (err) {
+ aprint_error_dev(sc->sc_dev, "couldn't create workqueue: %d\n",
+ err);
+ return;
+ }
+
status = usbd_open_pipe_intr(sc->sc_iface, ed->bEndpointAddress,
USBD_EXCLUSIVE_USE, &sc->sc_intr_pipe, sc, &sc->sc_intr_buf, 1,
emdtv_ir_intr, USBD_DEFAULT_INTERVAL);
@@ -88,14 +98,6 @@ emdtv_ir_attach(struct emdtv_softc *sc)
return;
}
- mutex_init(&sc->sc_ir_mutex, MUTEX_DEFAULT, IPL_VM);
-
- err = workqueue_create(&sc->sc_ir_wq, "emdtvir",
- emdtv_ir_worker, sc, PRI_NONE, IPL_VM, 0);
- if (err)
- aprint_error_dev(sc->sc_dev, "couldn't create workqueue: %d\n",
- err);
-
ia.ia_type = IR_TYPE_CIR;
ia.ia_methods = &emdtv_ir_methods;
ia.ia_handle = sc;
diff --git a/sys/dev/usb/emdtvvar.h b/sys/dev/usb/emdtvvar.h
index f9dd46d0549..924ac6f5e14 100644
--- a/sys/dev/usb/emdtvvar.h
+++ b/sys/dev/usb/emdtvvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: emdtvvar.h,v 1.4 2016/04/23 10:15:31 skrll Exp $ */
+/* $NetBSD: emdtvvar.h,v 1.5 2022/06/26 22:49:09 riastradh Exp $ */
/*-
* Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
@@ -70,6 +70,8 @@ struct emdtv_softc {
uint16_t sc_vendor, sc_product;
+ bool sc_subdevs_attached;
+
const struct emdtv_board *sc_board;
struct lg3303 *sc_lg3303;