Skip to contentSkip to conversation

coresight: Convert to use sysfs_emit()/sysfs_emit_at() APIs

PATCH New [email protected] 1 participant 1 message Dec 6, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coresight: Convert to use sysfs_emit()/sysfs_emit_at() APIs

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/hwtracing/coresight/coresight-core.c  |   4 +-
 .../hwtracing/coresight/coresight-etm-perf.c  |   4 +-
 .../coresight/coresight-etm3x-sysfs.c         |   2 +-
 .../coresight/coresight-etm4x-sysfs.c         | 114 +++++++++---------
 drivers/hwtracing/coresight/coresight-stm.c   |   8 +-
 .../coresight/coresight-syscfg-configfs.c     |  25 ++--
 6 files changed, 77 insertions(+), 80 deletions(-)
drivers/hwtracing/coresight/coresight-core.c +2 -2
index f3068175ca9d..d5d5080cce78 100644
@@ -1236,7 +1236,7 @@ static ssize_t enable_sink_show(struct device *dev,
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", csdev->activated);
+	return  sysfs_emit(buf, "%u\n", csdev->activated);
 }
 
 static ssize_t enable_sink_store(struct device *dev,
@@ -1266,7 +1266,7 @@ static ssize_t enable_source_show(struct device *dev,
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", csdev->enable);
+	return sysfs_emit(buf, "%u\n", csdev->enable);
 }
 
 static ssize_t enable_source_store(struct device *dev,
drivers/hwtracing/coresight/coresight-etm-perf.c +2 -2
index 43bbd5dc3d3b..8bf8dbf4b7c2 100644
@@ -726,7 +726,7 @@ static ssize_t etm_perf_sink_name_show(struct device *dev,
 	struct dev_ext_attribute *ea;
 
 	ea = container_of(dattr, struct dev_ext_attribute, attr);
-	return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
+	return sysfs_emit(buf, "0x%lx\n", (unsigned long)(ea->var));
 }
 
 static struct dev_ext_attribute *
@@ -818,7 +818,7 @@ static ssize_t etm_perf_cscfg_event_show(struct device *dev,
 	struct dev_ext_attribute *ea;
 
 	ea = container_of(dattr, struct dev_ext_attribute, attr);
-	return scnprintf(buf, PAGE_SIZE, "configid=0x%lx\n", (unsigned long)(ea->var));
+	return sysfs_emit(buf, "configid=0x%lx\n", (unsigned long)(ea->var));
 }
 
 int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *config_desc)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -1
index fd81eca3ec18..3cb811853d64 100644
@@ -1181,7 +1181,7 @@ static ssize_t cpu_show(struct device *dev,
 	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 
 	val = drvdata->cpu;
-	return scnprintf(buf, PAGE_SIZE, "%d\n", val);
+	return sysfs_emit(buf, "%d\n", val);
 
 }
 static DEVICE_ATTR_RO(cpu);
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +56 -58

438 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-stm.c +4 -4
index 463f449cfb79..3a1b07217932 100644
@@ -466,7 +466,7 @@ static ssize_t hwevent_enable_show(struct device *dev,
 	struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	unsigned long val = drvdata->stmheer;
 
-	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
+	return sysfs_emit(buf, "%#lx\n", val);
 }
 
 static ssize_t hwevent_enable_store(struct device *dev,
@@ -495,7 +495,7 @@ static ssize_t hwevent_select_show(struct device *dev,
 	struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	unsigned long val = drvdata->stmhebsr;
 
-	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
+	return sysfs_emit(buf, "%#lx\n", val);
 }
 
 static ssize_t hwevent_select_store(struct device *dev,
@@ -530,7 +530,7 @@ static ssize_t port_select_show(struct device *dev,
 		spin_unlock(&drvdata->spinlock);
 	}
 
-	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
+	return sysfs_emit(buf, "%#lx\n", val);
 }
 
 static ssize_t port_select_store(struct device *dev,
@@ -577,7 +577,7 @@ static ssize_t port_enable_show(struct device *dev,
 		spin_unlock(&drvdata->spinlock);
 	}
 
-	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
+	return sysfs_emit(buf, "%#lx\n", val);
 }
 
 static ssize_t port_enable_store(struct device *dev,
drivers/hwtracing/coresight/coresight-syscfg-configfs.c +12 -13
index 433ede94dd63..20effbd5fb80 100644
@@ -29,7 +29,7 @@ static ssize_t cscfg_cfg_description_show(struct config_item *item, char *page)
 	struct cscfg_fs_config *fs_config = container_of(to_config_group(item),
 							 struct cscfg_fs_config, group);
 
-	return scnprintf(page, PAGE_SIZE, "%s", fs_config->config_desc->description);
+	return sysfs_emit(page, "%s", fs_config->config_desc->description);
 }
 CONFIGFS_ATTR_RO(cscfg_cfg_, description);
 
@@ -42,8 +42,7 @@ static ssize_t cscfg_cfg_feature_refs_show(struct config_item *item, char *page)
 	int i;
 
 	for (i = 0; i < config_desc->nr_feat_refs; i++)
-		ch_used += scnprintf(page + ch_used, PAGE_SIZE - ch_used,
-				     "%s\n", config_desc->feat_ref_names[i]);
+		ch_used += sysfs_emit_at(page, ch_used, "%s\n", config_desc->feat_ref_names[i]);
 	return ch_used;
 }
 CONFIGFS_ATTR_RO(cscfg_cfg_, feature_refs);
@@ -75,14 +74,14 @@ static ssize_t cscfg_cfg_values_show(struct config_item *item, char *page)
 	for (i = 0; i < config_desc->nr_feat_refs; i++) {
 		feat_desc = cscfg_get_named_feat_desc(config_desc->feat_ref_names[i]);
 		for (j = 0; j < feat_desc->nr_params; j++) {
-			used += scnprintf(page + used, PAGE_SIZE - used,
+			used += sysfs_emit_at(page, used,
 					  "%s.%s = 0x%llx ",
 					  feat_desc->name,
 					  feat_desc->params_desc[j].name,
 					  config_desc->presets[val_idx++]);
 		}
 	}
-	used += scnprintf(page + used, PAGE_SIZE - used, "\n");
+	used += sysfs_emit_at(page, used, "\n");
 
 	return used;
 }
@@ -93,7 +92,7 @@ static ssize_t cscfg_cfg_enable_show(struct config_item *item, char *page)
 	struct cscfg_fs_config *fs_config = container_of(to_config_group(item),
 							 struct cscfg_fs_config, group);
 
-	return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->active);
+	return sysfs_emit(page, "%d\n", fs_config->active);
 }
 
 static ssize_t cscfg_cfg_enable_store(struct config_item *item,
@@ -121,7 +120,7 @@ static ssize_t cscfg_cfg_preset_show(struct config_item *item, char *page)
 	struct cscfg_fs_config *fs_config = container_of(to_config_group(item),
 							 struct cscfg_fs_config, group);
 
-	return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->preset);
+	return sysfs_emit(page, "%d\n", fs_config->preset);
 }
 
 static ssize_t cscfg_cfg_preset_store(struct config_item *item,
@@ -233,7 +232,7 @@ static ssize_t cscfg_feat_description_show(struct config_item *item, char *page)
 	struct cscfg_fs_feature *fs_feat = container_of(to_config_group(item),
 							struct cscfg_fs_feature, group);
 
-	return scnprintf(page, PAGE_SIZE, "%s", fs_feat->feat_desc->description);
+	return sysfs_emit(page, "%s", fs_feat->feat_desc->description);
 }
 CONFIGFS_ATTR_RO(cscfg_feat_, description);
 
@@ -245,12 +244,12 @@ static ssize_t cscfg_feat_matches_show(struct config_item *item, char *page)
 	int used = 0;
 
 	if (match_flags & CS_CFG_MATCH_CLASS_SRC_ALL)
-		used = scnprintf(page, PAGE_SIZE, "SRC_ALL ");
+		used = sysfs_emit(page, "SRC_ALL ");
 
 	if (match_flags & CS_CFG_MATCH_CLASS_SRC_ETM4)
-		used += scnprintf(page + used, PAGE_SIZE - used, "SRC_ETMV4 ");
+		used += sysfs_emit_at(page, used, "SRC_ETMV4 ");
 
-	used += scnprintf(page + used, PAGE_SIZE - used, "\n");
+	used += sysfs_emit_at(page, used, "\n");
 	return used;
 }
 CONFIGFS_ATTR_RO(cscfg_feat_, matches);
@@ -260,7 +259,7 @@ static ssize_t cscfg_feat_nr_params_show(struct config_item *item, char *page)
 	struct cscfg_fs_feature *fs_feat = container_of(to_config_group(item),
 							struct cscfg_fs_feature, group);
 
-	return scnprintf(page, PAGE_SIZE, "%d\n", fs_feat->feat_desc->nr_params);
+	return sysfs_emit(page, "%d\n", fs_feat->feat_desc->nr_params);
 }
 CONFIGFS_ATTR_RO(cscfg_feat_, nr_params);
 
@@ -283,7 +282,7 @@ static ssize_t cscfg_param_value_show(struct config_item *item, char *page)
 							 struct cscfg_fs_param, group);
 	u64 value = param_item->feat_desc->params_desc[param_item->param_idx].value;
 
-	return scnprintf(page, PAGE_SIZE, "0x%llx\n", value);
+	return sysfs_emit(page, "0x%llx\n", value);
 }
 
 static ssize_t cscfg_param_value_store(struct config_item *item,
Signature · 1 line
2.25.1