drivers/iio/adc/pac1934.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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
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
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 > > ? >
© 2016 - 2025 Red Hat, Inc.