drivers/perf: convert sysfs sprintf family to sysfs_emit
authorQi Liu <liuqi115@huawei.com>
Fri, 19 Mar 2021 10:04:33 +0000 (18:04 +0800)
committerWill Deacon <will@kernel.org>
Thu, 25 Mar 2021 12:55:44 +0000 (12:55 +0000)
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>
Link: https://lore.kernel.org/r/1616148273-16374-4-git-send-email-liuqi115@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm_dmc620_pmu.c
drivers/perf/arm_smmuv3_pmu.c
drivers/perf/fsl_imx8_ddr_perf.c
drivers/perf/hisilicon/hisi_uncore_pmu.c
drivers/perf/qcom_l2_pmu.c
drivers/perf/qcom_l3_pmu.c
drivers/perf/thunderx2_pmu.c
drivers/perf/xgene_pmu.c

index f2a85500258d0bca8bfb57f01bd0d1b4f545d456..b6c2511d59af27862baffdb9028da48f96197bb2 100644 (file)
@@ -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)               \
index fa9dfbcbd68386dd9508f3c7cbeac205346e6fbc..45a399f20afa436a25a497cdc8ba93624f36bf85 100644 (file)
@@ -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) \
index c126fd8703eec4e2bb7b669c93e40f08a5ea4ee6..2bbb9318806495687e2d9ef9dceb968a1cab1dbf 100644 (file)
@@ -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)                            \
index 64ccf5ed00e30f7fca56b5eaefb1afbd2e313ca4..5e2b5e12777f5dfcfe39ef1bf5900a8b32708cb4 100644 (file)
@@ -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);
 
index 8883af955a2a3d2f8e59896b11c6d467b726491f..fc54a80f9c5cfc940cacd684c3b1386f92cac619 100644 (file)
@@ -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)                                      \
index fb34b87b94712bf1766ca4775fa13a5290fa7f74..bba078077c93cb417e794f32f5fe8494cfc5c8a5 100644 (file)
@@ -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)                                      \
index e116815fa8092fcc1bc96e7957ccf32ac628ceb8..06a6d569b0b56e556ea4917e4717d44821794fb6 100644 (file)
@@ -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) \
index 44faa51ba799291c707242a5327fdc300d84e692..ffe3bdeec8459efe26f0f3823b6e210c09c16b7a 100644 (file)
@@ -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)           \