]> asedeno.scripts.mit.edu Git - linux.git/commit
RDMA/bnxt_re: fix a size calculation
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 10 Jan 2019 13:00:19 +0000 (16:00 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Mon, 14 Jan 2019 21:05:54 +0000 (14:05 -0700)
commit97099cc6529cdf50af32a496b588d9428c57341f
tree79a3f625f33d2c57804c3b62d4ad1af9aebbc12d
parent54747231150f0dddf68f2ee29ec2970fcc433909
RDMA/bnxt_re: fix a size calculation

This is from static analysis not from testing.  Depending on the value
of rcfw->cmdq_depth, then this might not cause an issue at runtime.

The BITS_TO_LONGS() macro tells us how many longs it take to hold a
bitmap.  In other words, it divides by the number if bits per long and
rounds up.  Then we want to take that number and multiple by
sizeof(long) to get the number of bytes to allocate.

The code here does the multiplication first so the rounding up is done
in the wrong place.  So imagine we want to allocate 1 bit, then
"(1 * 8) / 64 = 1" when we round up.  But it should be
"(1 / 64) * 8 = 8".  In other words, because of the rounding difference
we might allocate up to "sizeof(long) - 1" bytes fewer than intended.

Fixes: 1ac5a4047975 ("RDMA/bnxt_re: Add bnxt_re RoCE driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-By: Devesh Sharma <devesh.sharma@broadcom.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/bnxt_re/qplib_rcfw.c