Re: [PATCH] media: iris: avoid plain 64-bit division

From: David Laight

Date: Sat Oct 03 2026 - 13:38:36 EST


On Fri, 2 Oct 2026 14:44:22 +0200
Arnd Bergmann <arnd@xxxxxxxxxx> wrote:

> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> inst->fw_caps[BITRATE].value is a 64-bit integer, which on 32-bit
> architectures cannot be divided:
>
> ERROR: modpost: drivers/media/platform/qcom/iris/qcom-iris.ko: symbol '__divdi3' undefined!
>
> In particular, doing three divisions in a row is particularly slow,
> even on 64-bit CPUs.
>
> Rework the calculation to replace it with a single division, thus
> avoiding the build failure.
>
> Fixes: 5f21cd9a4ae4 ("media: iris: add support for multi_slice in iris encoder")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> Please check the math, as I'm not sure if this is the intended
> amount of rounding. Previously it was rounding down twice and up
> once, now it just rounds up during the combined division.

Can definitely change the result:
DIV_ROUND_UP(7 / 3, 2) is 1
but
DIV_ROUND_UP(7, 2 * 3) is 2
who knows what the value is supposed to be.

>
> Ideally this would be replaced with a cast of the incoming value
> to u32, but doing this requires to prove that this does not overflow.

You only need to prove that in incoming value is less than 32G (Hz).
The '/ 8' is cheap(ish) and can be done first.

David

>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> drivers/media/platform/qcom/iris/iris_ctrls.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/iris/iris_ctrls.c b/drivers/media/platform/qcom/iris/iris_ctrls.c
> index 8c4c47944f22..5294999fdf7b 100644
> --- a/drivers/media/platform/qcom/iris/iris_ctrls.c
> +++ b/drivers/media/platform/qcom/iris/iris_ctrls.c
> @@ -1588,8 +1588,9 @@ int iris_set_slice_count(struct iris_inst *inst, enum platform_inst_fw_cap_type
> } else if (slice_mode == V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES) {
> hfi_value = inst->fw_caps[SLICE_MAX_BYTES].value;
> if (rc_type != HFI_RC_OFF) {
> - max_avg_slicesize = DIV_ROUND_UP((inst->fw_caps[BITRATE].value / fps) / 8,
> - slice_caps->max_slices_per_frame);
> + max_avg_slicesize = DIV_U64_ROUND_UP(inst->fw_caps[BITRATE].value,
> + fps * 8 *
> + slice_caps->max_slices_per_frame);
> } else {
> /*
> * No bitrate target exists under RC_OFF, so approximate a