[PATCH] media: iris: avoid plain 64-bit division
From: Arnd Bergmann
Date: Fri Oct 02 2026 - 08:45:42 EST
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.
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.
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
--
2.53.0