From owner-dev-commits-src-main@freebsd.org Tue Sep 28 18:22:57 2021 Return-Path: Delivered-To: dev-commits-src-main@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 F1BD56A9D88; Tue, 28 Sep 2021 18:22:56 +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 4HJntS6FfCz4d1J; Tue, 28 Sep 2021 18:22:56 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B79411614; Tue, 28 Sep 2021 18:22:56 +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 18SIMuNI055765; Tue, 28 Sep 2021 18:22:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18SIMucq055764; Tue, 28 Sep 2021 18:22:56 GMT (envelope-from git) Date: Tue, 28 Sep 2021 18:22:56 GMT Message-Id: <202109281822.18SIMucq055764@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ian Lepore Subject: git: 1acf73d54412 - main - qoriq_therm.c: avoid a segfault on the error exit path. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ian X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1acf73d5441219d292e225bf0afbd81b490c4b91 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2021 18:22:57 -0000 The branch main has been updated by ian: URL: https://cgit.FreeBSD.org/src/commit/?id=1acf73d5441219d292e225bf0afbd81b490c4b91 commit 1acf73d5441219d292e225bf0afbd81b490c4b91 Author: Ian Lepore AuthorDate: 2021-09-28 18:19:44 +0000 Commit: Ian Lepore 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);