Date: Fri, 7 Feb 2020 21:55:45 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r357666 - in stable: 11/sys/dev/atkbdc 12/sys/dev/atkbdc Message-ID: <202002072155.017Ltjv1007948@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Fri Feb 7 21:55:45 2020 New Revision: 357666 URL: https://svnweb.freebsd.org/changeset/base/357666 Log: MFC r357509-r357510: small psm cleanup r357509: psm: release resources on attach failure In exactly 1/3 cases we'll release resources on failure; touch up the other two to do so as well. r357510: psm: use make_dev_s instead of make_dev This most importantly reduces duplication, but it also removes any potential race with usage of dev->si_drv1 since it's now set prior to the device being constructed enough to be accessible. Modified: stable/11/sys/dev/atkbdc/psm.c Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/12/sys/dev/atkbdc/psm.c Directory Properties: stable/12/ (props changed) Modified: stable/11/sys/dev/atkbdc/psm.c ============================================================================== --- stable/11/sys/dev/atkbdc/psm.c Fri Feb 7 21:36:14 2020 (r357665) +++ stable/11/sys/dev/atkbdc/psm.c Fri Feb 7 21:55:45 2020 (r357666) @@ -1940,6 +1940,7 @@ psm_register_elantech(device_t dev) static int psmattach(device_t dev) { + struct make_dev_args mda; int unit = device_get_unit(dev); struct psm_softc *sc = device_get_softc(dev); int error; @@ -1957,17 +1958,20 @@ psmattach(device_t dev) return (ENXIO); error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, psmintr, sc, &sc->ih); - if (error) { - bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); - return (error); - } + if (error) + goto out; /* Done */ - sc->dev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "psm%d", unit); - sc->dev->si_drv1 = sc; - sc->bdev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "bpsm%d", unit); - sc->bdev->si_drv1 = sc; + make_dev_args_init(&mda); + mda.mda_devsw = &psm_cdevsw; + mda.mda_mode = 0666; + mda.mda_si_drv1 = sc; + if ((error = make_dev_s(&mda, &sc->dev, "psm%d", unit)) != 0) + goto out; + if ((error = make_dev_s(&mda, &sc->bdev, "bpsm%d", unit)) != 0) + goto out; + #ifdef EVDEV_SUPPORT switch (sc->hw.model) { case MOUSE_MODEL_SYNAPTICS: @@ -1983,7 +1987,7 @@ psmattach(device_t dev) } if (error) - return (error); + goto out; #endif /* Some touchpad devices need full reinitialization after suspend. */ @@ -2024,7 +2028,15 @@ psmattach(device_t dev) if (bootverbose) --verbose; - return (0); +out: + if (error != 0) { + bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); + if (sc->dev != NULL) + destroy_dev(sc->dev); + if (sc->bdev != NULL) + destroy_dev(sc->bdev); + } + return (error); } static int
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002072155.017Ltjv1007948>