[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250619142609.323082-1-rongqianfeng@vivo.com>
Date: Thu, 19 Jun 2025 22:26:09 +0800
From: Qianfeng Rong <rongqianfeng@...o.com>
To: Patrice Chotard <patrice.chotard@...s.st.com>,
Andi Shyti <andi.shyti@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
linux-i2c@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: opensource.kernel@...o.com,
Qianfeng Rong <rongqianfeng@...o.com>
Subject: [PATCH] i2c: busses: Use min() to improve code
Use min() to reduce the code and improve its readability.
Signed-off-by: Qianfeng Rong <rongqianfeng@...o.com>
---
drivers/i2c/busses/i2c-st.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
index 750fff3d2389..3373a828b5a0 100644
--- a/drivers/i2c/busses/i2c-st.c
+++ b/drivers/i2c/busses/i2c-st.c
@@ -19,6 +19,7 @@
#include <linux/of.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
+#include <linux/minmax.h>
/* SSC registers */
#define SSC_BRG 0x000
@@ -422,10 +423,7 @@ static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
tx_fstat &= SSC_TX_FSTAT_STATUS;
- if (c->count < (SSC_TXFIFO_SIZE - tx_fstat))
- i = c->count;
- else
- i = SSC_TXFIFO_SIZE - tx_fstat;
+ i = min(c->count, SSC_TXFIFO_SIZE - tx_fstat);
for (; i > 0; i--, c->count--, c->buf++)
st_i2c_write_tx_fifo(i2c_dev, *c->buf);
@@ -452,10 +450,7 @@ static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
tx_fstat &= SSC_TX_FSTAT_STATUS;
- if (max < (SSC_TXFIFO_SIZE - tx_fstat))
- i = max;
- else
- i = SSC_TXFIFO_SIZE - tx_fstat;
+ i = min(max, SSC_TXFIFO_SIZE - tx_fstat);
for (; i > 0; i--, c->xfered++)
st_i2c_write_tx_fifo(i2c_dev, 0xff);
--
2.34.1
Powered by blists - more mailing lists