Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Sep 2021 18:22:56 GMT
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 1acf73d54412 - main - qoriq_therm.c: avoid a segfault on the error exit path.
Message-ID:  <202109281822.18SIMucq055764@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by ian:

URL: https://cgit.FreeBSD.org/src/commit/?id=1acf73d5441219d292e225bf0afbd81b490c4b91

commit 1acf73d5441219d292e225bf0afbd81b490c4b91
Author:     Ian Lepore <ian@FreeBSD.org>
AuthorDate: 2021-09-28 18:19:44 +0000
Commit:     Ian Lepore <ian@FreeBSD.org>
CommitDate: 2021-09-28 18:19:44 +0000

    qoriq_therm.c: avoid a segfault on the error exit path.
    
    If anything goes wrong during attach() it is handled with a 'goto fail'
    which calls sysctl_ctx_free().  But the sysctl context doesn't get
    initialized until very late in attach(), so almost any error just results
    in a segfault.  Move the sysctl_ctx_init() call to the beginning of the
    attach() function, so that it is done before any errors can happen that
    will lead to freeing the context.
---
 sys/arm64/qoriq/qoriq_therm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/arm64/qoriq/qoriq_therm.c b/sys/arm64/qoriq/qoriq_therm.c
index 33237fc94c07..c880e68025bf 100644
--- a/sys/arm64/qoriq/qoriq_therm.c
+++ b/sys/arm64/qoriq/qoriq_therm.c
@@ -190,7 +190,6 @@ qoriq_therm_init_sysctl(struct qoriq_therm_softc *sc)
 	int i;
 	struct sysctl_oid *oid, *tmp;
 
-	sysctl_ctx_init(&qoriq_therm_sysctl_ctx);
 	/* create node for hw.temp */
 	oid = SYSCTL_ADD_NODE(&qoriq_therm_sysctl_ctx,
 	    SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO, "temperature",
@@ -269,6 +268,8 @@ qoriq_therm_attach(device_t dev)
 	node = ofw_bus_get_node(sc->dev);
 	sc->little_endian = OF_hasprop(node, "little-endian");
 
+	sysctl_ctx_init(&qoriq_therm_sysctl_ctx);
+
 	rid = 0;
 	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
 	    RF_ACTIVE);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109281822.18SIMucq055764>