linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: Aharon Landau <aharonl@nvidia.com>,
	linux-rdma@vger.kernel.org, Maor Gottlieb <maorg@mellanox.com>,
	Mark Bloch <mbloch@nvidia.com>, Parav Pandit <parav@nvidia.com>
Subject: [PATCH rdma-next 1/5] RDMA/umem: Avoid undefined behavior of rounddown_pow_of_two
Date: Wed, 13 Jan 2021 14:16:59 +0200	[thread overview]
Message-ID: <20210113121703.559778-2-leon@kernel.org> (raw)
In-Reply-To: <20210113121703.559778-1-leon@kernel.org>

From: Aharon Landau <aharonl@nvidia.com>

rounddown_pow_of_two is undefined when the input is 0. Therefore we need
to avoid it in ib_umem_find_best_pgsz and return 0.
Otherwise, it could result in incorrect page size.

Fixes: 3361c29e9279 ("RDMA/umem: Use simpler logic for ib_umem_find_best_pgsz()")
Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/umem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 95be8cc75d2e..baaf1bf22941 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -137,7 +137,7 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
 	 */
 	if (mask)
 		pgsz_bitmap &= GENMASK(count_trailing_zeros(mask), 0);
-	return rounddown_pow_of_two(pgsz_bitmap);
+	return pgsz_bitmap ? rounddown_pow_of_two(pgsz_bitmap) : 0;
 }
 EXPORT_SYMBOL(ib_umem_find_best_pgsz);

--
2.29.2


  reply	other threads:[~2021-01-13 12:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 12:16 [PATCH rdma-next 0/5] Set of fixes Leon Romanovsky
2021-01-13 12:16 ` Leon Romanovsky [this message]
2021-01-13 12:17 ` [PATCH rdma-next 2/5] IB/mlx5: Fix error unwinding when set_has_smi_cap fails Leon Romanovsky
2021-01-13 12:17 ` [PATCH rdma-next 3/5] IB/mlx5: Add mutex destroy call to cap_mask_mutex mutex Leon Romanovsky
2021-01-13 12:17 ` [PATCH rdma-next 4/5] IB/mlx5: Make function static Leon Romanovsky
2021-01-13 12:17 ` [PATCH rdma-next 5/5] RDMA/mlx5: Fix wrong free of blue flame register on error Leon Romanovsky
2021-01-14 17:04 ` [PATCH rdma-next 0/5] Set of fixes Jason Gunthorpe
2021-01-14 17:36   ` Leon Romanovsky
2021-01-20  0:15 ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210113121703.559778-2-leon@kernel.org \
    --to=leon@kernel.org \
    --cc=aharonl@nvidia.com \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maorg@mellanox.com \
    --cc=mbloch@nvidia.com \
    --cc=parav@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).