linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit
@ 2021-03-17  9:41 Qi Liu
  2021-03-17  9:41 ` [PATCH 1/3] drivers/perf: convert sysfs snprintf family " Qi Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Qi Liu @ 2021-03-17  9:41 UTC (permalink / raw)
  To: john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

Use the generic sysfs_emit() and sysfs_emit_at() function to take
place of sprintf/snprintf/scnprintf, to avoid buffer overrun.

Zihao Tang (1)
  drivers/perf: convert sysfs snprintf family to sysfs_emit

Qi Liu (2):
  drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  drivers/perf: convert sysfs sprintf family to sysfs_emit

 drivers/perf/arm-cci.c                   | 12 ++++++------
 drivers/perf/arm-ccn.c                   | 28 ++++++++++++----------------
 drivers/perf/arm-cmn.c                   | 22 +++++++++++-----------
 drivers/perf/arm_dmc620_pmu.c            |  2 +-
 drivers/perf/arm_dsu_pmu.c               |  5 ++---
 drivers/perf/arm_smmuv3_pmu.c            |  4 ++--
 drivers/perf/arm_spe_pmu.c               |  3 +--
 drivers/perf/fsl_imx8_ddr_perf.c         |  7 +++----
 drivers/perf/hisilicon/hisi_uncore_pmu.c |  8 ++++----
 drivers/perf/qcom_l2_pmu.c               |  2 +-
 drivers/perf/qcom_l3_pmu.c               |  4 ++--
 drivers/perf/thunderx2_pmu.c             |  4 ++--
 drivers/perf/xgene_pmu.c                 |  4 ++--
 13 files changed, 49 insertions(+), 56 deletions(-)

-- 
2.8.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] drivers/perf: convert sysfs snprintf family to sysfs_emit
  2021-03-17  9:41 [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit Qi Liu
@ 2021-03-17  9:41 ` Qi Liu
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
  2021-03-17  9:41 ` [PATCH 3/3] drivers/perf: convert sysfs sprintf family to sysfs_emit Qi Liu
  2 siblings, 0 replies; 10+ messages in thread
From: Qi Liu @ 2021-03-17  9:41 UTC (permalink / raw)
  To: john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

From: Zihao Tang <tangzihao1@hisilicon.com>

Fix the following coccicheck warning:

./drivers/perf/hisilicon/hisi_uncore_pmu.c:128:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/fsl_imx8_ddr_perf.c:173:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm_spe_pmu.c:129:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm_smmu_pmu.c:563:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm_dsu_pmu.c:149:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm_dsu_pmu.c:139:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cmn.c:563:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cmn.c:351:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-ccn.c:224:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:708:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:699:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:528:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:309:8-16: WARNING: use scnprintf or sprintf.

Signed-off-by: Zihao Tang <tangzihao1@hisilicon.com>
Signed-off-by: Qi Liu <liuqi115@huawei.com>
---
 drivers/perf/arm-cci.c                   | 12 ++++++------
 drivers/perf/arm-ccn.c                   |  4 ++--
 drivers/perf/arm-cmn.c                   | 22 +++++++++++-----------
 drivers/perf/arm_dsu_pmu.c               |  5 ++---
 drivers/perf/arm_smmuv3_pmu.c            |  2 +-
 drivers/perf/arm_spe_pmu.c               |  3 +--
 drivers/perf/fsl_imx8_ddr_perf.c         |  3 +--
 drivers/perf/hisilicon/hisi_uncore_pmu.c |  2 +-
 8 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
index f81e2ec..666d8a9 100644
--- a/drivers/perf/arm-cci.c
+++ b/drivers/perf/arm-cci.c
@@ -306,7 +306,7 @@ static ssize_t cci400_pmu_cycle_event_show(struct device *dev,
 {
 	struct dev_ext_attribute *eattr = container_of(attr,
 				struct dev_ext_attribute, attr);
-	return snprintf(buf, PAGE_SIZE, "config=0x%lx\n", (unsigned long)eattr->var);
+	return sysfs_emit(buf, "config=0x%lx\n", (unsigned long)eattr->var);
 }
 
 static int cci400_get_event_idx(struct cci_pmu *cci_pmu,
@@ -525,8 +525,8 @@ static ssize_t cci5xx_pmu_global_event_show(struct device *dev,
 	struct dev_ext_attribute *eattr = container_of(attr,
 					struct dev_ext_attribute, attr);
 	/* Global events have single fixed source code */
-	return snprintf(buf, PAGE_SIZE, "event=0x%lx,source=0x%x\n",
-				(unsigned long)eattr->var, CCI5xx_PORT_GLOBAL);
+	return sysfs_emit(buf, "event=0x%lx,source=0x%x\n",
+			  (unsigned long)eattr->var, CCI5xx_PORT_GLOBAL);
 }
 
 /*
@@ -696,7 +696,7 @@ static ssize_t cci_pmu_format_show(struct device *dev,
 {
 	struct dev_ext_attribute *eattr = container_of(attr,
 				struct dev_ext_attribute, attr);
-	return snprintf(buf, PAGE_SIZE, "%s\n", (char *)eattr->var);
+	return sysfs_emit(buf, "%s\n", (char *)eattr->var);
 }
 
 static ssize_t cci_pmu_event_show(struct device *dev,
@@ -705,8 +705,8 @@ static ssize_t cci_pmu_event_show(struct device *dev,
 	struct dev_ext_attribute *eattr = container_of(attr,
 				struct dev_ext_attribute, attr);
 	/* source parameter is mandatory for normal PMU events */
-	return snprintf(buf, PAGE_SIZE, "source=?,event=0x%lx\n",
-					 (unsigned long)eattr->var);
+	return sysfs_emit(buf, "source=?,event=0x%lx\n",
+			  (unsigned long)eattr->var);
 }
 
 static int pmu_is_valid_counter(struct cci_pmu *cci_pmu, int idx)
diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
index a0a71c1..3a2ddc0 100644
--- a/drivers/perf/arm-ccn.c
+++ b/drivers/perf/arm-ccn.c
@@ -221,7 +221,7 @@ static ssize_t arm_ccn_pmu_format_show(struct device *dev,
 	struct dev_ext_attribute *ea = container_of(attr,
 			struct dev_ext_attribute, attr);
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", (char *)ea->var);
+	return sysfs_emit(buf, "%s\n", (char *)ea->var);
 }
 
 #define CCN_FORMAT_ATTR(_name, _config) \
@@ -476,7 +476,7 @@ static ssize_t arm_ccn_pmu_cmp_mask_show(struct device *dev,
 	struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev));
 	u64 *mask = arm_ccn_pmu_get_cmp_mask(ccn, attr->attr.name);
 
-	return mask ? snprintf(buf, PAGE_SIZE, "0x%016llx\n", *mask) : -EINVAL;
+	return mask ? sysfs_emit(buf, "0x%016llx\n", *mask) : -EINVAL;
 }
 
 static ssize_t arm_ccn_pmu_cmp_mask_store(struct device *dev,
diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c
index 1328159f..56a5c35 100644
--- a/drivers/perf/arm-cmn.c
+++ b/drivers/perf/arm-cmn.c
@@ -348,19 +348,19 @@ static ssize_t arm_cmn_event_show(struct device *dev,
 	eattr = container_of(attr, typeof(*eattr), attr);
 
 	if (eattr->type == CMN_TYPE_DTC)
-		return snprintf(buf, PAGE_SIZE, "type=0x%x\n", eattr->type);
+		return sysfs_emit(buf, "type=0x%x\n", eattr->type);
 
 	if (eattr->type == CMN_TYPE_WP)
-		return snprintf(buf, PAGE_SIZE,
-				"type=0x%x,eventid=0x%x,wp_dev_sel=?,wp_chn_sel=?,wp_grp=?,wp_val=?,wp_mask=?\n",
-				eattr->type, eattr->eventid);
+		return sysfs_emit(buf,
+				  "type=0x%x,eventid=0x%x,wp_dev_sel=?,wp_chn_sel=?,wp_grp=?,wp_val=?,wp_mask=?\n",
+				  eattr->type, eattr->eventid);
 
 	if (arm_cmn_is_occup_event(eattr->type, eattr->eventid))
-		return snprintf(buf, PAGE_SIZE, "type=0x%x,eventid=0x%x,occupid=0x%x\n",
-				eattr->type, eattr->eventid, eattr->occupid);
+		return sysfs_emit(buf, "type=0x%x,eventid=0x%x,occupid=0x%x\n",
+				  eattr->type, eattr->eventid, eattr->occupid);
 
-	return snprintf(buf, PAGE_SIZE, "type=0x%x,eventid=0x%x\n",
-			eattr->type, eattr->eventid);
+	return sysfs_emit(buf, "type=0x%x,eventid=0x%x\n", eattr->type,
+			  eattr->eventid);
 }
 
 static umode_t arm_cmn_event_attr_is_visible(struct kobject *kobj,
@@ -560,12 +560,12 @@ static ssize_t arm_cmn_format_show(struct device *dev,
 	int lo = __ffs(fmt->field), hi = __fls(fmt->field);
 
 	if (lo == hi)
-		return snprintf(buf, PAGE_SIZE, "config:%d\n", lo);
+		return sysfs_emit(buf, "config:%d\n", lo);
 
 	if (!fmt->config)
-		return snprintf(buf, PAGE_SIZE, "config:%d-%d\n", lo, hi);
+		return sysfs_emit(buf, "config:%d-%d\n", lo, hi);
 
-	return snprintf(buf, PAGE_SIZE, "config%d:%d-%d\n", fmt->config, lo, hi);
+	return sysfs_emit(buf, "config%d:%d-%d\n", fmt->config, lo, hi);
 }
 
 #define _CMN_FORMAT_ATTR(_name, _cfg, _fld)				\
diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
index 0459a34..196faea 100644
--- a/drivers/perf/arm_dsu_pmu.c
+++ b/drivers/perf/arm_dsu_pmu.c
@@ -136,8 +136,7 @@ static ssize_t dsu_pmu_sysfs_event_show(struct device *dev,
 {
 	struct dev_ext_attribute *eattr = container_of(attr,
 					struct dev_ext_attribute, attr);
-	return snprintf(buf, PAGE_SIZE, "event=0x%lx\n",
-					 (unsigned long)eattr->var);
+	return sysfs_emit(buf, "event=0x%lx\n", (unsigned long)eattr->var);
 }
 
 static ssize_t dsu_pmu_sysfs_format_show(struct device *dev,
@@ -146,7 +145,7 @@ static ssize_t dsu_pmu_sysfs_format_show(struct device *dev,
 {
 	struct dev_ext_attribute *eattr = container_of(attr,
 					struct dev_ext_attribute, attr);
-	return snprintf(buf, PAGE_SIZE, "%s\n", (char *)eattr->var);
+	return sysfs_emit(buf, "%s\n", (char *)eattr->var);
 }
 
 static ssize_t dsu_pmu_cpumask_show(struct device *dev,
diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index 8ff7a67..fa9dfbc 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -560,7 +560,7 @@ static ssize_t smmu_pmu_identifier_attr_show(struct device *dev,
 {
 	struct smmu_pmu *smmu_pmu = to_smmu_pmu(dev_get_drvdata(dev));
 
-	return snprintf(page, PAGE_SIZE, "0x%08x\n", smmu_pmu->iidr);
+	return sysfs_emit(page, "0x%08x\n", smmu_pmu->iidr);
 }
 
 static umode_t smmu_pmu_identifier_attr_visible(struct kobject *kobj,
diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index d3929cc..8a1e86a 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -126,8 +126,7 @@ static ssize_t arm_spe_pmu_cap_show(struct device *dev,
 		container_of(attr, struct dev_ext_attribute, attr);
 	int cap = (long)ea->var;
 
-	return snprintf(buf, PAGE_SIZE, "%u\n",
-		arm_spe_pmu_cap_get(spe_pmu, cap));
+	return sysfs_emit(buf, "%u\n", arm_spe_pmu_cap_get(spe_pmu, cap));
 }
 
 #define SPE_EXT_ATTR_ENTRY(_name, _func, _var)				\
diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c
index be1f26b..c126fd8 100644
--- a/drivers/perf/fsl_imx8_ddr_perf.c
+++ b/drivers/perf/fsl_imx8_ddr_perf.c
@@ -170,8 +170,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,
 		container_of(attr, struct dev_ext_attribute, attr);
 	int cap = (long)ea->var;
 
-	return snprintf(buf, PAGE_SIZE, "%u\n",
-			ddr_perf_filter_cap_get(pmu, cap));
+	return sysfs_emit(buf, "%u\n", ddr_perf_filter_cap_get(pmu, cap));
 }
 
 #define PERF_EXT_ATTR_ENTRY(_name, _func, _var)				\
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 9dbdc3f..64ccf5e 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -125,7 +125,7 @@ ssize_t hisi_uncore_pmu_identifier_attr_show(struct device *dev,
 {
 	struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
 
-	return snprintf(page, PAGE_SIZE, "0x%08x\n", hisi_pmu->identifier);
+	return sysfs_emit(page, "0x%08x\n", hisi_pmu->identifier);
 }
 EXPORT_SYMBOL_GPL(hisi_uncore_pmu_identifier_attr_show);
 
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17  9:41 [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit Qi Liu
  2021-03-17  9:41 ` [PATCH 1/3] drivers/perf: convert sysfs snprintf family " Qi Liu
@ 2021-03-17  9:41 ` Qi Liu
  2021-03-17 13:47   ` kernel test robot
                     ` (3 more replies)
  2021-03-17  9:41 ` [PATCH 3/3] drivers/perf: convert sysfs sprintf family to sysfs_emit Qi Liu
  2 siblings, 4 replies; 10+ messages in thread
From: Qi Liu @ 2021-03-17  9:41 UTC (permalink / raw)
  To: john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

Use the generic sysfs_emit_at() function take place of scnprintf()

Signed-off-by: Qi Liu <liuqi115@huawei.com>
---
 drivers/perf/arm-ccn.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
index 3a2ddc0..0588f29 100644
--- a/drivers/perf/arm-ccn.c
+++ b/drivers/perf/arm-ccn.c
@@ -328,41 +328,37 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
 			struct arm_ccn_pmu_event, attr);
 	ssize_t res;
 
-	res = scnprintf(buf, PAGE_SIZE, "type=0x%x", event->type);
+	res = sysfs_emit(buf, "type=0x%x", event->type);
 	if (event->event)
-		res += scnprintf(buf + res, PAGE_SIZE - res, ",event=0x%x",
+		res += sysfs_emit_at(buf + res, res, ",event=0x%x",
 				event->event);
 	if (event->def)
-		res += scnprintf(buf + res, PAGE_SIZE - res, ",%s",
-				event->def);
+		res += sysfs_emit_at(buf + res, res, ",%s", event->def);
 	if (event->mask)
-		res += scnprintf(buf + res, PAGE_SIZE - res, ",mask=0x%x",
-				event->mask);
+		res += sysfs_emit_at(buf + res, res, ",mask=0x%x", event->mask);
 
 	/* Arguments required by an event */
 	switch (event->type) {
 	case CCN_TYPE_CYCLES:
 		break;
 	case CCN_TYPE_XP:
-		res += scnprintf(buf + res, PAGE_SIZE - res,
-				",xp=?,vc=?");
+		res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
 		if (event->event == CCN_EVENT_WATCHPOINT)
-			res += scnprintf(buf + res, PAGE_SIZE - res,
+			res += sysfs_emit_at(buf + res, res,
 					",port=?,dir=?,cmp_l=?,cmp_h=?,mask=?");
 		else
-			res += scnprintf(buf + res, PAGE_SIZE - res,
-					",bus=?");
+			res += sysfs_emit_at(buf + res, res, ",bus=?");
 
 		break;
 	case CCN_TYPE_MN:
-		res += scnprintf(buf + res, PAGE_SIZE - res, ",node=%d", ccn->mn_id);
+		res += sysfs_emit_at(buf + res, res, ",node=%d", ccn->mn_id);
 		break;
 	default:
-		res += scnprintf(buf + res, PAGE_SIZE - res, ",node=?");
+		res += sysfs_emit_at(buf + res, res, ",node=?");
 		break;
 	}
 
-	res += scnprintf(buf + res, PAGE_SIZE - res, "\n");
+	res += sysfs_emit_at(buf + res, res, "\n");
 
 	return res;
 }
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] drivers/perf: convert sysfs sprintf family to sysfs_emit
  2021-03-17  9:41 [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit Qi Liu
  2021-03-17  9:41 ` [PATCH 1/3] drivers/perf: convert sysfs snprintf family " Qi Liu
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
@ 2021-03-17  9:41 ` Qi Liu
  2 siblings, 0 replies; 10+ messages in thread
From: Qi Liu @ 2021-03-17  9:41 UTC (permalink / raw)
  To: john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

sprintf does not know the PAGE_SIZE maximum of the temporary buffer
used for sysfs content and it's possible to overrun the buffer length.

Use sysfs_emit() function to ensures that no overrun is done.

Signed-off-by: Qi Liu <liuqi115@huawei.com>
---
 drivers/perf/arm_dmc620_pmu.c            | 2 +-
 drivers/perf/arm_smmuv3_pmu.c            | 2 +-
 drivers/perf/fsl_imx8_ddr_perf.c         | 4 ++--
 drivers/perf/hisilicon/hisi_uncore_pmu.c | 6 +++---
 drivers/perf/qcom_l2_pmu.c               | 2 +-
 drivers/perf/qcom_l3_pmu.c               | 4 ++--
 drivers/perf/thunderx2_pmu.c             | 4 ++--
 drivers/perf/xgene_pmu.c                 | 4 ++--
 8 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c
index 66ad5b3..8e9002a 100644
--- a/drivers/perf/arm_dmc620_pmu.c
+++ b/drivers/perf/arm_dmc620_pmu.c
@@ -113,7 +113,7 @@ dmc620_pmu_event_show(struct device *dev,
 
 	eattr = container_of(attr, typeof(*eattr), attr);
 
-	return sprintf(page, "event=0x%x,clkdiv2=0x%x\n", eattr->eventid, eattr->clkdiv2);
+	return sysfs_emit(page, "event=0x%x,clkdiv2=0x%x\n", eattr->eventid, eattr->clkdiv2);
 }
 
 #define DMC620_PMU_EVENT_ATTR(_name, _eventid, _clkdiv2)		\
diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index fa9dfbc..45a399f 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -506,7 +506,7 @@ static ssize_t smmu_pmu_event_show(struct device *dev,
 
 	pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
 
-	return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+	return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 #define SMMU_EVENT_ATTR(name, config) \
diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c
index c126fd8..2bbb931 100644
--- a/drivers/perf/fsl_imx8_ddr_perf.c
+++ b/drivers/perf/fsl_imx8_ddr_perf.c
@@ -110,7 +110,7 @@ static ssize_t ddr_perf_identifier_show(struct device *dev,
 {
 	struct ddr_pmu *pmu = dev_get_drvdata(dev);
 
-	return sprintf(page, "%s\n", pmu->devtype_data->identifier);
+	return sysfs_emit(page, "%s\n", pmu->devtype_data->identifier);
 }
 
 static umode_t ddr_perf_identifier_attr_visible(struct kobject *kobj,
@@ -219,7 +219,7 @@ ddr_pmu_event_show(struct device *dev, struct device_attribute *attr,
 	struct perf_pmu_events_attr *pmu_attr;
 
 	pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
-	return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+	return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 #define IMX8_DDR_PMU_EVENT_ATTR(_name, _id)				\
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 64ccf5e..5e2b5e1 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -33,7 +33,7 @@ ssize_t hisi_format_sysfs_show(struct device *dev,
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
 
-	return sprintf(buf, "%s\n", (char *)eattr->var);
+	return sysfs_emit(buf, "%s\n", (char *)eattr->var);
 }
 EXPORT_SYMBOL_GPL(hisi_format_sysfs_show);
 
@@ -47,7 +47,7 @@ ssize_t hisi_event_sysfs_show(struct device *dev,
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
 
-	return sprintf(page, "config=0x%lx\n", (unsigned long)eattr->var);
+	return sysfs_emit(page, "config=0x%lx\n", (unsigned long)eattr->var);
 }
 EXPORT_SYMBOL_GPL(hisi_event_sysfs_show);
 
@@ -59,7 +59,7 @@ ssize_t hisi_cpumask_sysfs_show(struct device *dev,
 {
 	struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
 
-	return sprintf(buf, "%d\n", hisi_pmu->on_cpu);
+	return sysfs_emit(buf, "%d\n", hisi_pmu->on_cpu);
 }
 EXPORT_SYMBOL_GPL(hisi_cpumask_sysfs_show);
 
diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c
index 8883af9..fc54a80 100644
--- a/drivers/perf/qcom_l2_pmu.c
+++ b/drivers/perf/qcom_l2_pmu.c
@@ -676,7 +676,7 @@ static ssize_t l2cache_pmu_event_show(struct device *dev,
 	struct perf_pmu_events_attr *pmu_attr;
 
 	pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
-	return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+	return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 #define L2CACHE_EVENT_ATTR(_name, _id)					     \
diff --git a/drivers/perf/qcom_l3_pmu.c b/drivers/perf/qcom_l3_pmu.c
index fb34b87..bba0780 100644
--- a/drivers/perf/qcom_l3_pmu.c
+++ b/drivers/perf/qcom_l3_pmu.c
@@ -615,7 +615,7 @@ static ssize_t l3cache_pmu_format_show(struct device *dev,
 	struct dev_ext_attribute *eattr;
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	return sprintf(buf, "%s\n", (char *) eattr->var);
+	return sysfs_emit(buf, "%s\n", (char *) eattr->var);
 }
 
 #define L3CACHE_PMU_FORMAT_ATTR(_name, _config)				      \
@@ -643,7 +643,7 @@ static ssize_t l3cache_pmu_event_show(struct device *dev,
 	struct perf_pmu_events_attr *pmu_attr;
 
 	pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
-	return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+	return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 #define L3CACHE_EVENT_ATTR(_name, _id)					     \
diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
index e116815..06a6d56 100644
--- a/drivers/perf/thunderx2_pmu.c
+++ b/drivers/perf/thunderx2_pmu.c
@@ -128,7 +128,7 @@ __tx2_pmu_##_var##_show(struct device *dev,				\
 			       char *page)				\
 {									\
 	BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);			\
-	return sprintf(page, _format "\n");				\
+	return sysfs_emit(page, _format "\n");				\
 }									\
 									\
 static struct device_attribute format_attr_##_var =			\
@@ -176,7 +176,7 @@ static ssize_t tx2_pmu_event_show(struct device *dev,
 	struct dev_ext_attribute *eattr;
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	return sprintf(buf, "event=0x%lx\n", (unsigned long) eattr->var);
+	return sysfs_emit(buf, "event=0x%lx\n", (unsigned long) eattr->var);
 }
 
 #define TX2_EVENT_ATTR(name, config) \
diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index 44faa51..ffe3bde 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -170,7 +170,7 @@ static ssize_t xgene_pmu_format_show(struct device *dev,
 	struct dev_ext_attribute *eattr;
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	return sprintf(buf, "%s\n", (char *) eattr->var);
+	return sysfs_emit(buf, "%s\n", (char *) eattr->var);
 }
 
 #define XGENE_PMU_FORMAT_ATTR(_name, _config)		\
@@ -281,7 +281,7 @@ static ssize_t xgene_pmu_event_show(struct device *dev,
 	struct dev_ext_attribute *eattr;
 
 	eattr = container_of(attr, struct dev_ext_attribute, attr);
-	return sprintf(buf, "config=0x%lx\n", (unsigned long) eattr->var);
+	return sysfs_emit(buf, "config=0x%lx\n", (unsigned long) eattr->var);
 }
 
 #define XGENE_PMU_EVENT_ATTR(_name, _config)		\
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
@ 2021-03-17 13:47   ` kernel test robot
  2021-03-17 14:29   ` kernel test robot
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2021-03-17 13:47 UTC (permalink / raw)
  To: Qi Liu, john.garry, zhangshaokun, will, mark.rutland
  Cc: kbuild-all, linux-arm-kernel, linux-kernel, linuxarm

[-- Attachment #1: Type: text/plain, Size: 6553 bytes --]

Hi Qi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.12-rc3 next-20210317]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1df27313f50a57497c1faeb6a6ae4ca939c85a7d
config: arm64-randconfig-r003-20210317 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/81a69a2f7fa73d0c41d699d6c6993c2594001241
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
        git checkout 81a69a2f7fa73d0c41d699d6c6993c2594001241
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/perf/arm-ccn.c: In function 'arm_ccn_pmu_event_show':
>> drivers/perf/arm-ccn.c:345:32: warning: passing argument 2 of 'sysfs_emit' makes pointer from integer without a cast [-Wint-conversion]
     345 |   res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
         |                                ^~~
         |                                |
         |                                ssize_t {aka long int}
   In file included from include/linux/kobject.h:20,
                    from include/linux/irqdesc.h:6,
                    from include/linux/irq.h:584,
                    from include/asm-generic/hardirq.h:17,
                    from arch/arm64/include/asm/hardirq.h:17,
                    from include/linux/hardirq.h:10,
                    from include/linux/interrupt.h:11,
                    from drivers/perf/arm-ccn.c:10:
   include/linux/sysfs.h:335:39: note: expected 'const char *' but argument is of type 'ssize_t' {aka 'long int'}
     335 | int sysfs_emit(char *buf, const char *fmt, ...);
         |                           ~~~~~~~~~~~~^~~


vim +/sysfs_emit +345 drivers/perf/arm-ccn.c

   274	
   275	#define CCN_EVENT_ATTR(_name) \
   276		__ATTR(_name, S_IRUGO, arm_ccn_pmu_event_show, NULL)
   277	
   278	/*
   279	 * Events defined in TRM for MN, HN-I and SBSX are actually watchpoints set on
   280	 * their ports in XP they are connected to. For the sake of usability they are
   281	 * explicitly defined here (and translated into a relevant watchpoint in
   282	 * arm_ccn_pmu_event_init()) so the user can easily request them without deep
   283	 * knowledge of the flit format.
   284	 */
   285	
   286	#define CCN_EVENT_MN(_name, _def, _mask) { .attr = CCN_EVENT_ATTR(mn_##_name), \
   287			.type = CCN_TYPE_MN, .event = CCN_EVENT_WATCHPOINT, \
   288			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, \
   289			.def = _def, .mask = _mask, }
   290	
   291	#define CCN_EVENT_HNI(_name, _def, _mask) { \
   292			.attr = CCN_EVENT_ATTR(hni_##_name), .type = CCN_TYPE_HNI, \
   293			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   294			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   295	
   296	#define CCN_EVENT_SBSX(_name, _def, _mask) { \
   297			.attr = CCN_EVENT_ATTR(sbsx_##_name), .type = CCN_TYPE_SBSX, \
   298			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   299			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   300	
   301	#define CCN_EVENT_HNF(_name, _event) { .attr = CCN_EVENT_ATTR(hnf_##_name), \
   302			.type = CCN_TYPE_HNF, .event = _event, }
   303	
   304	#define CCN_EVENT_XP(_name, _event) { .attr = CCN_EVENT_ATTR(xp_##_name), \
   305			.type = CCN_TYPE_XP, .event = _event, \
   306			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, }
   307	
   308	/*
   309	 * RN-I & RN-D (RN-D = RN-I + DVM) nodes have different type ID depending
   310	 * on configuration. One of them is picked to represent the whole group,
   311	 * as they all share the same event types.
   312	 */
   313	#define CCN_EVENT_RNI(_name, _event) { .attr = CCN_EVENT_ATTR(rni_##_name), \
   314			.type = CCN_TYPE_RNI_3P, .event = _event, }
   315	
   316	#define CCN_EVENT_SBAS(_name, _event) { .attr = CCN_EVENT_ATTR(sbas_##_name), \
   317			.type = CCN_TYPE_SBAS, .event = _event, }
   318	
   319	#define CCN_EVENT_CYCLES(_name) { .attr = CCN_EVENT_ATTR(_name), \
   320			.type = CCN_TYPE_CYCLES }
   321	
   322	
   323	static ssize_t arm_ccn_pmu_event_show(struct device *dev,
   324			struct device_attribute *attr, char *buf)
   325	{
   326		struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev));
   327		struct arm_ccn_pmu_event *event = container_of(attr,
   328				struct arm_ccn_pmu_event, attr);
   329		ssize_t res;
   330	
   331		res = sysfs_emit(buf, "type=0x%x", event->type);
   332		if (event->event)
   333			res += sysfs_emit_at(buf + res, res, ",event=0x%x",
   334					event->event);
   335		if (event->def)
   336			res += sysfs_emit_at(buf + res, res, ",%s", event->def);
   337		if (event->mask)
   338			res += sysfs_emit_at(buf + res, res, ",mask=0x%x", event->mask);
   339	
   340		/* Arguments required by an event */
   341		switch (event->type) {
   342		case CCN_TYPE_CYCLES:
   343			break;
   344		case CCN_TYPE_XP:
 > 345			res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
   346			if (event->event == CCN_EVENT_WATCHPOINT)
   347				res += sysfs_emit_at(buf + res, res,
   348						",port=?,dir=?,cmp_l=?,cmp_h=?,mask=?");
   349			else
   350				res += sysfs_emit_at(buf + res, res, ",bus=?");
   351	
   352			break;
   353		case CCN_TYPE_MN:
   354			res += sysfs_emit_at(buf + res, res, ",node=%d", ccn->mn_id);
   355			break;
   356		default:
   357			res += sysfs_emit_at(buf + res, res, ",node=?");
   358			break;
   359		}
   360	
   361		res += sysfs_emit_at(buf + res, res, "\n");
   362	
   363		return res;
   364	}
   365	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36853 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
  2021-03-17 13:47   ` kernel test robot
@ 2021-03-17 14:29   ` kernel test robot
  2021-03-17 14:57   ` Joe Perches
  2021-03-17 15:44   ` kernel test robot
  3 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2021-03-17 14:29 UTC (permalink / raw)
  To: Qi Liu, john.garry, zhangshaokun, will, mark.rutland
  Cc: kbuild-all, linux-arm-kernel, linux-kernel, linuxarm

[-- Attachment #1: Type: text/plain, Size: 5901 bytes --]

Hi Qi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.12-rc3 next-20210317]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1df27313f50a57497c1faeb6a6ae4ca939c85a7d
config: arm64-randconfig-s031-20210317 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-277-gc089cd2d-dirty
        # https://github.com/0day-ci/linux/commit/81a69a2f7fa73d0c41d699d6c6993c2594001241
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
        git checkout 81a69a2f7fa73d0c41d699d6c6993c2594001241
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> drivers/perf/arm-ccn.c:345:46: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected char const *fmt @@     got long [assigned] [usertype] res @@
   drivers/perf/arm-ccn.c:345:46: sparse:     expected char const *fmt
   drivers/perf/arm-ccn.c:345:46: sparse:     got long [assigned] [usertype] res

vim +345 drivers/perf/arm-ccn.c

   274	
   275	#define CCN_EVENT_ATTR(_name) \
   276		__ATTR(_name, S_IRUGO, arm_ccn_pmu_event_show, NULL)
   277	
   278	/*
   279	 * Events defined in TRM for MN, HN-I and SBSX are actually watchpoints set on
   280	 * their ports in XP they are connected to. For the sake of usability they are
   281	 * explicitly defined here (and translated into a relevant watchpoint in
   282	 * arm_ccn_pmu_event_init()) so the user can easily request them without deep
   283	 * knowledge of the flit format.
   284	 */
   285	
   286	#define CCN_EVENT_MN(_name, _def, _mask) { .attr = CCN_EVENT_ATTR(mn_##_name), \
   287			.type = CCN_TYPE_MN, .event = CCN_EVENT_WATCHPOINT, \
   288			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, \
   289			.def = _def, .mask = _mask, }
   290	
   291	#define CCN_EVENT_HNI(_name, _def, _mask) { \
   292			.attr = CCN_EVENT_ATTR(hni_##_name), .type = CCN_TYPE_HNI, \
   293			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   294			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   295	
   296	#define CCN_EVENT_SBSX(_name, _def, _mask) { \
   297			.attr = CCN_EVENT_ATTR(sbsx_##_name), .type = CCN_TYPE_SBSX, \
   298			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   299			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   300	
   301	#define CCN_EVENT_HNF(_name, _event) { .attr = CCN_EVENT_ATTR(hnf_##_name), \
   302			.type = CCN_TYPE_HNF, .event = _event, }
   303	
   304	#define CCN_EVENT_XP(_name, _event) { .attr = CCN_EVENT_ATTR(xp_##_name), \
   305			.type = CCN_TYPE_XP, .event = _event, \
   306			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, }
   307	
   308	/*
   309	 * RN-I & RN-D (RN-D = RN-I + DVM) nodes have different type ID depending
   310	 * on configuration. One of them is picked to represent the whole group,
   311	 * as they all share the same event types.
   312	 */
   313	#define CCN_EVENT_RNI(_name, _event) { .attr = CCN_EVENT_ATTR(rni_##_name), \
   314			.type = CCN_TYPE_RNI_3P, .event = _event, }
   315	
   316	#define CCN_EVENT_SBAS(_name, _event) { .attr = CCN_EVENT_ATTR(sbas_##_name), \
   317			.type = CCN_TYPE_SBAS, .event = _event, }
   318	
   319	#define CCN_EVENT_CYCLES(_name) { .attr = CCN_EVENT_ATTR(_name), \
   320			.type = CCN_TYPE_CYCLES }
   321	
   322	
   323	static ssize_t arm_ccn_pmu_event_show(struct device *dev,
   324			struct device_attribute *attr, char *buf)
   325	{
   326		struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev));
   327		struct arm_ccn_pmu_event *event = container_of(attr,
   328				struct arm_ccn_pmu_event, attr);
   329		ssize_t res;
   330	
   331		res = sysfs_emit(buf, "type=0x%x", event->type);
   332		if (event->event)
   333			res += sysfs_emit_at(buf + res, res, ",event=0x%x",
   334					event->event);
   335		if (event->def)
   336			res += sysfs_emit_at(buf + res, res, ",%s", event->def);
   337		if (event->mask)
   338			res += sysfs_emit_at(buf + res, res, ",mask=0x%x", event->mask);
   339	
   340		/* Arguments required by an event */
   341		switch (event->type) {
   342		case CCN_TYPE_CYCLES:
   343			break;
   344		case CCN_TYPE_XP:
 > 345			res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
   346			if (event->event == CCN_EVENT_WATCHPOINT)
   347				res += sysfs_emit_at(buf + res, res,
   348						",port=?,dir=?,cmp_l=?,cmp_h=?,mask=?");
   349			else
   350				res += sysfs_emit_at(buf + res, res, ",bus=?");
   351	
   352			break;
   353		case CCN_TYPE_MN:
   354			res += sysfs_emit_at(buf + res, res, ",node=%d", ccn->mn_id);
   355			break;
   356		default:
   357			res += sysfs_emit_at(buf + res, res, ",node=?");
   358			break;
   359		}
   360	
   361		res += sysfs_emit_at(buf + res, res, "\n");
   362	
   363		return res;
   364	}
   365	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 35436 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
  2021-03-17 13:47   ` kernel test robot
  2021-03-17 14:29   ` kernel test robot
@ 2021-03-17 14:57   ` Joe Perches
  2021-03-18  9:33     ` [Linuxarm] " liuqi (BA)
  2021-03-17 15:44   ` kernel test robot
  3 siblings, 1 reply; 10+ messages in thread
From: Joe Perches @ 2021-03-17 14:57 UTC (permalink / raw)
  To: Qi Liu, john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

On Wed, 2021-03-17 at 17:41 +0800, Qi Liu wrote:
> Use the generic sysfs_emit_at() function take place of scnprintf()
[]
> diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
[]
> @@ -328,41 +328,37 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
>  			struct arm_ccn_pmu_event, attr);
>  	ssize_t res;
>  
> 
> -	res = scnprintf(buf, PAGE_SIZE, "type=0x%x", event->type);
> +	res = sysfs_emit(buf, "type=0x%x", event->type);
>  	if (event->event)
> -		res += scnprintf(buf + res, PAGE_SIZE - res, ",event=0x%x",
> +		res += sysfs_emit_at(buf + res, res, ",event=0x%x",
>  				event->event);

sysfs_emit_at should always use buf, not buf + offset.
res should be int and is the offset from buf for the output

so the form should be similar to

	int len;

	len = sysfs_emit(buf, "type=0x%x", event->type);
	if (event->event) {
		len += sysfs_emit_at(buf, len, ",event=0x%x", event->event);

		etc...



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
                     ` (2 preceding siblings ...)
  2021-03-17 14:57   ` Joe Perches
@ 2021-03-17 15:44   ` kernel test robot
  3 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2021-03-17 15:44 UTC (permalink / raw)
  To: Qi Liu, john.garry, zhangshaokun, will, mark.rutland
  Cc: kbuild-all, clang-built-linux, linux-arm-kernel, linux-kernel, linuxarm

[-- Attachment #1: Type: text/plain, Size: 6121 bytes --]

Hi Qi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.12-rc3 next-20210317]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1df27313f50a57497c1faeb6a6ae4ca939c85a7d
config: arm-randconfig-r036-20210317 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 8ef111222a3dd12a9175f69c3bff598c46e8bdf7)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/0day-ci/linux/commit/81a69a2f7fa73d0c41d699d6c6993c2594001241
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Qi-Liu/drivers-perf-convert-sysfs-sprintf-snprintf-scnprintf-to-sysfs_emit/20210317-174750
        git checkout 81a69a2f7fa73d0c41d699d6c6993c2594001241
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/perf/arm-ccn.c:345:32: warning: incompatible integer to pointer conversion passing 'ssize_t' (aka 'int') to parameter of type 'const char *' [-Wint-conversion]
                   res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
                                                ^~~
   include/linux/sysfs.h:335:39: note: passing argument to parameter 'fmt' here
   int sysfs_emit(char *buf, const char *fmt, ...);
                                         ^
   1 warning generated.


vim +345 drivers/perf/arm-ccn.c

   274	
   275	#define CCN_EVENT_ATTR(_name) \
   276		__ATTR(_name, S_IRUGO, arm_ccn_pmu_event_show, NULL)
   277	
   278	/*
   279	 * Events defined in TRM for MN, HN-I and SBSX are actually watchpoints set on
   280	 * their ports in XP they are connected to. For the sake of usability they are
   281	 * explicitly defined here (and translated into a relevant watchpoint in
   282	 * arm_ccn_pmu_event_init()) so the user can easily request them without deep
   283	 * knowledge of the flit format.
   284	 */
   285	
   286	#define CCN_EVENT_MN(_name, _def, _mask) { .attr = CCN_EVENT_ATTR(mn_##_name), \
   287			.type = CCN_TYPE_MN, .event = CCN_EVENT_WATCHPOINT, \
   288			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, \
   289			.def = _def, .mask = _mask, }
   290	
   291	#define CCN_EVENT_HNI(_name, _def, _mask) { \
   292			.attr = CCN_EVENT_ATTR(hni_##_name), .type = CCN_TYPE_HNI, \
   293			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   294			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   295	
   296	#define CCN_EVENT_SBSX(_name, _def, _mask) { \
   297			.attr = CCN_EVENT_ATTR(sbsx_##_name), .type = CCN_TYPE_SBSX, \
   298			.event = CCN_EVENT_WATCHPOINT, .num_ports = CCN_NUM_XP_PORTS, \
   299			.num_vcs = CCN_NUM_VCS, .def = _def, .mask = _mask, }
   300	
   301	#define CCN_EVENT_HNF(_name, _event) { .attr = CCN_EVENT_ATTR(hnf_##_name), \
   302			.type = CCN_TYPE_HNF, .event = _event, }
   303	
   304	#define CCN_EVENT_XP(_name, _event) { .attr = CCN_EVENT_ATTR(xp_##_name), \
   305			.type = CCN_TYPE_XP, .event = _event, \
   306			.num_ports = CCN_NUM_XP_PORTS, .num_vcs = CCN_NUM_VCS, }
   307	
   308	/*
   309	 * RN-I & RN-D (RN-D = RN-I + DVM) nodes have different type ID depending
   310	 * on configuration. One of them is picked to represent the whole group,
   311	 * as they all share the same event types.
   312	 */
   313	#define CCN_EVENT_RNI(_name, _event) { .attr = CCN_EVENT_ATTR(rni_##_name), \
   314			.type = CCN_TYPE_RNI_3P, .event = _event, }
   315	
   316	#define CCN_EVENT_SBAS(_name, _event) { .attr = CCN_EVENT_ATTR(sbas_##_name), \
   317			.type = CCN_TYPE_SBAS, .event = _event, }
   318	
   319	#define CCN_EVENT_CYCLES(_name) { .attr = CCN_EVENT_ATTR(_name), \
   320			.type = CCN_TYPE_CYCLES }
   321	
   322	
   323	static ssize_t arm_ccn_pmu_event_show(struct device *dev,
   324			struct device_attribute *attr, char *buf)
   325	{
   326		struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev));
   327		struct arm_ccn_pmu_event *event = container_of(attr,
   328				struct arm_ccn_pmu_event, attr);
   329		ssize_t res;
   330	
   331		res = sysfs_emit(buf, "type=0x%x", event->type);
   332		if (event->event)
   333			res += sysfs_emit_at(buf + res, res, ",event=0x%x",
   334					event->event);
   335		if (event->def)
   336			res += sysfs_emit_at(buf + res, res, ",%s", event->def);
   337		if (event->mask)
   338			res += sysfs_emit_at(buf + res, res, ",mask=0x%x", event->mask);
   339	
   340		/* Arguments required by an event */
   341		switch (event->type) {
   342		case CCN_TYPE_CYCLES:
   343			break;
   344		case CCN_TYPE_XP:
 > 345			res += sysfs_emit(buf + res, res, ",xp=?,vc=?");
   346			if (event->event == CCN_EVENT_WATCHPOINT)
   347				res += sysfs_emit_at(buf + res, res,
   348						",port=?,dir=?,cmp_l=?,cmp_h=?,mask=?");
   349			else
   350				res += sysfs_emit_at(buf + res, res, ",bus=?");
   351	
   352			break;
   353		case CCN_TYPE_MN:
   354			res += sysfs_emit_at(buf + res, res, ",node=%d", ccn->mn_id);
   355			break;
   356		default:
   357			res += sysfs_emit_at(buf + res, res, ",node=?");
   358			break;
   359		}
   360	
   361		res += sysfs_emit_at(buf + res, res, "\n");
   362	
   363		return res;
   364	}
   365	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 25421 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Linuxarm] Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-17 14:57   ` Joe Perches
@ 2021-03-18  9:33     ` liuqi (BA)
  2021-03-18 13:33       ` Joe Perches
  0 siblings, 1 reply; 10+ messages in thread
From: liuqi (BA) @ 2021-03-18  9:33 UTC (permalink / raw)
  To: Joe Perches, john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm



On 2021/3/17 22:57, Joe Perches wrote:
> On Wed, 2021-03-17 at 17:41 +0800, Qi Liu wrote:
>> Use the generic sysfs_emit_at() function take place of scnprintf()
> []
>> diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
> []
>> @@ -328,41 +328,37 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
>>   			struct arm_ccn_pmu_event, attr);
>>   	ssize_t res;
>>   
>>
>> -	res = scnprintf(buf, PAGE_SIZE, "type=0x%x", event->type);
>> +	res = sysfs_emit(buf, "type=0x%x", event->type);
>>   	if (event->event)
>> -		res += scnprintf(buf + res, PAGE_SIZE - res, ",event=0x%x",
>> +		res += sysfs_emit_at(buf + res, res, ",event=0x%x",
>>   				event->event);
> 
> sysfs_emit_at should always use buf, not buf + offset.
> res should be int and is the offset from buf for the output
> 
> so the form should be similar to
> 
> 	int len;
> 
> 	len = sysfs_emit(buf, "type=0x%x", event->type);
> 	if (event->event) {
> 		len += sysfs_emit_at(buf, len, ",event=0x%x", event->event);
> 
> 		etc...
> 
Hi Joe,

I'll fix the use of sysfs_emit_at in next version, thanks.
But I think it's better to keep the res as ssize_t, as the return value 
of this function is ssize_t.

Thanks,

Qi

> _______________________________________________
> Linuxarm mailing list -- linuxarm@openeuler.org
> To unsubscribe send an email to linuxarm-leave@openeuler.org
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Linuxarm] Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
  2021-03-18  9:33     ` [Linuxarm] " liuqi (BA)
@ 2021-03-18 13:33       ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2021-03-18 13:33 UTC (permalink / raw)
  To: liuqi (BA), john.garry, zhangshaokun, will, mark.rutland
  Cc: linux-arm-kernel, linux-kernel, linuxarm

On Thu, 2021-03-18 at 17:33 +0800, liuqi (BA) wrote:
> On 2021/3/17 22:57, Joe Perches wrote:
> > On Wed, 2021-03-17 at 17:41 +0800, Qi Liu wrote:
> > > Use the generic sysfs_emit_at() function take place of scnprintf()
> > []
> > > diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
> > []
> > > @@ -328,41 +328,37 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
> > >   			struct arm_ccn_pmu_event, attr);
> > >   	ssize_t res;
> > >   
> > > 
> > > 
> > > -	res = scnprintf(buf, PAGE_SIZE, "type=0x%x", event->type);
> > > +	res = sysfs_emit(buf, "type=0x%x", event->type);
> > >   	if (event->event)
> > > -		res += scnprintf(buf + res, PAGE_SIZE - res, ",event=0x%x",
> > > +		res += sysfs_emit_at(buf + res, res, ",event=0x%x",
> > >   				event->event);
> > 
> > sysfs_emit_at should always use buf, not buf + offset.
> > res should be int and is the offset from buf for the output
> > 
> > so the form should be similar to
> > 
> > 	int len;
> > 
> > 	len = sysfs_emit(buf, "type=0x%x", event->type);
> > 	if (event->event) {
> > 		len += sysfs_emit_at(buf, len, ",event=0x%x", event->event);
> > 
> > 		etc...
> > 
> Hi Joe,
> 
> I'll fix the use of sysfs_emit_at in next version, thanks.
> But I think it's better to keep the res as ssize_t, as the return value 
> of this function is ssize_t.

The 2nd arg of sysfs_emit_at is int.
On 64 bit platforms, ssize_t is 64 bit while int is 32.

If res (or len) is ssize_t, there could be a lot of -Wconversion warnings
like this produced when using make W=

warning: conversion from ‘ssize_t’ {aka ‘long int’} to ‘int’ may change value [-Wconversion]
  262 |  len += sysfs_emit_at(buf, len, "\n");



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-18 13:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17  9:41 [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit Qi Liu
2021-03-17  9:41 ` [PATCH 1/3] drivers/perf: convert sysfs snprintf family " Qi Liu
2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
2021-03-17 13:47   ` kernel test robot
2021-03-17 14:29   ` kernel test robot
2021-03-17 14:57   ` Joe Perches
2021-03-18  9:33     ` [Linuxarm] " liuqi (BA)
2021-03-18 13:33       ` Joe Perches
2021-03-17 15:44   ` kernel test robot
2021-03-17  9:41 ` [PATCH 3/3] drivers/perf: convert sysfs sprintf family to sysfs_emit Qi Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).