Commit 1b5d9a6e98350e0713b4faa1b04e8f239f63b581

Authored by Christoph Hellwig
Committed by Martin K. Petersen
1 parent e70bdd81bf

scsi: core: fix the dma_max_mapping_size call

We should only call dma_max_mapping_size for devices that have a DMA mask
set, otherwise we can run into a NULL pointer dereference that will crash
the system.

Also we need to do right shift to get the sectors from the size in bytes,
not a left shift.

Fixes: bdd17bdef7d8 ("scsi: core: take the DMA max mapping size into account")
Reported-by: Bart Van Assche <bvanassche@acm.org>
Reported-by: Ming Lei <tom.leiming@gmail.com>
Tested-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Showing 1 changed file with 4 additions and 2 deletions Side-by-side Diff

drivers/scsi/scsi_lib.c
... ... @@ -1784,8 +1784,10 @@
1784 1784 blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize);
1785 1785 }
1786 1786  
1787   - shost->max_sectors = min_t(unsigned int, shost->max_sectors,
1788   - dma_max_mapping_size(dev) << SECTOR_SHIFT);
  1787 + if (dev->dma_mask) {
  1788 + shost->max_sectors = min_t(unsigned int, shost->max_sectors,
  1789 + dma_max_mapping_size(dev) >> SECTOR_SHIFT);
  1790 + }
1789 1791 blk_queue_max_hw_sectors(q, shost->max_sectors);
1790 1792 if (shost->unchecked_isa_dma)
1791 1793 blk_queue_bounce_limit(q, BLK_BOUNCE_ISA);