diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-03-13 12:49:36 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-03-13 12:49:36 +0000 |
| commit | 2fdd42007862bc4cc55f8bf037cd92b4e43fb613 (patch) | |
| tree | 36adecf0942fb003b6c4303c5fad3c68ee7369c2 /sys | |
| parent | d09dda326024cd5769992c8f6a0b8ca2eaa6856d (diff) | |
auvitek(4): Fix i2c detach if attach failed.
While here, use config_detach_children.
Reported-by: syzbot+bf05898af6a53cb3b262@syzkaller.appspotmail.com
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/dev/usb/auvitek.c | 16 | ||||
| -rw-r--r-- | sys/dev/usb/auvitek_audio.c | 8 | ||||
| -rw-r--r-- | sys/dev/usb/auvitek_dtv.c | 8 | ||||
| -rw-r--r-- | sys/dev/usb/auvitek_i2c.c | 14 | ||||
| -rw-r--r-- | sys/dev/usb/auvitek_video.c | 8 | ||||
| -rw-r--r-- | sys/dev/usb/auvitekvar.h | 3 |
6 files changed, 31 insertions, 26 deletions
diff --git a/sys/dev/usb/auvitek.c b/sys/dev/usb/auvitek.c index d78ac38ea6c..a9ecf0812f7 100644 --- a/sys/dev/usb/auvitek.c +++ b/sys/dev/usb/auvitek.c @@ -1,4 +1,4 @@ -/* $NetBSD: auvitek.c,v 1.12 2020/03/14 02:35:33 christos Exp $ */ +/* $NetBSD: auvitek.c,v 1.13 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.12 2020/03/14 02:35:33 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.13 2022/03/13 12:49:36 riastradh Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -260,9 +260,21 @@ static int auvitek_detach(device_t self, int flags) { struct auvitek_softc *sc = device_private(self); + int error; sc->sc_dying = 1; + error = config_detach_children(self, flags); + if (error) { + /* + * XXX Should ask autoconf to block open with + * .d_cfdriver until we're done, instead of setting + * this and then rolling it back. + */ + sc->sc_dying = 0; + return error; + } + pmf_device_deregister(self); auvitek_dtv_detach(sc, flags); diff --git a/sys/dev/usb/auvitek_audio.c b/sys/dev/usb/auvitek_audio.c index da7d6618854..36cd8636927 100644 --- a/sys/dev/usb/auvitek_audio.c +++ b/sys/dev/usb/auvitek_audio.c @@ -1,4 +1,4 @@ -/* $NetBSD: auvitek_audio.c,v 1.5 2021/08/07 16:19:16 thorpej Exp $ */ +/* $NetBSD: auvitek_audio.c,v 1.6 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auvitek_audio.c,v 1.5 2021/08/07 16:19:16 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auvitek_audio.c,v 1.6 2022/03/13 12:49:36 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -112,10 +112,6 @@ auvitek_audio_attach(struct auvitek_softc *sc) int auvitek_audio_detach(struct auvitek_softc *sc, int flags) { - if (sc->sc_audiodev != NULL) { - config_detach(sc->sc_audiodev, flags); - sc->sc_audiodev = NULL; - } return 0; } diff --git a/sys/dev/usb/auvitek_dtv.c b/sys/dev/usb/auvitek_dtv.c index cc364a33203..e161a67a974 100644 --- a/sys/dev/usb/auvitek_dtv.c +++ b/sys/dev/usb/auvitek_dtv.c @@ -1,4 +1,4 @@ -/* $NetBSD: auvitek_dtv.c,v 1.9 2021/08/07 16:19:16 thorpej Exp $ */ +/* $NetBSD: auvitek_dtv.c,v 1.10 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auvitek_dtv.c,v 1.9 2021/08/07 16:19:16 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auvitek_dtv.c,v 1.10 2022/03/13 12:49:36 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -98,10 +98,6 @@ auvitek_dtv_attach(struct auvitek_softc *sc) int auvitek_dtv_detach(struct auvitek_softc *sc, int flags) { - if (sc->sc_dtvdev != NULL) { - config_detach(sc->sc_dtvdev, flags); - sc->sc_dtvdev = NULL; - } return 0; } diff --git a/sys/dev/usb/auvitek_i2c.c b/sys/dev/usb/auvitek_i2c.c index f8c999b49fc..3f0b845ad0f 100644 --- a/sys/dev/usb/auvitek_i2c.c +++ b/sys/dev/usb/auvitek_i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: auvitek_i2c.c,v 1.7 2021/08/07 16:19:16 thorpej Exp $ */ +/* $NetBSD: auvitek_i2c.c,v 1.8 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auvitek_i2c.c,v 1.7 2021/08/07 16:19:16 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auvitek_i2c.c,v 1.8 2022/03/13 12:49:36 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -71,22 +71,26 @@ static bool auvitek_i2c_wait_wrdone(struct auvitek_softc *); int auvitek_i2c_attach(struct auvitek_softc *sc) { + iic_tag_init(&sc->sc_i2c); sc->sc_i2c.ic_cookie = sc; sc->sc_i2c.ic_exec = auvitek_i2c_exec; auvitek_i2c_rescan(sc, NULL, NULL); + sc->sc_i2c_attached = true; + return 0; } int auvitek_i2c_detach(struct auvitek_softc *sc, int flags) { - iic_tag_fini(&sc->sc_i2c); - if (sc->sc_i2cdev) - config_detach(sc->sc_i2cdev, flags); + if (!sc->sc_i2c_attached) + return 0; + + iic_tag_fini(&sc->sc_i2c); return 0; } diff --git a/sys/dev/usb/auvitek_video.c b/sys/dev/usb/auvitek_video.c index a5822c38e09..f939ae71591 100644 --- a/sys/dev/usb/auvitek_video.c +++ b/sys/dev/usb/auvitek_video.c @@ -1,4 +1,4 @@ -/* $NetBSD: auvitek_video.c,v 1.10 2022/03/03 06:23:25 riastradh Exp $ */ +/* $NetBSD: auvitek_video.c,v 1.11 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auvitek_video.c,v 1.10 2022/03/03 06:23:25 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auvitek_video.c,v 1.11 2022/03/13 12:49:36 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -140,10 +140,6 @@ auvitek_video_attach(struct auvitek_softc *sc) int auvitek_video_detach(struct auvitek_softc *sc, int flags) { - if (sc->sc_videodev != NULL) { - config_detach(sc->sc_videodev, flags); - sc->sc_videodev = NULL; - } return 0; } diff --git a/sys/dev/usb/auvitekvar.h b/sys/dev/usb/auvitekvar.h index 55da9b266c2..7a7c7ef9ffb 100644 --- a/sys/dev/usb/auvitekvar.h +++ b/sys/dev/usb/auvitekvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: auvitekvar.h,v 1.9 2016/04/23 10:15:31 skrll Exp $ */ +/* $NetBSD: auvitekvar.h,v 1.10 2022/03/13 12:49:36 riastradh Exp $ */ /*- * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> @@ -102,6 +102,7 @@ struct auvitek_softc { device_t sc_videodev, sc_dtvdev, sc_audiodev, sc_i2cdev; struct i2c_controller sc_i2c; kmutex_t sc_i2c_lock; + bool sc_i2c_attached; struct usbd_device *sc_udev; int sc_uport; |
