[PATCH 12/15] media: microchip-isc: do the AWB gain product in 64 bits

From: Balakrishnan Sambath

Date: Wed Dec 02 2026 - 02:16:52 EST


s_gain and gw_gain are Q9, so their product is Q18 and can wrap a u32
on a strong stretch with a large grey world gain. Multiply in u64 and
clamp the Q9 result to GENMASK(12, 0), the width of the gain field.

Signed-off-by: Balakrishnan Sambath <balakrishnan.s@xxxxxxxxxxxxx>
---
drivers/media/platform/microchip/microchip-isc-base.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c
index 491f710fe08d..a767dfc719f3 100644
--- a/drivers/media/platform/microchip/microchip-isc-base.c
+++ b/drivers/media/platform/microchip/microchip-isc-base.c
@@ -1428,11 +1428,9 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
"isc wb: component %d, s_gain %u, gw_gain %u\n",
c, s_gain[c], gw_gain[c]);
/* multiply both gains and adjust for decimals */
- ctrls->gain[c] = s_gain[c] * gw_gain[c];
- ctrls->gain[c] >>= 9;
-
- /* make sure we are not out of range */
- ctrls->gain[c] = clamp_val(ctrls->gain[c], 0, GENMASK(12, 0));
+ /* the product of two Q9 gains can exceed 32 bits */
+ ctrls->gain[c] = min_t(u64, ((u64)s_gain[c] * gw_gain[c]) >> 9,
+ GENMASK(12, 0));

dev_dbg(isc->dev, "isc wb: component %d, final gain %u\n",
c, ctrls->gain[c]);

--
2.34.1