RDMA clang warning fixes
Subsystems (2)
cover RDMA clang warning fixes
From: Leon Romanovsky <[email protected]>
This is followup to Stephen's series [1].
Thanks
[1] https://lore.kernel.org/all/[email protected]
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(-)
Signature · 1 line
2.33.1
PATCH 1/2 rdma: Limit copy data by the destination size
From: Leon Romanovsky <[email protected]>
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);
^~~~~~~~~~~~~~~--- rdma/res-srq.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
rdma/res-srq.c +5 -9
@@ -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 ]) {
Signature · 1 line
2.33.1
PATCH 2/2 rdma: Don't allocate sparse array
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
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.
--- rdma/res.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
rdma/res.c +3 -3
@@ -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)
Signature · 1 line
2.33.1
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 9 lines · On Sun, 9 Jan 2022 20:41:37 +0200 you wrote:
From: Leon Romanovsky <[email protected]>
This is followup to Stephen's series [1].
Thanks
[1] https://lore.kernel.org/all/[email protected]
[...]
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html