From nobody Mon Jul 04 14:27:19 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 6E62283107A; Mon, 4 Jul 2022 14:27:20 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lc7Rr1ccrz3N0F; Mon, 4 Jul 2022 14:27:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656944840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S3QdIdYiv8kstEz5oxeGAotJl2nj3uAeg0aOMxUFuQI=; b=Qth0mSEi+i5Qvshor7Fhw3lfMh6JGiOsQKA3bqXbQ+J+j6ubOCXzTHn3uKTNDaQFoGQ7qO 4V7jdpuuvmA6zgHnIJdklfE+gBRaLxI4dUlaHlkhDkEKtv/j8Ka9/ygpUtpsHwgXuVQm+c 6bLeFEtdjuiQNv6gSW9noGJkXKRWKdDwdkXiUhapOUeccjd7nb/N5tYx+x0CaMyGLZ56gj E5QCjA4Ua3II08TPrGzKf5GjPcNv8TfC9g+T5S/u26tmN7xbIeRj4kZkmDTjKUJjkm9sHn X6+iupVqdsYdwyS6JlvWNP1NO8Jkr29kMHxXx6sMqOoZy1IOtPw/bqDBqHjBQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 08A0212F0B; Mon, 4 Jul 2022 14:27:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 264ERJjA064440; Mon, 4 Jul 2022 14:27:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 264ERJ2x064439; Mon, 4 Jul 2022 14:27:19 GMT (envelope-from git) Date: Mon, 4 Jul 2022 14:27:19 GMT Message-Id: <202207041427.264ERJ2x064439@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: b1e931327426 - main - Fix ofw pcib when it rman_init fails List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b1e9313274265645e163508ff1704ace2e0b1294 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656944840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S3QdIdYiv8kstEz5oxeGAotJl2nj3uAeg0aOMxUFuQI=; b=iF4+537UkGnNmg1XE0/L0kIcHsJ8Z5VJEqXuI7cgX4311qYgY1n7gdhy/V3flw4LxMN35f gdRgBD0r1XQ1qFt/FNreHTAwoFt0xyafchaNMl7eu/2F4cJKGqaMtycAjn4gSeUnE2rjyN i+YtjRXlFZgHIr6PHMVUVuO5y2CXvoT95ITGFOd8xHGtX2FC57xy4vd6r+mvf+TlzHKfZO xeF9DVe3qTmn481Kj/pdQ55GvyeFfjLyg8MjI0VBtxjVYxdAfMOUKQcH6UlQIcnPeZM56H 4fZ3RPLwOI3oyVkAMht89y2u/+N3u/MKVq7UwNHDouhENatwoaOSgM8vU06liA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656944840; a=rsa-sha256; cv=none; b=xmwOJsgRlFdINH0EkHwBnL/ePoRUqgtM2k5eelw/DDVGKOfBOMKkTMkW7AQLvLCjE4+AV1 AH6Q1wG2ESwqIcLnxqZBmvlCOu3wXaHEGxkywJTA7ociyuItDezRYez0RfzQwddT+v5Fzf v2lZCbKWwIKFI7Gn/ln3iSxlMyGlwq/AVNnURJTyrKE+hWWaJCKXJ5apQ55rrxFoEPr7NJ AYE2IP0+JrmYrvHKy3/nvf+gH2agvvZQG6FOsSDHpyQTfqZCgwp9b0fr+HsnnosE4bmjDH KAc+OpOIRxfVDS+HJdlywlfH25gGiqnCJil1RYxoqh9ZRDYjf9POIeYRrWuNeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=b1e9313274265645e163508ff1704ace2e0b1294 commit b1e9313274265645e163508ff1704ace2e0b1294 Author: Andrew Turner AuthorDate: 2022-06-30 18:12:46 +0000 Commit: Andrew Turner CommitDate: 2022-07-04 14:27:00 +0000 Fix ofw pcib when it rman_init fails rman_fini assumes rman_init has been called successfully. Clean up init faulure by only calling rman_fini when rman_init has succeeded. While here add ofw_pcib_fini that can be used by a sub-class to clean up. Reviewed by: bz, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35681 --- sys/dev/ofw/ofw_pcib.c | 28 ++++++++++++++++++++++------ sys/dev/ofw/ofwpci.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sys/dev/ofw/ofw_pcib.c b/sys/dev/ofw/ofw_pcib.c index b10feffedf6c..e2aa0c9203b7 100644 --- a/sys/dev/ofw/ofw_pcib.c +++ b/sys/dev/ofw/ofw_pcib.c @@ -211,7 +211,7 @@ ofw_pcib_init(device_t dev) error = rman_init(&sc->sc_mem_rman); if (error != 0) { device_printf(dev, "rman_init() failed. error = %d\n", error); - goto out; + goto out_mem_rman; } sc->sc_pmem_rman.rm_type = RMAN_ARRAY; @@ -219,7 +219,7 @@ ofw_pcib_init(device_t dev) error = rman_init(&sc->sc_pmem_rman); if (error != 0) { device_printf(dev, "rman_init() failed. error = %d\n", error); - goto out; + goto out_pmem_rman; } for (i = 0; i < sc->sc_nrange; i++) { @@ -254,21 +254,37 @@ ofw_pcib_init(device_t dev) "error = %d\n", rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK, rp->pci, rp->pci + rp->size - 1, error); - goto out; + goto out_full; } } ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(cell_t)); return (0); +out_full: + rman_fini(&sc->sc_pmem_rman); +out_pmem_rman: + rman_fini(&sc->sc_mem_rman); +out_mem_rman: + rman_fini(&sc->sc_io_rman); out: - free(cell_info, M_DEVBUF); + free(sc->sc_cell_info, M_DEVBUF); + free(sc->sc_range, M_DEVBUF); + + return (error); +} + +void +ofw_pcib_fini(device_t dev) +{ + struct ofw_pci_softc *sc; + + sc = device_get_softc(dev); + free(sc->sc_cell_info, M_DEVBUF); free(sc->sc_range, M_DEVBUF); rman_fini(&sc->sc_io_rman); rman_fini(&sc->sc_mem_rman); rman_fini(&sc->sc_pmem_rman); - - return (error); } int diff --git a/sys/dev/ofw/ofwpci.h b/sys/dev/ofw/ofwpci.h index d58efa2daaef..7c2ec90a5d18 100644 --- a/sys/dev/ofw/ofwpci.h +++ b/sys/dev/ofw/ofwpci.h @@ -78,6 +78,7 @@ struct ofw_pci_softc { }; int ofw_pcib_init(device_t); +void ofw_pcib_fini(device_t); int ofw_pcib_attach(device_t); int ofw_pcib_read_ivar(device_t, device_t, int, uintptr_t *); int ofw_pcib_write_ivar(device_t, device_t, int, uintptr_t);