Skip to content

Commit

Permalink
iio: invensense: fix interrupt timestamp alignment
Browse files Browse the repository at this point in the history
commit 0340dc4 upstream.

Restrict interrupt timestamp alignment for not overflowing max/min
period thresholds.

Fixes: 0ecc363 ("iio: make invensense timestamp module generic")
Cc: stable@vger.kernel.org
Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Link: https://lore.kernel.org/r/20240426135814.141837-1-inv.git-commit@tdk.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
jmaneyrol-invn authored and gregkh committed Jun 21, 2024
1 parent c70cc82 commit 6cb5c18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,23 @@ static bool inv_update_chip_period(struct inv_sensors_timestamp *ts,

static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts)
{
const int64_t period_min = ts->min_period * ts->mult;
const int64_t period_max = ts->max_period * ts->mult;
int64_t add_max, sub_max;
int64_t delta, jitter;
int64_t adjust;

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

/* adjust timestamp while respecting jitter */
add_max = period_max - (int64_t)ts->period;
sub_max = period_min - (int64_t)ts->period;
jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter);
if (delta > jitter)
adjust = jitter;
adjust = add_max;
else if (delta < -jitter)
adjust = -jitter;
adjust = sub_max;
else
adjust = 0;

Expand Down

0 comments on commit 6cb5c18

Please sign in to comment.