Re: [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot
From: Jonathan Cameron
Date: Sun Dec 07 2025 - 08:46:08 EST
On Tue, 2 Dec 2025 20:47:37 +0200
Andy Shevchenko <andy.shevchenko@xxxxxxxxx> wrote:
> On Tue, Dec 2, 2025 at 8:13 PM Thorsten Blum <thorsten.blum@xxxxxxxxx> wrote:
> >
> > The local variable 'curr_energy' was never clamped to
> > PAC_193X_MIN_POWER_ACC or PAC_193X_MAX_POWER_ACC because the return
> > value of clamp() was not used. Fix this by assigning the clamped value
> > back to 'curr_energy'.
>
> ...
>
> > /* add the power_acc field */
> > curr_energy += inc;
> >
> > - clamp(curr_energy, PAC_193X_MIN_POWER_ACC, PAC_193X_MAX_POWER_ACC);
> > + curr_energy = clamp(curr_energy, PAC_193X_MIN_POWER_ACC,
> > + PAC_193X_MAX_POWER_ACC);
> >
> > reg_data->energy_sec_acc[cnt] = curr_energy;
>
> Hmm... Maybe
>
> reg_data->energy_sec_acc[cnt] = clamp(curr_energy,
> PAC_193X_MIN_POWER_ACC,
> PAC_193X_MAX_POWER_ACC);
I went with aligning after ( and slightly longer than 80 char lines.
other combinations didn't seem to read quite as well to me.
Applied to the fixes-togreg branch of iio.git. I'll probably sit on pushing
that out until I can rebase on rc1 however.
Jonathan
>
> ?
>