From owner-svn-src-stable-11@freebsd.org Fri Feb 7 21:55:45 2020 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EEFE222F2A6; Fri, 7 Feb 2020 21:55:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48DpyT64X0z440y; Fri, 7 Feb 2020 21:55:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C6DC3B360; Fri, 7 Feb 2020 21:55:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 017Ltjcu007949; Fri, 7 Feb 2020 21:55:45 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 017Ltjv1007948; Fri, 7 Feb 2020 21:55:45 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202002072155.017Ltjv1007948@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 7 Feb 2020 21:55:45 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/sys/dev/atkbdc 12/sys/dev/atkbdc X-SVN-Commit-Revision: 357666 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Feb 2020 21:55:46 -0000 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