[v5,29/47] ipa: libipa: agc: Fix multiplication type
diff mbox series

Message ID 20260817114349.994123-30-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • ipa: libipa: agc rework
Related show

Commit Message

Barnabás Pőcze Aug. 17, 2026, 11:43 a.m. UTC
The type of `frameSize` is `uint64_t`, but it is assigned the result
of a 32-bit multiplication. So make one of the terms a 64-bit integer
so that the result will be actually 64-bit.

Furthermore, also adjust the calculation to do the multiplication first
just to be as accurate as possible. No wraparound will happen as long
as the frame size is less than about 16.7 TiB.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/libipa/agc.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
index 8ae5d61075..15c7bb204d 100644
--- a/src/ipa/libipa/agc.cpp
+++ b/src/ipa/libipa/agc.cpp
@@ -330,8 +330,8 @@  int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
 
 	std::array<int64_t, 3> frameDurations;
 	for (unsigned int i = 0; i < frameHeights.size(); ++i) {
-		uint64_t frameSize = lineLength * frameHeights[i];
-		frameDurations[i] = frameSize / (config.sensorInfo.pixelRate / 1000000U);
+		uint64_t frameSize = static_cast<uint64_t>(lineLength) * frameHeights[i];
+		frameDurations[i] = frameSize * 1000000U / config.sensorInfo.pixelRate;
 	}
 
 	/*