mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: iris: avoid plain 64-bit division
@ 2026-10-02 12:44 Arnd Bergmann
  0 siblings, 0 replies; only message in thread
From: Arnd Bergmann @ 2026-10-02 12:44 UTC (permalink / raw)
  To: Vikash Garodia, Dikshita Agarwal, Bryan O'Donoghue,
	Mauro Carvalho Chehab, Sachin Kumar Garg
  Cc: Arnd Bergmann, Abhinav Kumar, Wangao Wang, Dmitry Baryshkov,
	Deepa Guthyappa Madivalara, linux-media, linux-arm-msm,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

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@arndb.de>
---
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@arndb.de>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-02 12:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02 12:44 [PATCH] media: iris: avoid plain 64-bit division Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®