[PATCH v2 02/23] coresight: trbe: Make watermark range check overflow safe in __trbe_normal_offset()

James Clark james.clark at linaro.org
Tue Nov 10 07:28:41 PST 2026



On 16/10/2026 17:55, Leo Yan wrote:
> 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 at arm.com>
> ---
>   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));
>   
>   	/*
> 

Reviewed-by: James Clark <james.clark at linaro.org>



More information about the linux-arm-kernel mailing list