Skip to contentSkip to conversation

iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot

PATCH Applied Thorsten Blum 3 participants 3 messages Dec 2, 2025 – Dec 7, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: PAC1934: Fix clamped value in pac1934_reg_snapshot

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'.

Fixes 0fb528c8255b ("iio: adc: adding support for PAC193x")
---
 drivers/iio/adc/pac1934.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/pac1934.c +2 -1
index 48df16509260..256488d3936b 100644
@@ -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;
 		}
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#1 lore raw
Quoted 5 lines · Thorsten Blum

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'.

...

drivers/iio/adc/pac1934.c static int pac1934_reg_snapshot(struct pac1934_chip_info *info, · line 671

Quoted 8 lines
                        /* add the power_acc field */
                        curr_energy += inc;
drivers/iio/adc/pac1934.c +2 -1
-                       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);

?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#2 lore raw
Quoted 16 lines · On Tue, 2 Dec 2025 20:47:37 +0200 Andy Shevchenko <[email protected]>…
Quoted 5 lines · Thorsten Blum

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'.

...

Quoted 7 lines
                        /* add the power_acc field */
                        curr_energy += inc;
drivers/iio/adc/pac1934.c +2 -1
-                       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);
Quoted 7 lines
Quoted 1 line
                        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

Quoted 3 lines

?