scsi: mvumi: use sg helper to iterate over scatterlist [Linux 5.3]

This Linux kernel change "scsi: mvumi: use sg helper to iterate over scatterlist" is included in the Linux 5.3 release. This change is authored by Ming Lei <ming.lei [at]> on Tue Jun 18 09:37:45 2019 +0800. The commit for this change in Linux stable tree is 3c1a30d (patch).

scsi: mvumi: use sg helper to iterate over scatterlist

Unlike the legacy I/O path, scsi-mq preallocates a large array to hold
the scatterlist for each request. This static allocation can consume
substantial amounts of memory on modern controllers which support a
large number of concurrently outstanding requests.

To facilitate a switch to a smaller static allocation combined with a
dynamic allocation for requests that need it, we need to make sure all
SCSI drivers handle chained scatterlists correctly.

Convert remaining drivers that directly dereference the scatterlist
array to using the iterator functions.

[mkp: clarified commit message and folded in build fix reported by zeroday]

Reviewed-by: Christoph Hellwig <>
Reviewed-by: Bart Van Assche <>
Reviewed-by: Ewan D. Milne <>
Signed-off-by: Ming Lei <>
Signed-off-by: Martin K. Petersen <>

There are 11 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/scsi/mvumi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index a541061..53f3563 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -211,23 +211,22 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
    unsigned int sgnum = scsi_sg_count(scmd);
    dma_addr_t busaddr;

-   sg = scsi_sglist(scmd);
-   *sg_count = dma_map_sg(&mhba->pdev->dev, sg, sgnum,
+   *sg_count = dma_map_sg(&mhba->pdev->dev, scsi_sglist(scmd), sgnum,
    if (*sg_count > mhba->max_sge) {
            "sg count[0x%x] is bigger than max sg[0x%x].\n",
            *sg_count, mhba->max_sge);
-       dma_unmap_sg(&mhba->pdev->dev, sg, sgnum,
+       dma_unmap_sg(&mhba->pdev->dev, scsi_sglist(scmd), sgnum,
        return -1;
-   for (i = 0; i < *sg_count; i++) {
-       busaddr = sg_dma_address(&sg[i]);
+   scsi_for_each_sg(scmd, sg, *sg_count, i) {
+       busaddr = sg_dma_address(sg);
        m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
        m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
        m_sg->flags = 0;
-       sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
+       sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(sg)));
        if ((i + 1) == *sg_count)
            m_sg->flags |= 1U << mhba->eot_flag;

Leave a Reply

Your email address will not be published. Required fields are marked *