On 11/20/2025 6:40 AM, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
>
> The code that bounds the brs->nr to event->attr.sample_max_stack
> incorrectly masks brs->nr with 65535 before the limit check.
> Replace the min_t(u16, ...) with a plain min(...).
>
> I guess there may be another limit on brs->nr (which is u64).
>
> Fixes: c53e14f1ea4a8 ("perf: Extend per event callchain limit to branch stack")
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
> include/linux/perf_event.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index fd1d91017b99..f91c875ea311 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -1430,7 +1430,7 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data,
> if (branch_sample_hw_index(event))
> size += sizeof(u64);
>
> - brs->nr = min_t(u16, event->attr.sample_max_stack, brs->nr);
> + brs->nr = min(event->attr.sample_max_stack, brs->nr);
>
> size += brs->nr * sizeof(struct perf_branch_entry);
>
LGTM. Thanks.
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>