Skip to content

Commit e29aca7

Browse files
andy-shevbroonie
authored andcommitted
spi: microchip-core: use min() instead of min_t()
min_t(int, a, b) casts an 'unsigned int' to 'int'. This might lead to the cases when big number is wrongly chosen. On the other hand, the SPI transfer length is unsigned and driver uses signed type for an unknown reason. Change the type of the transfer length to be unsigned and convert use min() instead of min_t(). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: David Laight <david.laight.linux@gmail.com> Reviewed-by: Prajna Rajendra Kumar <prajna.rajendrakumar@microchip.com> Link: https://patch.msgid.link/20251126075558.2035012-2-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 625f43b commit e29aca7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/spi/spi-microchip-core-spi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ struct mchp_corespi {
7474
u8 *rx_buf;
7575
u32 clk_gen;
7676
int irq;
77-
int tx_len;
78-
int rx_len;
77+
unsigned int tx_len;
78+
unsigned int rx_len;
7979
u32 fifo_depth;
8080
};
8181

@@ -214,7 +214,7 @@ static irqreturn_t mchp_corespi_interrupt(int irq, void *dev_id)
214214
spi->regs + MCHP_CORESPI_REG_INTCLEAR);
215215
finalise = true;
216216
dev_err(&host->dev,
217-
"RX OVERFLOW: rxlen: %d, txlen: %d\n",
217+
"RX OVERFLOW: rxlen: %u, txlen: %u\n",
218218
spi->rx_len, spi->tx_len);
219219
}
220220

@@ -223,7 +223,7 @@ static irqreturn_t mchp_corespi_interrupt(int irq, void *dev_id)
223223
spi->regs + MCHP_CORESPI_REG_INTCLEAR);
224224
finalise = true;
225225
dev_err(&host->dev,
226-
"TX UNDERFLOW: rxlen: %d, txlen: %d\n",
226+
"TX UNDERFLOW: rxlen: %u, txlen: %u\n",
227227
spi->rx_len, spi->tx_len);
228228
}
229229

@@ -283,7 +283,7 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
283283
spi->rx_len = xfer->len;
284284

285285
while (spi->tx_len) {
286-
int fifo_max = min_t(int, spi->tx_len, spi->fifo_depth);
286+
unsigned int fifo_max = min(spi->tx_len, spi->fifo_depth);
287287

288288
mchp_corespi_write_fifo(spi, fifo_max);
289289
mchp_corespi_read_fifo(spi, fifo_max);

0 commit comments

Comments
 (0)