summaryrefslogtreecommitdiff
path: root/drivers/infiniband/core
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2020-10-07 19:36:26 -0700
committerJason Gunthorpe <jgg@nvidia.com>2020-10-30 21:03:52 -0300
commit45808361d4491217de11cdf0661d657081f8f422 (patch)
treeac2e051297c598c34e9a9ac960aab518e0df589e /drivers/infiniband/core
parent32053e584e4a342be37a0932ffc1f9b13e914515 (diff)
RDMA: Manual changes for sysfs_emit and neatening
Make changes to use sysfs_emit in the RDMA code as cocci scripts can not be written to handle _all_ the possible variants of various sprintf family uses in sysfs show functions. While there, make the code more legible and update its style to be more like the typical kernel styles. Miscellanea: o Use intermediate pointers for dereferences o Add and use string lookup functions o return early when any intermediate call fails so normal return is at the bottom of the function o mlx4/mcg.c:sysfs_show_group: use scnprintf to format intermediate strings Link: https://lore.kernel.org/r/f5c9e4c9d8dafca1b7b70bd597ee7f8f219c31c8.1602122880.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/infiniband/core')
-rw-r--r--drivers/infiniband/core/sysfs.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 4e335fc4d016..4dd803f23aaa 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -1224,29 +1224,34 @@ err_put:
return ret;
}
-static ssize_t node_type_show(struct device *device,
- struct device_attribute *attr, char *buf)
+static const char *node_type_string(int node_type)
{
- struct ib_device *dev = rdma_device_to_ibdev(device);
-
- switch (dev->node_type) {
+ switch (node_type) {
case RDMA_NODE_IB_CA:
- return sysfs_emit(buf, "%d: CA\n", dev->node_type);
+ return "CA";
+ case RDMA_NODE_IB_SWITCH:
+ return "switch";
+ case RDMA_NODE_IB_ROUTER:
+ return "router";
case RDMA_NODE_RNIC:
- return sysfs_emit(buf, "%d: RNIC\n", dev->node_type);
+ return "RNIC";
case RDMA_NODE_USNIC:
- return sysfs_emit(buf, "%d: usNIC\n", dev->node_type);
+ return "usNIC";
case RDMA_NODE_USNIC_UDP:
- return sysfs_emit(buf, "%d: usNIC UDP\n", dev->node_type);
+ return "usNIC UDP";
case RDMA_NODE_UNSPECIFIED:
- return sysfs_emit(buf, "%d: unspecified\n", dev->node_type);
- case RDMA_NODE_IB_SWITCH:
- return sysfs_emit(buf, "%d: switch\n", dev->node_type);
- case RDMA_NODE_IB_ROUTER:
- return sysfs_emit(buf, "%d: router\n", dev->node_type);
- default:
- return sysfs_emit(buf, "%d: <unknown>\n", dev->node_type);
+ return "unspecified";
}
+ return "<unknown>";
+}
+
+static ssize_t node_type_show(struct device *device,
+ struct device_attribute *attr, char *buf)
+{
+ struct ib_device *dev = rdma_device_to_ibdev(device);
+
+ return sysfs_emit(buf, "%d: %s\n", dev->node_type,
+ node_type_string(dev->node_type));
}
static DEVICE_ATTR_RO(node_type);
@@ -1254,13 +1259,13 @@ static ssize_t sys_image_guid_show(struct device *device,
struct device_attribute *dev_attr, char *buf)
{
struct ib_device *dev = rdma_device_to_ibdev(device);
+ __be16 *guid = (__be16 *)&dev->attrs.sys_image_guid;
- return sysfs_emit(
- buf, "%04x:%04x:%04x:%04x\n",
- be16_to_cpu(((__be16 *)&dev->attrs.sys_image_guid)[0]),
- be16_to_cpu(((__be16 *)&dev->attrs.sys_image_guid)[1]),
- be16_to_cpu(((__be16 *)&dev->attrs.sys_image_guid)[2]),
- be16_to_cpu(((__be16 *)&dev->attrs.sys_image_guid)[3]));
+ return sysfs_emit(buf, "%04x:%04x:%04x:%04x\n",
+ be16_to_cpu(guid[0]),
+ be16_to_cpu(guid[1]),
+ be16_to_cpu(guid[2]),
+ be16_to_cpu(guid[3]));
}
static DEVICE_ATTR_RO(sys_image_guid);
@@ -1268,12 +1273,13 @@ static ssize_t node_guid_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct ib_device *dev = rdma_device_to_ibdev(device);
+ __be16 *node_guid = (__be16 *)&dev->node_guid;
return sysfs_emit(buf, "%04x:%04x:%04x:%04x\n",
- be16_to_cpu(((__be16 *)&dev->node_guid)[0]),
- be16_to_cpu(((__be16 *)&dev->node_guid)[1]),
- be16_to_cpu(((__be16 *)&dev->node_guid)[2]),
- be16_to_cpu(((__be16 *)&dev->node_guid)[3]));
+ be16_to_cpu(node_guid[0]),
+ be16_to_cpu(node_guid[1]),
+ be16_to_cpu(node_guid[2]),
+ be16_to_cpu(node_guid[3]));
}
static DEVICE_ATTR_RO(node_guid);
@@ -1309,10 +1315,11 @@ static ssize_t fw_ver_show(struct device *device, struct device_attribute *attr,
char *buf)
{
struct ib_device *dev = rdma_device_to_ibdev(device);
+ char version[IB_FW_VERSION_NAME_MAX] = {};
+
+ ib_get_device_fw_str(dev, version);
- ib_get_device_fw_str(dev, buf);
- strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX);
- return strlen(buf);
+ return sysfs_emit(buf, "%s\n", version);
}
static DEVICE_ATTR_RO(fw_ver);