[PATCH 13/25] coresight: trbe: Handle an already disabled sink
From: Leo Yan
Date: Tue Sep 15 2026 - 12:57:44 EST
arm_trbe_disable() detaches the trace buffer and clears cpudata->buf. A
subsequent disable dereferences this NULL pointer in the buffer consistency
check before testing whether the sink is still in perf mode.
Check the mode before accessing the buffer and return success when the
sink is already disabled. This allows deferred event cleanup to revisit a
path that an AUX snapshot has already disabled after a failure.
Assisted-by: Codex:gpt-6
Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
drivers/hwtracing/coresight/coresight-trbe.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
index 8eb625d3fc99db57a18e35ef59ef814dacf20a09..6da89a890712d32e87a15f7c564ff4dc4d197bb1 100644
--- a/drivers/hwtracing/coresight/coresight-trbe.c
+++ b/drivers/hwtracing/coresight/coresight-trbe.c
@@ -1098,11 +1098,15 @@ static int arm_trbe_disable(struct coresight_device *csdev)
struct trbe_cpudata *cpudata = dev_get_drvdata(&csdev->dev);
struct trbe_buf *buf = cpudata->buf;
+ /* A failed AUX snapshot may have already disabled the sink. */
+ if (cpudata->mode == CS_MODE_DISABLED)
+ return 0;
+ if (cpudata->mode != CS_MODE_PERF)
+ return -EINVAL;
+
WARN_ON(buf->cpudata != cpudata);
WARN_ON(cpudata->cpu != smp_processor_id());
WARN_ON(cpudata->drvdata != drvdata);
- if (cpudata->mode != CS_MODE_PERF)
- return -EINVAL;
trbe_drain_and_disable_local(cpudata);
buf->cpudata = NULL;
--
2.34.1