Skip to content

Commit 50b6cb3

Browse files
dcuimartinkpetersen
authored andcommitted
scsi: core: Fix shost->cmd_per_lun calculation in scsi_add_host_with_dma()
After commit ea2f0f7 ("scsi: core: Cap scsi_host cmd_per_lun at can_queue"), a 416-CPU VM running on Hyper-V hangs during boot because the hv_storvsc driver sets scsi_driver.can_queue to an integer value that exceeds SHRT_MAX, and hence scsi_add_host_with_dma() sets shost->cmd_per_lun to a negative "short" value. Use min_t(int, ...) to work around the issue. Link: https://lore.kernel.org/r/[email protected] Fixes: ea2f0f7 ("scsi: core: Cap scsi_host cmd_per_lun at can_queue") Cc: [email protected] Reviewed-by: Haiyang Zhang <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: John Garry <[email protected]> Signed-off-by: Dexuan Cui <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 258aad7 commit 50b6cb3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/hosts.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
220220
goto fail;
221221
}
222222

223-
shost->cmd_per_lun = min_t(short, shost->cmd_per_lun,
223+
/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */
224+
shost->cmd_per_lun = min_t(int, shost->cmd_per_lun,
224225
shost->can_queue);
225226

226227
error = scsi_init_sense_cache(shost);

0 commit comments

Comments
 (0)