* [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot
@ 2025-12-02 18:13 Thorsten Blum
2025-12-02 18:47 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2025-12-02 18:13 UTC (permalink / raw)
To: Marius Cristea, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko
Cc: Thorsten Blum, stable, Jonathan Cameron, linux-iio, linux-kernel
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'.
Cc: stable@vger.kernel.org
Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/iio/adc/pac1934.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index 48df16509260..256488d3936b 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -665,7 +665,8 @@ static int pac1934_reg_snapshot(struct pac1934_chip_info *info,
/* 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;
}
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot
2025-12-02 18:13 [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot Thorsten Blum
@ 2025-12-02 18:47 ` Andy Shevchenko
2025-12-07 13:46 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2025-12-02 18:47 UTC (permalink / raw)
To: Thorsten Blum
Cc: Marius Cristea, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, stable, Jonathan Cameron, linux-iio,
linux-kernel
On Tue, Dec 2, 2025 at 8:13 PM Thorsten Blum <thorsten.blum@linux.dev> 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);
?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot
2025-12-02 18:47 ` Andy Shevchenko
@ 2025-12-07 13:46 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-12-07 13:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Thorsten Blum, Marius Cristea, David Lechner, Nuno Sá,
Andy Shevchenko, stable, Jonathan Cameron, linux-iio,
linux-kernel
On Tue, 2 Dec 2025 20:47:37 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Tue, Dec 2, 2025 at 8:13 PM Thorsten Blum <thorsten.blum@linux.dev> 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
>
> ?
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-07 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 18:13 [PATCH] iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot Thorsten Blum
2025-12-02 18:47 ` Andy Shevchenko
2025-12-07 13:46 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox