]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/core: Use ib_port_state_to_str() for IB state sysfs
authorMaher Sanalla <msanalla@nvidia.com>
Mon, 3 Feb 2025 12:48:05 +0000 (14:48 +0200)
committerLeon Romanovsky <leon@kernel.org>
Thu, 6 Feb 2025 08:40:57 +0000 (03:40 -0500)
Refactor the IB state sysfs implementation to replace the local array
used for converting IB state to string with the ib_port_state_to_str()
function.

Signed-off-by: Maher Sanalla <msanalla@nvidia.com>
Link: https://patch.msgid.link/06affabbbf144f990e64b447918af39483c78c3e.1738586601.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/sysfs.c

index 9f97bef0214975adb88b541496c3c10071c081c3..7491328ca5e645194f9a28e0e740c45a944f494e 100644 (file)
@@ -216,24 +216,12 @@ static ssize_t state_show(struct ib_device *ibdev, u32 port_num,
        struct ib_port_attr attr;
        ssize_t ret;
 
-       static const char *state_name[] = {
-               [IB_PORT_NOP]           = "NOP",
-               [IB_PORT_DOWN]          = "DOWN",
-               [IB_PORT_INIT]          = "INIT",
-               [IB_PORT_ARMED]         = "ARMED",
-               [IB_PORT_ACTIVE]        = "ACTIVE",
-               [IB_PORT_ACTIVE_DEFER]  = "ACTIVE_DEFER"
-       };
-
        ret = ib_query_port(ibdev, port_num, &attr);
        if (ret)
                return ret;
 
        return sysfs_emit(buf, "%d: %s\n", attr.state,
-                         attr.state >= 0 &&
-                                         attr.state < ARRAY_SIZE(state_name) ?
-                                 state_name[attr.state] :
-                                 "UNKNOWN");
+                         ib_port_state_to_str(attr.state));
 }
 
 static ssize_t lid_show(struct ib_device *ibdev, u32 port_num,