diff mbox

mlx5: shift wrapping bug in mlx5_ib_get_buf_offset()

Message ID 20131108095259.GK27977@elgon.mountain (mailing list archive)
State Rejected
Headers show

Commit Message

Dan Carpenter Nov. 8, 2013, 9:52 a.m. UTC
"page_size" is declared as u64 but the (1 << page_shift) shift will wrap
at 32 bits.

Fixes: e126ba97dba9 ('mlx5: Add driver for Mellanox Connect-IB adapters')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Eli Cohen Nov. 10, 2013, 7:09 a.m. UTC | #1
On Fri, Nov 08, 2013 at 12:52:59PM +0300, Dan Carpenter wrote:
> "page_size" is declared as u64 but the (1 << page_shift) shift will wrap
> at 32 bits.

I hope to live when this happnes :-)
I prefer to be explicit and use:
        page_size = (u64)1 << page_shift;

> 
> Fixes: e126ba97dba9 ('mlx5: Add driver for Mellanox Connect-IB adapters')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/infiniband/hw/mlx5/mem.c b/drivers/infiniband/hw/mlx5/mem.c
> index 3a53228..3020ec2 100644
> --- a/drivers/infiniband/hw/mlx5/mem.c
> +++ b/drivers/infiniband/hw/mlx5/mem.c
> @@ -148,7 +148,7 @@ int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset)
>  	u64 off_mask;
>  	u64 buf_off;
>  
> -	page_size = 1 << page_shift;
> +	page_size = 1ULL << page_shift;
>  	page_mask = page_size - 1;
>  	buf_off = addr & page_mask;
>  	off_size = page_size >> 6;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/infiniband/hw/mlx5/mem.c b/drivers/infiniband/hw/mlx5/mem.c
index 3a53228..3020ec2 100644
--- a/drivers/infiniband/hw/mlx5/mem.c
+++ b/drivers/infiniband/hw/mlx5/mem.c
@@ -148,7 +148,7 @@  int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset)
 	u64 off_mask;
 	u64 buf_off;
 
-	page_size = 1 << page_shift;
+	page_size = 1ULL << page_shift;
 	page_mask = page_size - 1;
 	buf_off = addr & page_mask;
 	off_size = page_size >> 6;