Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: myrs: Fix dma_alloc_coherent() error check

Check for NULL return value with dma_alloc_coherent(), because DMA
address is not always set by dma_alloc_coherent() on failure.

Fixes: 77266186397c ("scsi: myrs: Add Mylex RAID controller (SCSI interface)")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Link: https://lore.kernel.org/r/20250725083112.43975-2-fourier.thomas@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Thomas Fourier and committed by
Martin K. Petersen
edb35b1f e79aa10e

+4 -4
+4 -4
drivers/scsi/myrs.c
··· 498 498 /* Temporary dma mapping, used only in the scope of this function */ 499 499 mbox = dma_alloc_coherent(&pdev->dev, sizeof(union myrs_cmd_mbox), 500 500 &mbox_addr, GFP_KERNEL); 501 - if (dma_mapping_error(&pdev->dev, mbox_addr)) 501 + if (!mbox) 502 502 return false; 503 503 504 504 /* These are the base addresses for the command memory mailbox array */ 505 505 cs->cmd_mbox_size = MYRS_MAX_CMD_MBOX * sizeof(union myrs_cmd_mbox); 506 506 cmd_mbox = dma_alloc_coherent(&pdev->dev, cs->cmd_mbox_size, 507 507 &cs->cmd_mbox_addr, GFP_KERNEL); 508 - if (dma_mapping_error(&pdev->dev, cs->cmd_mbox_addr)) { 508 + if (!cmd_mbox) { 509 509 dev_err(&pdev->dev, "Failed to map command mailbox\n"); 510 510 goto out_free; 511 511 } ··· 520 520 cs->stat_mbox_size = MYRS_MAX_STAT_MBOX * sizeof(struct myrs_stat_mbox); 521 521 stat_mbox = dma_alloc_coherent(&pdev->dev, cs->stat_mbox_size, 522 522 &cs->stat_mbox_addr, GFP_KERNEL); 523 - if (dma_mapping_error(&pdev->dev, cs->stat_mbox_addr)) { 523 + if (!stat_mbox) { 524 524 dev_err(&pdev->dev, "Failed to map status mailbox\n"); 525 525 goto out_free; 526 526 } ··· 533 533 cs->fwstat_buf = dma_alloc_coherent(&pdev->dev, 534 534 sizeof(struct myrs_fwstat), 535 535 &cs->fwstat_addr, GFP_KERNEL); 536 - if (dma_mapping_error(&pdev->dev, cs->fwstat_addr)) { 536 + if (!cs->fwstat_buf) { 537 537 dev_err(&pdev->dev, "Failed to map firmware health buffer\n"); 538 538 cs->fwstat_buf = NULL; 539 539 goto out_free;