Skip to content

Commit a9320f3

Browse files
qianfengrongAndi Shyti
authored andcommitted
i2c: st: Use min() to improve code
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 <[email protected]> Reviewed-by: Patrice Chotard <[email protected]> Signed-off-by: Andi Shyti <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 07e0e8e commit a9320f3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

drivers/i2c/busses/i2c-st.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/i2c.h>
1414
#include <linux/interrupt.h>
1515
#include <linux/io.h>
16+
#include <linux/minmax.h>
1617
#include <linux/module.h>
1718
#include <linux/of_address.h>
1819
#include <linux/of_irq.h>
@@ -422,12 +423,8 @@ static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
422423
tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
423424
tx_fstat &= SSC_TX_FSTAT_STATUS;
424425

425-
if (c->count < (SSC_TXFIFO_SIZE - tx_fstat))
426-
i = c->count;
427-
else
428-
i = SSC_TXFIFO_SIZE - tx_fstat;
429-
430-
for (; i > 0; i--, c->count--, c->buf++)
426+
for (i = min(c->count, SSC_TXFIFO_SIZE - tx_fstat);
427+
i > 0; i--, c->count--, c->buf++)
431428
st_i2c_write_tx_fifo(i2c_dev, *c->buf);
432429
}
433430

@@ -439,7 +436,7 @@ static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
439436
* This functions fills the Tx FIFO with fixed pattern when
440437
* in read mode to trigger clock.
441438
*/
442-
static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
439+
static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, u32 max)
443440
{
444441
struct st_i2c_client *c = &i2c_dev->client;
445442
u32 tx_fstat, sta;
@@ -452,12 +449,8 @@ static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
452449
tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
453450
tx_fstat &= SSC_TX_FSTAT_STATUS;
454451

455-
if (max < (SSC_TXFIFO_SIZE - tx_fstat))
456-
i = max;
457-
else
458-
i = SSC_TXFIFO_SIZE - tx_fstat;
459-
460-
for (; i > 0; i--, c->xfered++)
452+
for (i = min(max, SSC_TXFIFO_SIZE - tx_fstat);
453+
i > 0; i--, c->xfered++)
461454
st_i2c_write_tx_fifo(i2c_dev, 0xff);
462455
}
463456

0 commit comments

Comments
 (0)