From d6c74926767a26e16a4a1fc0a8d5a1c3c2d1afdf Mon Sep 17 00:00:00 2001 From: kevans Date: Tue, 4 Feb 2020 18:45:28 +0000 Subject: [PATCH] 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. --- sys/dev/atkbdc/psm.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/dev/atkbdc/psm.c b/sys/dev/atkbdc/psm.c index 20586ba9267c..67890f45bb1e 100644 --- a/sys/dev/atkbdc/psm.c +++ b/sys/dev/atkbdc/psm.c @@ -1948,6 +1948,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; @@ -1969,10 +1970,15 @@ psmattach(device_t dev) 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) { @@ -2031,8 +2037,13 @@ psmattach(device_t dev) --verbose; out: - if (error != 0) + 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); }