⬢ DragonFlyBSD Kernel Audit
DF-4555 / fix.diff
← back to finding ↓ download raw
fix.diff — DF-4555: honor acquire() failure and make release_engine() NULL-safe

Two-part fix. Part 1 (primary, in the caller that ignores the result today)
stops the known-bad sequencing. Part 2 (defense-in-depth, in the audited file)
makes release_engine() safe for any future caller that repeats the mistake,
mirroring the NULL-safety that already exists in dal_gpio_close().

Never applied to sys/ (read-only audit target).

--- a/sys/dev/drm/amd/display/dc/core/dc_link_ddc.c
+++ b/sys/dev/drm/amd/display/dc/core/dc_link_ddc.c
@@ -652,7 +652,10 @@ int dc_link_aux_transfer(struct ddc_service *ddc,
 	memset(&aux_rep, 0, sizeof(aux_rep));

 	aux_engine = ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en];
-	aux_engine->funcs->acquire(aux_engine, ddc_pin);
+	if (!aux_engine->funcs->acquire(aux_engine, ddc_pin)) {
+		/* engine not owned: do not submit, do not release */
+		return -1;
+	}

 	aux_req.type = type;
 	aux_req.action = action;
--- a/sys/dev/drm/amd/display/dc/dce/dce_aux.c
+++ b/sys/dev/drm/amd/display/dc/dce/dce_aux.c
@@ -55,7 +55,10 @@ static void release_engine(
 	struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine);

-	dal_ddc_close(engine->ddc);
+	/* NULL-safe: engine->ddc is only set by a successful acquire() */
+	if (engine->ddc)
+		dal_ddc_close(engine->ddc);

 	engine->ddc = NULL;

 	REG_UPDATE(AUX_ARB_CONTROL, AUX_SW_DONE_USING_AUX_REG, 1);