Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: imu: inv_icm42600: use min() to improve code

Use min() to reduce code in inv_icm42600_buffer_update_fifo_period()
and inv_icm42600_buffer_update_watermark(), and improve readability.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250816120510.355835-1-rongqianfeng@vivo.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Qianfeng Rong and committed by
Jonathan Cameron
35e3d0cd 1ab10737

+5 -14
+5 -14
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
··· 5 5 6 6 #include <linux/kernel.h> 7 7 #include <linux/device.h> 8 + #include <linux/minmax.h> 8 9 #include <linux/mutex.h> 9 10 #include <linux/pm_runtime.h> 10 11 #include <linux/regmap.h> ··· 101 100 102 101 void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st) 103 102 { 104 - u32 period_gyro, period_accel, period; 103 + u32 period_gyro, period_accel; 105 104 106 105 if (st->fifo.en & INV_ICM42600_SENSOR_GYRO) 107 106 period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr); ··· 113 112 else 114 113 period_accel = U32_MAX; 115 114 116 - if (period_gyro <= period_accel) 117 - period = period_gyro; 118 - else 119 - period = period_accel; 120 - 121 - st->fifo.period = period; 115 + st->fifo.period = min(period_gyro, period_accel); 122 116 } 123 117 124 118 int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st, ··· 200 204 { 201 205 size_t packet_size, wm_size; 202 206 unsigned int wm_gyro, wm_accel, watermark; 203 - u32 period_gyro, period_accel, period; 207 + u32 period_gyro, period_accel; 204 208 u32 latency_gyro, latency_accel, latency; 205 209 bool restore; 206 210 __le16 raw_wm; ··· 233 237 latency = latency_gyro - (latency_accel % latency_gyro); 234 238 else 235 239 latency = latency_accel - (latency_gyro % latency_accel); 236 - /* use the shortest period */ 237 - if (period_gyro <= period_accel) 238 - period = period_gyro; 239 - else 240 - period = period_accel; 241 240 /* all this works because periods are multiple of each others */ 242 - watermark = latency / period; 241 + watermark = latency / min(period_gyro, period_accel); 243 242 if (watermark < 1) 244 243 watermark = 1; 245 244 /* update effective watermark */