Re: [PATCH v4 2/2] media: i2c: add ov2735 image sensor driver
From: Andy Shevchenko
Date: Mon Jul 21 2025 - 13:22:17 EST
On Thu, Jul 17, 2025 at 01:11:53PM +0000, Hardevsinh Palaniya wrote:
> > On Thu, Jul 17, 2025 at 07:26:49AM +0000, Hardevsinh Palaniya wrote:
> > > > On Wed, Jul 16, 2025 at 07:14:17PM +0530, Hardevsinh Palaniya wrote:
...
> > > > > +static int ov2735_page_access(struct ov2735 *ov2735,
> > > > > + u32 reg, void *val, int *err, bool is_read)
> > > > > +{
> > > > > + u8 page = (reg >> CCI_REG_PRIVATE_SHIFT) & 0xff;
> > > > > + u32 addr = reg & ~CCI_REG_PRIVATE_MASK;
> > > > > + int ret = 0;
> > > > > + if (err && *err)
> > > > > + return *err;
^^^ (1)
> > > > > + mutex_lock(&ov2735->page_lock);
> > > > > +
> > > > > + /* Perform page access before read/write */
> > > > > + if (ov2735->current_page != page) {
> > > > > + ret = cci_write(ov2735->cci, OV2735_REG_PAGE_SELECT, page, &ret);
> > > > > + if (ret)
> > > > > + goto err_mutex_unlock;
> > > > > + ov2735->current_page = page;
> > > > > + }
> > > > > +
> > > > > + if (is_read)
> > > > > + ret = cci_read(ov2735->cci, addr, (u64 *)val, err);
> > > > > + else
> > > > > + ret = cci_write(ov2735->cci, addr, *(u64 *)val, err);
> > > > > +
> > > > > +err_mutex_unlock:
> > > >
> > > > > + if (ret && err)
> > > >
> > > > Why do you need to check for ret != 0?
> > >
> > > To prevents overwriting *err with 0 on successful operations, which could
> > > obscure previous errors.
> >
> > Can you elaborate a bit how the *err is not 0 at this point
> > (assuming err != NULL)?
>
> A previous operation have already failed and stored a non-
> zero error code in *err.
Right and this function is no-op already for this case.
> Assuming this function is used in a sequence of write (or read)
> operations. If the current operation succeeds (i.e., ret == 0) and we
> unconditionally write *err = ret, we would overwrite the
> existing error with 0, falsely indicating that all operations
> were successful.
I don't see this scenario. I see that we apply *err = 0 when *err == 0 already.
> Therefore, the condition if (ret && err) ensures that we only
> update *err when there's a new error, preserving any previously
> recorded failures.
>
> Let me know if you have a different suggestion for how this should
> be handled.
Have you taken into account 1) above?
--
With Best Regards,
Andy Shevchenko