From: Leon Romanovsky Date: Sun, 9 Jan 2022 18:41:39 +0000 (+0200) Subject: rdma: Don't allocate sparse array X-Git-Tag: v5.17.0~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb4cc9cca40850370c1fe5ba79b3f7f186f379f1;p=thirdparty%2Fiproute2.git rdma: Don't allocate sparse array 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 Signed-off-by: Leon Romanovsky Signed-off-by: David Ahern --- diff --git a/rdma/res.c b/rdma/res.c index 9aae5d4b9..21fef9bdd 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)