Commit 1c7fd726 authored by Joe Perches's avatar Joe Perches Committed by Jason Gunthorpe
Browse files

RDMA: Convert sysfs device * show functions to use sysfs_emit()

Done with cocci script:

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	strcpy(buf, chr);
+	sysfs_emit(buf, chr);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
-	len += scnprintf(buf + len, PAGE_SIZE - len,
+	len += sysfs_emit_at(buf, len,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	...
-	strcpy(buf, chr);
-	return strlen(buf);
+	return sysfs_emit(buf, chr);
}

Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com


Signed-off-by: default avatarJoe Perches <joe@perches.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 676a80ad
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -1230,14 +1230,22 @@ static ssize_t node_type_show(struct device *device,
	struct ib_device *dev = rdma_device_to_ibdev(device);

	switch (dev->node_type) {
	case RDMA_NODE_IB_CA:	  return sprintf(buf, "%d: CA\n", dev->node_type);
	case RDMA_NODE_RNIC:	  return sprintf(buf, "%d: RNIC\n", dev->node_type);
	case RDMA_NODE_USNIC:	  return sprintf(buf, "%d: usNIC\n", dev->node_type);
	case RDMA_NODE_USNIC_UDP: return sprintf(buf, "%d: usNIC UDP\n", dev->node_type);
	case RDMA_NODE_UNSPECIFIED: return sprintf(buf, "%d: unspecified\n", dev->node_type);
	case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
	case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
	default:		  return sprintf(buf, "%d: <unknown>\n", dev->node_type);
	case RDMA_NODE_IB_CA:
		return sysfs_emit(buf, "%d: CA\n", dev->node_type);
	case RDMA_NODE_RNIC:
		return sysfs_emit(buf, "%d: RNIC\n", dev->node_type);
	case RDMA_NODE_USNIC:
		return sysfs_emit(buf, "%d: usNIC\n", dev->node_type);
	case RDMA_NODE_USNIC_UDP:
		return sysfs_emit(buf, "%d: usNIC UDP\n", dev->node_type);
	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);
	}
}
static DEVICE_ATTR_RO(node_type);
@@ -1247,7 +1255,8 @@ static ssize_t sys_image_guid_show(struct device *device,
{
	struct ib_device *dev = rdma_device_to_ibdev(device);

	return sprintf(buf, "%04x:%04x:%04x:%04x\n",
	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]),
@@ -1260,7 +1269,7 @@ static ssize_t node_guid_show(struct device *device,
{
	struct ib_device *dev = rdma_device_to_ibdev(device);

	return sprintf(buf, "%04x:%04x:%04x:%04x\n",
	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]),
@@ -1273,7 +1282,7 @@ static ssize_t node_desc_show(struct device *device,
{
	struct ib_device *dev = rdma_device_to_ibdev(device);

	return sprintf(buf, "%.64s\n", dev->node_desc);
	return sysfs_emit(buf, "%.64s\n", dev->node_desc);
}

static ssize_t node_desc_store(struct device *device,
+1 −1
Original line number Diff line number Diff line
@@ -1825,7 +1825,7 @@ static ssize_t show_abi_version(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	return sprintf(buf, "%d\n", RDMA_USER_CM_ABI_VERSION);
	return sysfs_emit(buf, "%d\n", RDMA_USER_CM_ABI_VERSION);
}
static DEVICE_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);

+2 −2
Original line number Diff line number Diff line
@@ -1191,7 +1191,7 @@ static ssize_t ibdev_show(struct device *dev, struct device_attribute *attr,
	if (!port)
		return -ENODEV;

	return sprintf(buf, "%s\n", dev_name(&port->ib_dev->dev));
	return sysfs_emit(buf, "%s\n", dev_name(&port->ib_dev->dev));
}
static DEVICE_ATTR_RO(ibdev);

@@ -1203,7 +1203,7 @@ static ssize_t port_show(struct device *dev, struct device_attribute *attr,
	if (!port)
		return -ENODEV;

	return sprintf(buf, "%d\n", port->port_num);
	return sysfs_emit(buf, "%d\n", port->port_num);
}
static DEVICE_ATTR_RO(port);

+2 −2
Original line number Diff line number Diff line
@@ -1046,7 +1046,7 @@ static ssize_t ibdev_show(struct device *device, struct device_attribute *attr,
	srcu_key = srcu_read_lock(&dev->disassociate_srcu);
	ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu);
	if (ib_dev)
		ret = sprintf(buf, "%s\n", dev_name(&ib_dev->dev));
		ret = sysfs_emit(buf, "%s\n", dev_name(&ib_dev->dev));
	srcu_read_unlock(&dev->disassociate_srcu, srcu_key);

	return ret;
@@ -1065,7 +1065,7 @@ static ssize_t abi_version_show(struct device *device,
	srcu_key = srcu_read_lock(&dev->disassociate_srcu);
	ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu);
	if (ib_dev)
		ret = sprintf(buf, "%u\n", ib_dev->ops.uverbs_abi_ver);
		ret = sysfs_emit(buf, "%u\n", ib_dev->ops.uverbs_abi_ver);
	srcu_read_unlock(&dev->disassociate_srcu, srcu_key);

	return ret;
+2 −2
Original line number Diff line number Diff line
@@ -608,7 +608,7 @@ static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
	struct bnxt_re_dev *rdev =
		rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);

	return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor);
	return sysfs_emit(buf, "0x%x\n", rdev->en_dev->pdev->vendor);
}
static DEVICE_ATTR_RO(hw_rev);

@@ -618,7 +618,7 @@ static ssize_t hca_type_show(struct device *device,
	struct bnxt_re_dev *rdev =
		rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);

	return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc);
	return sysfs_emit(buf, "%s\n", rdev->ibdev.node_desc);
}
static DEVICE_ATTR_RO(hca_type);

Loading