[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250702-iio-imu-adis16550-rework-clock-range-test-v1-1-b45f3a3b0dc1@baylibre.com>
Date: Wed, 02 Jul 2025 09:27:45 -0500
From: David Lechner <dlechner@...libre.com>
To: Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
Robert Budai <robert.budai@...log.com>, Andy Shevchenko <andy@...nel.org>
Cc: linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
David Lechner <dlechner@...libre.com>
Subject: [PATCH] iio: imu: adis16550: rework clock range test
Rework the clock rate range test to test if sync_mode_data != NULL
instead of testing if the for loop index variable. This makes it easier
for static analyzers to see that we aren't using an uninitialized
sync_mode_data [1].
Link: https://github.com/analogdevicesinc/linux/pull/2831/files#diff-e60c8024905ba921f6aac624cae67d6f9bd54aa5af5a27ae60a8ca21ef120ddaR950 [1]
Signed-off-by: David Lechner <dlechner@...libre.com>
---
Here is the for loop that comes just before the if statement in the
patch so reviewers don't have to look it up:
for (i = 0; i < st->info->num_sync; i++) {
if (st->clk_freq_hz >= st->info->sync_mode[i].min_rate &&
st->clk_freq_hz <= st->info->sync_mode[i].max_rate) {
sync_mode_data = &st->info->sync_mode[i];
break;
}
}
Previously, we were using the index variable `i` to check if we hit
the break or not, but checking if sync_mode_data was assigned is a bit
more straight-forward for machines (and probably some humans too).
---
drivers/iio/imu/adis16550.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/imu/adis16550.c b/drivers/iio/imu/adis16550.c
index 28f0dbd0226cbea67bc6c87d892f7812f21e9304..d733daaa05bcf0b0cfd710330230c671e66feef4 100644
--- a/drivers/iio/imu/adis16550.c
+++ b/drivers/iio/imu/adis16550.c
@@ -909,7 +909,7 @@ static int adis16550_reset(struct adis *adis)
static int adis16550_config_sync(struct adis16550 *st)
{
struct device *dev = &st->adis.spi->dev;
- const struct adis16550_sync *sync_mode_data;
+ const struct adis16550_sync *sync_mode_data = NULL;
struct clk *clk;
int ret, i;
u16 mode;
@@ -932,7 +932,7 @@ static int adis16550_config_sync(struct adis16550 *st)
}
}
- if (i == st->info->num_sync)
+ if (!sync_mode_data)
return dev_err_probe(dev, -EINVAL, "Clk rate: %lu not in a valid range",
st->clk_freq_hz);
---
base-commit: 6742eff60460e77158d4f1b233f17e0345c9e66a
change-id: 20250702-iio-imu-adis16550-rework-clock-range-test-63816e60586d
Best regards,
--
David Lechner <dlechner@...libre.com>
Powered by blists - more mailing lists