All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junxian Huang <huangjunxian6@hisilicon.com>
To: <jgg@ziepe.ca>, <leon@kernel.org>
Cc: <linux-rdma@vger.kernel.org>, <linuxarm@huawei.com>,
	<linux-kernel@vger.kernel.org>, <huangjunxian6@hisilicon.com>
Subject: [PATCH for-rc 3/7] RDMA/hns: Fix signed-unsigned mixed comparisons
Date: Tue, 17 Oct 2023 20:52:35 +0800	[thread overview]
Message-ID: <20231017125239.164455-4-huangjunxian6@hisilicon.com> (raw)
In-Reply-To: <20231017125239.164455-1-huangjunxian6@hisilicon.com>

From: Chengchang Tang <tangchengchang@huawei.com>

The ib_mtu_enum_to_int() and uverbs_attr_get_len() may returns a negative
value. In this case, mixed comparisons of signed and unsigned types will
throw wrong results.

This patch adds judgement for this situation.

Fixes: 30b707886aeb ("RDMA/hns: Support inline data in extented sge space for RC")
Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 2b8f6489ab3d..3daa684f8836 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -270,7 +270,7 @@ static bool check_inl_data_len(struct hns_roce_qp *qp, unsigned int len)
 	struct hns_roce_dev *hr_dev = to_hr_dev(qp->ibqp.device);
 	int mtu = ib_mtu_enum_to_int(qp->path_mtu);
 
-	if (len > qp->max_inline_data || len > mtu) {
+	if (mtu < 0 || len > qp->max_inline_data || len > mtu) {
 		ibdev_err(&hr_dev->ib_dev,
 			  "invalid length of data, data len = %u, max inline len = %u, path mtu = %d.\n",
 			  len, qp->max_inline_data, mtu);
-- 
2.30.0


  parent reply	other threads:[~2023-10-17 12:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 12:52 [PATCH for-rc 0/7] Bugfixes for hns RoCE Junxian Huang
2023-10-17 12:52 ` [PATCH for-rc 1/7] RDMA/hns: Fix printing level of asynchronous events Junxian Huang
2023-10-17 12:52 ` [PATCH for-rc 2/7] RDMA/hns: Fix uninitialized ucmd in hns_roce_create_qp_common() Junxian Huang
2023-10-17 12:52 ` Junxian Huang [this message]
2023-10-17 12:52 ` [PATCH for-rc 4/7] RDMA/hns: Add check for SL Junxian Huang
2023-10-17 12:52 ` [PATCH for-rc 5/7] RDMA/hns: The UD mode can only be configured with DCQCN Junxian Huang
2023-10-17 12:52 ` [PATCH for-rc 6/7] RDMA/hns: Fix unnecessary port_num transition in HW stats allocation Junxian Huang
2023-10-17 12:52 ` [PATCH for-rc 7/7] RDMA/hns: Fix init failure of RoCE VF and HIP08 Junxian Huang
2023-10-19  6:53 ` [PATCH for-rc 0/7] Bugfixes for hns RoCE Leon Romanovsky
2023-10-19  6:53 ` Leon Romanovsky

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=20231017125239.164455-4-huangjunxian6@hisilicon.com \
    --to=huangjunxian6@hisilicon.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.