Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/perf: convert sysfs snprintf family to sysfs_emit

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>
Link: https://lore.kernel.org/r/1616148273-16374-2-git-send-email-liuqi115@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Zihao Tang and committed by
Will Deacon
700a9cf0 1e28eed1

+25 -28
+6 -6
drivers/perf/arm-cci.c
··· 306 306 { 307 307 struct dev_ext_attribute *eattr = container_of(attr, 308 308 struct dev_ext_attribute, attr); 309 - return snprintf(buf, PAGE_SIZE, "config=0x%lx\n", (unsigned long)eattr->var); 309 + return sysfs_emit(buf, "config=0x%lx\n", (unsigned long)eattr->var); 310 310 } 311 311 312 312 static int cci400_get_event_idx(struct cci_pmu *cci_pmu, ··· 525 525 struct dev_ext_attribute *eattr = container_of(attr, 526 526 struct dev_ext_attribute, attr); 527 527 /* Global events have single fixed source code */ 528 - return snprintf(buf, PAGE_SIZE, "event=0x%lx,source=0x%x\n", 529 - (unsigned long)eattr->var, CCI5xx_PORT_GLOBAL); 528 + return sysfs_emit(buf, "event=0x%lx,source=0x%x\n", 529 + (unsigned long)eattr->var, CCI5xx_PORT_GLOBAL); 530 530 } 531 531 532 532 /* ··· 696 696 { 697 697 struct dev_ext_attribute *eattr = container_of(attr, 698 698 struct dev_ext_attribute, attr); 699 - return snprintf(buf, PAGE_SIZE, "%s\n", (char *)eattr->var); 699 + return sysfs_emit(buf, "%s\n", (char *)eattr->var); 700 700 } 701 701 702 702 static ssize_t cci_pmu_event_show(struct device *dev, ··· 705 705 struct dev_ext_attribute *eattr = container_of(attr, 706 706 struct dev_ext_attribute, attr); 707 707 /* source parameter is mandatory for normal PMU events */ 708 - return snprintf(buf, PAGE_SIZE, "source=?,event=0x%lx\n", 709 - (unsigned long)eattr->var); 708 + return sysfs_emit(buf, "source=?,event=0x%lx\n", 709 + (unsigned long)eattr->var); 710 710 } 711 711 712 712 static int pmu_is_valid_counter(struct cci_pmu *cci_pmu, int idx)
+2 -2
drivers/perf/arm-ccn.c
··· 221 221 struct dev_ext_attribute *ea = container_of(attr, 222 222 struct dev_ext_attribute, attr); 223 223 224 - return snprintf(buf, PAGE_SIZE, "%s\n", (char *)ea->var); 224 + return sysfs_emit(buf, "%s\n", (char *)ea->var); 225 225 } 226 226 227 227 #define CCN_FORMAT_ATTR(_name, _config) \ ··· 476 476 struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev)); 477 477 u64 *mask = arm_ccn_pmu_get_cmp_mask(ccn, attr->attr.name); 478 478 479 - return mask ? snprintf(buf, PAGE_SIZE, "0x%016llx\n", *mask) : -EINVAL; 479 + return mask ? sysfs_emit(buf, "0x%016llx\n", *mask) : -EINVAL; 480 480 } 481 481 482 482 static ssize_t arm_ccn_pmu_cmp_mask_store(struct device *dev,
+11 -11
drivers/perf/arm-cmn.c
··· 348 348 eattr = container_of(attr, typeof(*eattr), attr); 349 349 350 350 if (eattr->type == CMN_TYPE_DTC) 351 - return snprintf(buf, PAGE_SIZE, "type=0x%x\n", eattr->type); 351 + return sysfs_emit(buf, "type=0x%x\n", eattr->type); 352 352 353 353 if (eattr->type == CMN_TYPE_WP) 354 - return snprintf(buf, PAGE_SIZE, 355 - "type=0x%x,eventid=0x%x,wp_dev_sel=?,wp_chn_sel=?,wp_grp=?,wp_val=?,wp_mask=?\n", 356 - eattr->type, eattr->eventid); 354 + return sysfs_emit(buf, 355 + "type=0x%x,eventid=0x%x,wp_dev_sel=?,wp_chn_sel=?,wp_grp=?,wp_val=?,wp_mask=?\n", 356 + eattr->type, eattr->eventid); 357 357 358 358 if (arm_cmn_is_occup_event(eattr->type, eattr->eventid)) 359 - return snprintf(buf, PAGE_SIZE, "type=0x%x,eventid=0x%x,occupid=0x%x\n", 360 - eattr->type, eattr->eventid, eattr->occupid); 359 + return sysfs_emit(buf, "type=0x%x,eventid=0x%x,occupid=0x%x\n", 360 + eattr->type, eattr->eventid, eattr->occupid); 361 361 362 - return snprintf(buf, PAGE_SIZE, "type=0x%x,eventid=0x%x\n", 363 - eattr->type, eattr->eventid); 362 + return sysfs_emit(buf, "type=0x%x,eventid=0x%x\n", eattr->type, 363 + eattr->eventid); 364 364 } 365 365 366 366 static umode_t arm_cmn_event_attr_is_visible(struct kobject *kobj, ··· 560 560 int lo = __ffs(fmt->field), hi = __fls(fmt->field); 561 561 562 562 if (lo == hi) 563 - return snprintf(buf, PAGE_SIZE, "config:%d\n", lo); 563 + return sysfs_emit(buf, "config:%d\n", lo); 564 564 565 565 if (!fmt->config) 566 - return snprintf(buf, PAGE_SIZE, "config:%d-%d\n", lo, hi); 566 + return sysfs_emit(buf, "config:%d-%d\n", lo, hi); 567 567 568 - return snprintf(buf, PAGE_SIZE, "config%d:%d-%d\n", fmt->config, lo, hi); 568 + return sysfs_emit(buf, "config%d:%d-%d\n", fmt->config, lo, hi); 569 569 } 570 570 571 571 #define _CMN_FORMAT_ATTR(_name, _cfg, _fld) \
+2 -3
drivers/perf/arm_dsu_pmu.c
··· 136 136 { 137 137 struct dev_ext_attribute *eattr = container_of(attr, 138 138 struct dev_ext_attribute, attr); 139 - return snprintf(buf, PAGE_SIZE, "event=0x%lx\n", 140 - (unsigned long)eattr->var); 139 + return sysfs_emit(buf, "event=0x%lx\n", (unsigned long)eattr->var); 141 140 } 142 141 143 142 static ssize_t dsu_pmu_sysfs_format_show(struct device *dev, ··· 145 146 { 146 147 struct dev_ext_attribute *eattr = container_of(attr, 147 148 struct dev_ext_attribute, attr); 148 - return snprintf(buf, PAGE_SIZE, "%s\n", (char *)eattr->var); 149 + return sysfs_emit(buf, "%s\n", (char *)eattr->var); 149 150 } 150 151 151 152 static ssize_t dsu_pmu_cpumask_show(struct device *dev,
+1 -1
drivers/perf/arm_smmuv3_pmu.c
··· 560 560 { 561 561 struct smmu_pmu *smmu_pmu = to_smmu_pmu(dev_get_drvdata(dev)); 562 562 563 - return snprintf(page, PAGE_SIZE, "0x%08x\n", smmu_pmu->iidr); 563 + return sysfs_emit(page, "0x%08x\n", smmu_pmu->iidr); 564 564 } 565 565 566 566 static umode_t smmu_pmu_identifier_attr_visible(struct kobject *kobj,
+1 -2
drivers/perf/arm_spe_pmu.c
··· 126 126 container_of(attr, struct dev_ext_attribute, attr); 127 127 int cap = (long)ea->var; 128 128 129 - return snprintf(buf, PAGE_SIZE, "%u\n", 130 - arm_spe_pmu_cap_get(spe_pmu, cap)); 129 + return sysfs_emit(buf, "%u\n", arm_spe_pmu_cap_get(spe_pmu, cap)); 131 130 } 132 131 133 132 #define SPE_EXT_ATTR_ENTRY(_name, _func, _var) \
+1 -2
drivers/perf/fsl_imx8_ddr_perf.c
··· 170 170 container_of(attr, struct dev_ext_attribute, attr); 171 171 int cap = (long)ea->var; 172 172 173 - return snprintf(buf, PAGE_SIZE, "%u\n", 174 - ddr_perf_filter_cap_get(pmu, cap)); 173 + return sysfs_emit(buf, "%u\n", ddr_perf_filter_cap_get(pmu, cap)); 175 174 } 176 175 177 176 #define PERF_EXT_ATTR_ENTRY(_name, _func, _var) \
+1 -1
drivers/perf/hisilicon/hisi_uncore_pmu.c
··· 125 125 { 126 126 struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev)); 127 127 128 - return snprintf(page, PAGE_SIZE, "0x%08x\n", hisi_pmu->identifier); 128 + return sysfs_emit(page, "0x%08x\n", hisi_pmu->identifier); 129 129 } 130 130 EXPORT_SYMBOL_GPL(hisi_uncore_pmu_identifier_attr_show); 131 131