mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iio: imu: use min() to improve code
@ 2025-08-16 12:05 Qianfeng Rong
  2025-08-16 16:56 ` David Lechner
  0 siblings, 1 reply; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-16 12:05 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol, Jonathan Cameron, David Lechner,
	Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel
  Cc: Qianfeng Rong

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>
---
v2: Remove the redundant variable and comment as suggested by David.
---
 .../imu/inv_icm42600/inv_icm42600_buffer.c    | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
index 7c4ed981db04..ca744aaee542 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
@@ -5,6 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/device.h>
+#include <linux/minmax.h>
 #include <linux/mutex.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
@@ -100,7 +101,7 @@ ssize_t inv_icm42600_fifo_decode_packet(const void *packet, const void **accel,
 
 void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st)
 {
-	u32 period_gyro, period_accel, period;
+	u32 period_gyro, period_accel;
 
 	if (st->fifo.en & INV_ICM42600_SENSOR_GYRO)
 		period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr);
@@ -112,12 +113,7 @@ void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st)
 	else
 		period_accel = U32_MAX;
 
-	if (period_gyro <= period_accel)
-		period = period_gyro;
-	else
-		period = period_accel;
-
-	st->fifo.period = period;
+	st->fifo.period = min(period_gyro, period_accel);
 }
 
 int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
@@ -204,7 +200,7 @@ int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st)
 {
 	size_t packet_size, wm_size;
 	unsigned int wm_gyro, wm_accel, watermark;
-	u32 period_gyro, period_accel, period;
+	u32 period_gyro, period_accel;
 	u32 latency_gyro, latency_accel, latency;
 	bool restore;
 	__le16 raw_wm;
@@ -237,13 +233,8 @@ int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st)
 			latency = latency_gyro - (latency_accel % latency_gyro);
 		else
 			latency = latency_accel - (latency_gyro % latency_accel);
-		/* use the shortest period */
-		if (period_gyro <= period_accel)
-			period = period_gyro;
-		else
-			period = period_accel;
 		/* all this works because periods are multiple of each others */
-		watermark = latency / period;
+		watermark = latency / min(period_gyro, period_accel);
 		if (watermark < 1)
 			watermark = 1;
 		/* update effective watermark */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: imu: use min() to improve code
  2025-08-16 12:05 [PATCH v2] iio: imu: use min() to improve code Qianfeng Rong
@ 2025-08-16 16:56 ` David Lechner
  2025-08-17 14:30   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2025-08-16 16:56 UTC (permalink / raw)
  To: Qianfeng Rong, Jean-Baptiste Maneyrol, Jonathan Cameron,
	Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On 8/16/25 7:05 AM, Qianfeng Rong wrote:
> 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>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: imu: use min() to improve code
  2025-08-16 16:56 ` David Lechner
@ 2025-08-17 14:30   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-08-17 14:30 UTC (permalink / raw)
  To: David Lechner
  Cc: Qianfeng Rong, Jean-Baptiste Maneyrol, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Sat, 16 Aug 2025 11:56:24 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 8/16/25 7:05 AM, Qianfeng Rong wrote:
> > 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>
> 
Applied with tweak to patch title to include inv_icm42600.
When people are deciding whether to look at a patch or not
having info on what driver it applies to is always useful.

Jonathan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-17 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-16 12:05 [PATCH v2] iio: imu: use min() to improve code Qianfeng Rong
2025-08-16 16:56 ` David Lechner
2025-08-17 14:30   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®