Skip to content

Commit 0340dc4

Browse files
jmaneyrol-invnjic23
authored andcommitted
iio: invensense: fix interrupt timestamp alignment
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]>
1 parent 561e2e3 commit 0340dc4

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
@@ -101,18 +101,23 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,
101101

102102
static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
103103
{
104+
const int64_t period_min = ts->min_period * ts->mult;
105+
const int64_t period_max = ts->max_period * ts->mult;
106+
int64_t add_max, sub_max;
104107
int64_t delta, jitter;
105108
int64_t adjust;
106109

107110
/* delta time between last sample and last interrupt */
108111
delta = ts->it.lo - ts->timestamp;
109112

110113
/* adjust timestamp while respecting jitter */
114+
add_max = period_max - (int64_t)ts->period;
115+
sub_max = period_min - (int64_t)ts->period;
111116
jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
112117
if (delta > jitter)
113-
adjust = jitter;
118+
adjust = add_max;
114119
else if (delta < -jitter)
115-
adjust = -jitter;
120+
adjust = sub_max;
116121
else
117122
adjust = 0;
118123

0 commit comments

Comments
 (0)