Re: [PATCH v3 2/2] media: i2c: add Sony IMX111 CMOS camera sensor driver

From: Kieran Bingham

Date: Thu Oct 30 2025 - 11:57:48 EST


Quoting Svyatoslav Ryhel (2025-10-30 15:13:31)
...
> >
> > > +static int imx111_initialize(struct imx111 *sensor)
> > > +{
> > > +   struct device *dev = regmap_get_device(sensor->regmap);
> > > +   int ret;
> >
> > ret = 0;
> >
>
> cci_write does not state that ret must be initiated.
>
> > > +
> > > +   /* Configure the PLL. */
> > > +   cci_write(sensor->regmap, IMX111_PRE_PLL_CLK_DIVIDER_PLL1,
> > > +          sensor->pll->pre_div, &ret);

You definitely need to initialise ret = 0 or this line above will
probably fail because cci_write uses 'ret' to decide to do anything or
not.

- https://docs.kernel.org/driver-api/media/v4l2-cci.html

===============================================================================
int cci_write(struct regmap *map, u32 reg, u64 val, int *err)

Write a value to a single CCI register

Parameters

struct regmap *map
Register map to write to

u32 reg
Register address to write, use CCI_REG#() macros to encode reg width

u64 val
Value to be written

int *err
Optional pointer to store errors, if a previous error is set then
the write will be skipped

Return

0 on success or a negative error code on failure.
===============================================================================


So it should be initialised in a good state *or* you use NULL on
this first call and assign it - but init to ret = 0 is cleaner here I
think.

> > > +   cci_write(sensor->regmap, IMX111_PLL_MULTIPLIER_PLL1, sensor->pll->mult, &ret);
> > > +   cci_write(sensor->regmap, IMX111_POST_DIVIDER, IMX111_POST_DIVIDER_DIV1, &ret);
> > > +   cci_write(sensor->regmap, IMX111_PLL_SETTLING_TIME,
> > > +          to_settle_delay(sensor->pll->extclk_rate), &ret);
> > > +
> > > +   ret = cci_multi_reg_write(sensor->regmap, imx111_global_init,
> > > +                      ARRAY_SIZE(imx111_global_init), NULL);
> >
> > You are overwriting the previous errors.
> >
> > please use ret |=

No - just continue with the same pattern:

cci_multi_reg_write(sensor->regmap, imx111_global_init,
   ARRAY_SIZE(imx111_global_init), &ret);

> >
> > > +   if (ret < 0) {
> > > +         dev_err(dev, "Failed to initialize the sensor\n");
> > > +         return ret;
> > > +   }
> > > +
> > > +   return 0;
> > > +}