All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 0/2] RDMA clang warning fixes
@ 2022-01-09 18:41 Leon Romanovsky
  2022-01-09 18:41 ` [PATCH iproute2-next 1/2] rdma: Limit copy data by the destination size Leon Romanovsky
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Leon Romanovsky @ 2022-01-09 18:41 UTC (permalink / raw)
  To: netdev; +Cc: Leon Romanovsky, Stephen Hemminger

From: Leon Romanovsky <leonro@nvidia.com>

This is followup to Stephen's series [1].

Thanks

[1] https://lore.kernel.org/all/20220108204650.36185-1-sthemmin@microsoft.com

Leon Romanovsky (2):
  rdma: Limit copy data by the destination size
  rdma: Don't allocate sparse array

 rdma/res-srq.c | 14 +++++---------
 rdma/res.c     |  6 +++---
 2 files changed, 8 insertions(+), 12 deletions(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 1/2] rdma: Limit copy data by the destination size
  2022-01-09 18:41 [PATCH iproute2-next 0/2] RDMA clang warning fixes Leon Romanovsky
@ 2022-01-09 18:41 ` Leon Romanovsky
  2022-01-09 18:41 ` [PATCH iproute2-next 2/2] rdma: Don't allocate sparse array Leon Romanovsky
  2022-01-11 16:30 ` [PATCH iproute2-next 0/2] RDMA clang warning fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2022-01-09 18:41 UTC (permalink / raw)
  To: netdev; +Cc: Leon Romanovsky, Stephen Hemminger, Stephen Hemminger

From: Leon Romanovsky <leonro@nvidia.com>

The strncat() function will copy upto n bytes supplied as third
argument. The n bytes shouldn't be no more than destination and
not the source.

This change fixes the following clang compilation warnings:

res-srq.c:75:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
                        strncat(qp_str, tmp, sizeof(tmp) - 1);
                                             ^~~~~~~~~~~~~~~
res-srq.c:99:23: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
        strncat(qp_str, tmp, sizeof(tmp) - 1);
                             ^~~~~~~~~~~~~~~
res-srq.c:142:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
                        strncat(qp_str, tmp, sizeof(tmp) - 1);
                                             ^~~~~~~~~~~~~~~

Fixes: 9b272e138d23 ("rdma: Add SRQ resource tracking information")
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 rdma/res-srq.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/rdma/res-srq.c b/rdma/res-srq.c
index 5d8f3842..3038c352 100644
--- a/rdma/res-srq.c
+++ b/rdma/res-srq.c
@@ -70,9 +70,8 @@ static int filter_srq_range_qps(struct rd *rd, struct nlattr **qp_line,
 					 *delimiter, tmp_min_range,
 					 tmp_max_range);
 
-			if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN)
-				return -EINVAL;
-			strncat(qp_str, tmp, sizeof(tmp) - 1);
+			strncat(qp_str, tmp,
+				MAX_QP_STR_LEN - strlen(qp_str) - 1);
 
 			memset(tmp, 0, strlen(tmp));
 			*delimiter = ",";
@@ -94,9 +93,7 @@ static int filter_srq_range_qps(struct rd *rd, struct nlattr **qp_line,
 		snprintf(tmp, sizeof(tmp), "%s%d-%d", *delimiter,
 			 tmp_min_range, tmp_max_range);
 
-	if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN)
-		return -EINVAL;
-	strncat(qp_str, tmp, sizeof(tmp) - 1);
+	strncat(qp_str, tmp, MAX_QP_STR_LEN - strlen(qp_str) - 1);
 	*delimiter = ",";
 	return 0;
 }
@@ -137,9 +134,8 @@ static int get_srq_qps(struct rd *rd, struct nlattr *qp_table,  char *qp_str)
 					qp_line[RDMA_NLDEV_ATTR_RES_LQPN]))
 				continue;
 			snprintf(tmp, sizeof(tmp), "%s%d", delimiter, qpn);
-			if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN)
-				goto out;
-			strncat(qp_str, tmp, sizeof(tmp) - 1);
+			strncat(qp_str, tmp,
+				MAX_QP_STR_LEN - strlen(qp_str) - 1);
 			delimiter = ",";
 		} else if (qp_line[RDMA_NLDEV_ATTR_MIN_RANGE] &&
 			   qp_line[RDMA_NLDEV_ATTR_MAX_RANGE]) {
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 2/2] rdma: Don't allocate sparse array
  2022-01-09 18:41 [PATCH iproute2-next 0/2] RDMA clang warning fixes Leon Romanovsky
  2022-01-09 18:41 ` [PATCH iproute2-next 1/2] rdma: Limit copy data by the destination size Leon Romanovsky
@ 2022-01-09 18:41 ` Leon Romanovsky
  2022-01-11 16:30 ` [PATCH iproute2-next 0/2] RDMA clang warning fixes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2022-01-09 18:41 UTC (permalink / raw)
  To: netdev; +Cc: Leon Romanovsky, Stephen Hemminger, Stephen Hemminger

From: Leon Romanovsky <leonro@nvidia.com>

The addition of driver QP type with index 0xFF caused to the following
clang compilation error:

res.c:152:10: warning: result of comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
        if (idx < ARRAY_SIZE(qp_types_str) && qp_types_str[idx])
            ~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~

Instead of allocating very sparse array, simply create separate check
for the driver QP type.

Fixes: 39307384cea7 ("rdma: Add driver QP type string")
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 rdma/res.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rdma/res.c b/rdma/res.c
index 9aae5d4b..21fef9bd 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -146,12 +146,12 @@ const char *qp_types_to_str(uint8_t idx)
 						     "RAW_ETHERTYPE",
 						     "UNKNOWN", "RAW_PACKET",
 						     "XRC_INI", "XRC_TGT",
-						     [0xFF] = "DRIVER",
 	};
 
-	if (idx < ARRAY_SIZE(qp_types_str) && qp_types_str[idx])
+	if (idx < ARRAY_SIZE(qp_types_str))
 		return qp_types_str[idx];
-	return "UNKNOWN";
+
+	return (idx == 0xFF) ? "DRIVER" : "UNKNOWN";
 }
 
 void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line)
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2-next 0/2] RDMA clang warning fixes
  2022-01-09 18:41 [PATCH iproute2-next 0/2] RDMA clang warning fixes Leon Romanovsky
  2022-01-09 18:41 ` [PATCH iproute2-next 1/2] rdma: Limit copy data by the destination size Leon Romanovsky
  2022-01-09 18:41 ` [PATCH iproute2-next 2/2] rdma: Don't allocate sparse array Leon Romanovsky
@ 2022-01-11 16:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-11 16:30 UTC (permalink / raw)
  To: Leon Romanovsky; +Cc: netdev, leonro, sthemmin

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Sun,  9 Jan 2022 20:41:37 +0200 you wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> This is followup to Stephen's series [1].
> 
> Thanks
> 
> [1] https://lore.kernel.org/all/20220108204650.36185-1-sthemmin@microsoft.com
> 
> [...]

Here is the summary with links:
  - [iproute2-next,1/2] rdma: Limit copy data by the destination size
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=b87671681e8a
  - [iproute2-next,2/2] rdma: Don't allocate sparse array
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=bb4cc9cca408

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-11 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-09 18:41 [PATCH iproute2-next 0/2] RDMA clang warning fixes Leon Romanovsky
2022-01-09 18:41 ` [PATCH iproute2-next 1/2] rdma: Limit copy data by the destination size Leon Romanovsky
2022-01-09 18:41 ` [PATCH iproute2-next 2/2] rdma: Don't allocate sparse array Leon Romanovsky
2022-01-11 16:30 ` [PATCH iproute2-next 0/2] RDMA clang warning fixes patchwork-bot+netdevbpf

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.