Re: [PATCH 26/44] drivers/scsi: use min() instead of min_t()
From: Bart Van Assche
Date: Wed Nov 19 2025 - 18:09:17 EST
On 11/19/25 2:41 PM, david.laight.linux@xxxxxxxxx wrote:
From: David Laight <david.laight.linux@xxxxxxxxx>
min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'.
Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long'
and so cannot discard significant bits.
In this case the 'unsigned long' value is small enough that the result
is ok.
Detected by an extra check added to min_t().
Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
drivers/scsi/hosts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 17173239301e..b15896560cf6 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -247,7 +247,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
shost->dma_dev = dma_dev;
if (dma_dev->dma_mask) {
- shost->max_sectors = min_t(unsigned int, shost->max_sectors,
+ shost->max_sectors = min(shost->max_sectors,
dma_max_mapping_size(dma_dev) >> SECTOR_SHIFT);
}
So instead of the type cast performed by min_t() potentially discarding
bits, the assignment potentially discards bits. I'm not sure this is an
improvement.
Thanks,
Bart.