Skip to content

Commit 6ee0c84

Browse files
jmaneyrol-invngregkh
authored andcommitted
iio: invensense: fix interrupt timestamp alignment
commit 0340dc4 upstream. Restrict interrupt timestamp alignment for not overflowing max/min period thresholds. Fixes: 0ecc363 ("iio: make invensense timestamp module generic") Cc: [email protected] Signed-off-by: Jean-Baptiste Maneyrol <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 955c824 commit 6ee0c84

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/iio/common/inv_sensors/inv_sensors_timestamp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,23 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,
105105

106106
static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
107107
{
108+
const int64_t period_min = ts->min_period * ts->mult;
109+
const int64_t period_max = ts->max_period * ts->mult;
110+
int64_t add_max, sub_max;
108111
int64_t delta, jitter;
109112
int64_t adjust;
110113

111114
/* delta time between last sample and last interrupt */
112115
delta = ts->it.lo - ts->timestamp;
113116

114117
/* adjust timestamp while respecting jitter */
118+
add_max = period_max - (int64_t)ts->period;
119+
sub_max = period_min - (int64_t)ts->period;
115120
jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
116121
if (delta > jitter)
117-
adjust = jitter;
122+
adjust = add_max;
118123
else if (delta < -jitter)
119-
adjust = -jitter;
124+
adjust = sub_max;
120125
else
121126
adjust = 0;
122127

0 commit comments

Comments
 (0)