]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
RDMA/hns: fix potential integer overflow on left shift
authorColin Ian King <colin.king@canonical.com>
Mon, 24 Jun 2019 21:46:08 +0000 (22:46 +0100)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 25 Jun 2019 13:18:19 +0000 (10:18 -0300)
There is a potential integer overflow when int i is left shifted as this
is evaluated using 32 bit arithmetic but is being used in a context that
expects an expression of type dma_addr_t.  Fix this by casting integer i
to dma_addr_t before shifting to avoid the overflow.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 2ac0bc5e725e ("RDMA/hns: Add a group interfaces for optimizing buffers getting flow")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/hns/hns_roce_alloc.c

index 14fcc359599ccd6fb6557a4e38dff9500546675e..2c8defa9410709e388cc01f2e0254305a43a9475 100644 (file)
@@ -257,7 +257,7 @@ int hns_roce_get_kmem_bufs(struct hns_roce_dev *hr_dev, dma_addr_t *bufs,
        for (i = start; i < end; i++)
                if (buf->nbufs == 1)
                        bufs[total++] = buf->direct.map +
-                                       (i << buf->page_shift);
+                                       ((dma_addr_t)i << buf->page_shift);
                else
                        bufs[total++] = buf->page_list[i].map;