* [PATCH] i2c: busses: Use min() to improve code
@ 2025-06-19 14:26 Qianfeng Rong
2025-07-03 18:11 ` Andi Shyti
2025-07-04 13:08 ` Patrice CHOTARD
0 siblings, 2 replies; 3+ messages in thread
From: Qianfeng Rong @ 2025-06-19 14:26 UTC (permalink / raw)
To: Patrice Chotard, Andi Shyti, linux-arm-kernel, linux-i2c,
linux-kernel
Cc: opensource.kernel, Qianfeng Rong
Use min() to reduce the code and improve its readability.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: busses: Use min() to improve code
2025-06-19 14:26 [PATCH] i2c: busses: Use min() to improve code Qianfeng Rong
@ 2025-07-03 18:11 ` Andi Shyti
2025-07-04 13:08 ` Patrice CHOTARD
1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2025-07-03 18:11 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Patrice Chotard, linux-arm-kernel, linux-i2c, linux-kernel,
opensource.kernel
Hi Qianfeng,
> @@ -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);
I think it's safe enough not to need a min_t(int,...
merged to i2c/i2c-host.
Thanks,
Andi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: busses: Use min() to improve code
2025-06-19 14:26 [PATCH] i2c: busses: Use min() to improve code Qianfeng Rong
2025-07-03 18:11 ` Andi Shyti
@ 2025-07-04 13:08 ` Patrice CHOTARD
1 sibling, 0 replies; 3+ messages in thread
From: Patrice CHOTARD @ 2025-07-04 13:08 UTC (permalink / raw)
To: Qianfeng Rong, Andi Shyti, linux-arm-kernel, linux-i2c,
linux-kernel
Cc: opensource.kernel
On 6/19/25 16:26, Qianfeng Rong wrote:
> Use min() to reduce the code and improve its readability.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.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);
Hi Qianfeng
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
Patrice
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-04 13:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-19 14:26 [PATCH] i2c: busses: Use min() to improve code Qianfeng Rong
2025-07-03 18:11 ` Andi Shyti
2025-07-04 13:08 ` Patrice CHOTARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).