Message ID | 20211213134940.324266-20-eugen.hristev@microchip.com |
---|---|
State | Accepted |
Commit | 3f050110617de71c6bc65867fc56bdb30ee07f38 |
Headers | show |
Series | [v3,01/23] MAINTAINERS: add microchip csi2dc | expand |
Hi Eugen On Mon, Dec 13, 2021 at 03:49:36PM +0200, Eugen Hristev wrote: > White balance computed gains can overflow above the 13 bits hardware > coefficient that can be used, in some specific scenarios like a subexposure > from the sensor when the image is mostly black. > In this case the computed gain has to be clamped to the maximum value > allowed by the hardware. > > Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com> > --- > drivers/media/platform/atmel/atmel-isc-base.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c > index f1f1019f9d82..31c8e3029eee 100644 > --- a/drivers/media/platform/atmel/atmel-isc-base.c > +++ b/drivers/media/platform/atmel/atmel-isc-base.c > @@ -1415,6 +1415,10 @@ static void isc_wb_update(struct isc_ctrls *ctrls) > /* 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)); #include <linux/minmax.h> What is the type of gain[c} ? If it's unsigned clamping with [0 is not required. I would in that case gain[c] = min(gain[c], ...) It's fine anyway Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org> Thanks j > + > v4l2_dbg(1, debug, &isc->v4l2_dev, > "isc wb: component %d, final gain %u\n", > c, ctrls->gain[c]); > -- > 2.25.1 >
diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c index f1f1019f9d82..31c8e3029eee 100644 --- a/drivers/media/platform/atmel/atmel-isc-base.c +++ b/drivers/media/platform/atmel/atmel-isc-base.c @@ -1415,6 +1415,10 @@ static void isc_wb_update(struct isc_ctrls *ctrls) /* 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)); + v4l2_dbg(1, debug, &isc->v4l2_dev, "isc wb: component %d, final gain %u\n", c, ctrls->gain[c]);
White balance computed gains can overflow above the 13 bits hardware coefficient that can be used, in some specific scenarios like a subexposure from the sensor when the image is mostly black. In this case the computed gain has to be clamped to the maximum value allowed by the hardware. Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com> --- drivers/media/platform/atmel/atmel-isc-base.c | 4 ++++ 1 file changed, 4 insertions(+)