[PATCH v2 02/23] coresight: trbe: Make watermark range check overflow safe in __trbe_normal_offset()
From: Leo Yan
Date: Fri Oct 16 2026 - 14:02:50 EST
The current code checks whether the wakeup point lies before the current
tail by comparing against handle->head + handle->size. That addition can
overflow when the monotonically increasing perf AUX head is close to
ULONG_MAX, causing a valid wakeup point in the current writable range to
be missed.
Use unsigned subtraction to compare the distance from head to wakeup
against the buffer size instead. This keeps the check correct across
potential wrap.
Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
drivers/hwtracing/coresight/coresight-trbe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
index eca8e13a97447b46a4b383049aacb3fa7ad3c329..02d12445763a86d58c79bdf5143f761827456bc3 100644
--- a/drivers/hwtracing/coresight/coresight-trbe.c
+++ b/drivers/hwtracing/coresight/coresight-trbe.c
@@ -526,7 +526,7 @@ static unsigned long __trbe_normal_offset(struct perf_output_handle *handle)
* +----|---------------|-------|-------+
* trbe_base limit trbe_base + nr_pages
*/
- if (handle->wakeup < (handle->head + handle->size) && head <= wakeup)
+ if ((handle->wakeup - handle->head) < handle->size && head <= wakeup)
limit = min(limit, round_up(wakeup, PAGE_SIZE));
/*
--
2.34.1