Unverified Commit e29aca70 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Mark Brown
Browse files

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarDavid Laight <david.laight.linux@gmail.com>
Reviewed-by: default avatarPrajna Rajendra Kumar <prajna.rajendrakumar@microchip.com>
Link: https://patch.msgid.link/20251126075558.2035012-2-andriy.shevchenko@linux.intel.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 625f43be
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -74,8 +74,8 @@ struct mchp_corespi {
	u8 *rx_buf;
	u32 clk_gen;
	int irq;
	int tx_len;
	int rx_len;
	unsigned int tx_len;
	unsigned int rx_len;
	u32 fifo_depth;
};

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

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

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

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

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