From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: <wsa+renesas@sang-engineering.com>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Andi Shyti <andi.shyti@kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<opensource.kernel@vivo.com>
Subject: Re: [PATCH v3] i2c: busses: Use min() to improve code
Date: Tue, 8 Jul 2025 12:06:58 +0100 [thread overview]
Message-ID: <20250708120658.0000668a@huawei.com> (raw)
In-Reply-To: <20250708031520.365110-1-rongqianfeng@vivo.com>
On Tue, 8 Jul 2025 11:15:20 +0800
Qianfeng Rong <rongqianfeng@vivo.com> wrote:
> Use min() to reduce the code and improve its readability.
>
> The type of the max parameter in the st_i2c_rd_fill_tx_fifo()
> was changed from int to u32, because the max parameter passed
> in is always greater than 0.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> ---
> v2-> v3:
> - added the <linux/minmax.h> as suggested by Jonathan.
> - used i = min(...) as the loop initializer according
> to Jonathan.
>
> v1-> v2:
> - Change the max parameter type in st_i2c_rd_fill_tx_fifo()
> from int to u32
> ---
> drivers/i2c/busses/i2c-st.c | 19 ++++++-------------
> 1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
> index 750fff3d2389..e4b2ed8a9264 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,12 +423,8 @@ 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;
> -
> - for (; i > 0; i--, c->count--, c->buf++)
> + for (i = min(c->count, SSC_TXFIFO_SIZE - tx_fstat);
> + i > 0; i--, c->count--, c->buf++)
for (i = min(c->count, SSC_TXFIFO_SIZE - tx_fstat);
i > 0; i--, c->count--, c->buf++)
st_i2c_write_tx_fifo(i2c_dev, *c->buf);
So different alignment form what you have.
> st_i2c_write_tx_fifo(i2c_dev, *c->buf);
> }
>
> @@ -439,7 +436,7 @@ static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
> * This functions fills the Tx FIFO with fixed pattern when
> * in read mode to trigger clock.
> */
> -static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
> +static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, u32 max)
> {
> struct st_i2c_client *c = &i2c_dev->client;
> u32 tx_fstat, sta;
> @@ -452,12 +449,8 @@ 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;
> -
> - for (; i > 0; i--, c->xfered++)
> + for (i = min(max, SSC_TXFIFO_SIZE - tx_fstat);
> + i > 0; i--, c->xfered++)
> st_i2c_write_tx_fifo(i2c_dev, 0xff);
> }
>
next prev parent reply other threads:[~2025-07-08 11:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 3:15 [PATCH v3] i2c: busses: Use min() to improve code Qianfeng Rong
2025-07-08 11:06 ` Jonathan Cameron [this message]
2025-07-09 2:44 ` Qianfeng Rong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250708120658.0000668a@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=andi.shyti@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
--cc=patrice.chotard@foss.st.com \
--cc=rongqianfeng@vivo.com \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.