Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Rearranging the expression to `status->busy_time * 100` introduces 
an integer overflow on 32-bit architectures, resulting in drastically incorrect 
devfreq load percentages being logged.
--

--- Patch [2]: [PATCH 2/3] drm/panfrost: Prevent division by 0 ---
commit f1707dda0ddcd92307754978d37b7e0bf9939612
Author: Adrián Larumbe <[email protected]>
drm/panfrost: Prevent division by 0

This commit addresses a potential division by zero when calculating device
frequency utilization for debug logging. It rearranges the calculation to
multiply busy time by 100 before dividing by the maximum of total time or 1.

Closes: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/88

> diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c 
> b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
> --- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
> @@ -78,7 +78,7 @@ static int panfrost_devfreq_get_dev_status(struct device 
> *dev,
>  
>       dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n",
>               status->busy_time, status->total_time,
> -             status->busy_time / (status->total_time / 100),
> +             status->busy_time * 100 / MAX(status->total_time, 1),

[Severity: Medium]
Will this calculation overflow on 32-bit architectures?

In panfrost_devfreq_get_dev_status(), status->busy_time is an unsigned long,
which is 32 bits on ARM32 architectures where Panfrost is widely used.

Since devfreq times are calculated in nanoseconds, a standard 50ms polling
interval can yield a busy_time of around 50,000,000 ns. Multiplying
50,000,000 by 100 results in 5,000,000,000, which exceeds the maximum
32-bit unsigned long value of 4,294,967,295.

Could this cause drastically incorrect load percentages to be logged during
normal GPU workloads when devfreq debug logging is enabled?

>               status->current_frequency / 1000 / 1000);
>  
>       return 0;

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=2

Reply via email to