All of lore.kernel.org
 help / color / mirror / Atom feed
From: Weihang Li <liweihang@huawei.com>
To: <dledford@redhat.com>, <jgg@nvidia.com>
Cc: <leon@kernel.org>, <linux-rdma@vger.kernel.org>,
	<linuxarm@huawei.com>, Lang Cheng <chenglang@huawei.com>,
	Weihang Li <liweihang@huawei.com>
Subject: [PATCH RESEND v2 for-next 1/7] RDMA/hns: Fix potential compile warnings on hr_reg_write()
Date: Wed, 2 Jun 2021 16:57:39 +0800	[thread overview]
Message-ID: <1622624265-44796-2-git-send-email-liweihang@huawei.com> (raw)
In-Reply-To: <1622624265-44796-1-git-send-email-liweihang@huawei.com>

From: Lang Cheng <chenglang@huawei.com>

GCC may reports an running time assert error when a value calculated from
ib_mtu_enum_to_int() is using as 'val' in FIELD_PREDP:

include/linux/compiler_types.h:328:38: error: call to
'__compiletime_assert_1524' declared with attribute error: FIELD_PREP:
value too large for the field

But actually this error will still exists even if the driver can ensure
that ib_mtu_enum_to_int() returns a legal value. So add a mask in
hr_reg_write() to avoid above warning.

Also fix complains from sparse about "dubious: x & !y" when
hr_reg_write(ctx, field, !!val),Use temporary variables to avoid this.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Lang Cheng <chenglang@huawei.com>
Signed-off-by: Weihang Li <liweihang@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_common.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_common.h b/drivers/infiniband/hw/hns/hns_roce_common.h
index 3a5658f..dc7a9fe 100644
--- a/drivers/infiniband/hw/hns/hns_roce_common.h
+++ b/drivers/infiniband/hw/hns/hns_roce_common.h
@@ -79,9 +79,11 @@
 
 #define _hr_reg_write(ptr, field_type, field_h, field_l, val)                  \
 	({                                                                     \
+		u32 _val = val;                                                \
 		_hr_reg_clear(ptr, field_type, field_h, field_l);              \
-		*((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(FIELD_PREP(   \
-			GENMASK((field_h) % 32, (field_l) % 32), val));        \
+		*((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(              \
+			FIELD_PREP(GENMASK((field_h) % 32, (field_l) % 32),    \
+				   _val & GENMASK((field_h) - (field_l), 0))); \
 	})
 
 #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
-- 
2.7.4


  reply	other threads:[~2021-06-02  8:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02  8:57 [PATCH RESEND v2 for-next 0/7] RDMA/hns: Use new interfaces to write/read fields Weihang Li
2021-06-02  8:57 ` Weihang Li [this message]
2021-06-16 19:40   ` [PATCH RESEND v2 for-next 1/7] RDMA/hns: Fix potential compile warnings on hr_reg_write() Jason Gunthorpe
2021-06-17  6:33     ` liweihang
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 2/7] RDMA/hns: Use new interface to write CQ context Weihang Li
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 3/7] RDMA/hns: Use new interface to modify QP context Weihang Li
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 4/7] RDMA/hns: Use new interface to get CQE fields Weihang Li
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 5/7] RDMA/hns: Use new interface to write FRMR fields Weihang Li
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 6/7] RDMA/hns: Use new interface to write DB related fields Weihang Li
2021-06-02  8:57 ` [PATCH RESEND v2 for-next 7/7] RDMA/hns: Clean SRQC structure definition Weihang Li

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=1622624265-44796-2-git-send-email-liweihang@huawei.com \
    --to=liweihang@huawei.com \
    --cc=chenglang@huawei.com \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=leon@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.