]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
rdma: Don't allocate sparse array
authorLeon Romanovsky <leonro@nvidia.com>
Sun, 9 Jan 2022 18:41:39 +0000 (20:41 +0200)
committerDavid Ahern <dsahern@kernel.org>
Tue, 11 Jan 2022 16:19:27 +0000 (09:19 -0700)
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>
Signed-off-by: David Ahern <dsahern@kernel.org>
rdma/res.c

index 9aae5d4b9cf07264277c5e0ef602901d23662b48..21fef9bdd11355a21872cd4014181445221d96e2 100644 (file)
@@ -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)