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.
This commit is contained in:
Ian Lepore 2021-09-28 12:19:44 -06:00
parent 819961c580
commit 1acf73d544

View File

@ -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);