From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============2000137841205546352==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Thu, 25 Jun 2020 11:41:58 +0800 Message-ID: <20200625034158.GA130987@d009c32cc965> In-Reply-To: <202006251140.yIwaPtnF%lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============2000137841205546352== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable CC: kbuild-all(a)lists.01.org TO: Denis Efremov CC: Julia Lawall CC: Peter Zijlstra CC: Ingo Molnar CC: Arnaldo Carvalho de Melo CC: Mark Rutland CC: Alexander Shishkin CC: Jiri Olsa CC: Namhyung Kim CC: Thomas Gleixner From: kernel test robot arch/x86/events/core.c:2219:8-16: WARNING: use scnprintf or sprintf arch/x86/events/core.c:2277:8-16: WARNING: use scnprintf or sprintf From Documentation/filesystems/sysfs.txt: show() must not use snprintf() when formatting the value to be returned to user space. If you can guarantee that an overflow will never happen you can use sprintf() otherwise you must use scnprintf(). Generated by: scripts/coccinelle/api/device_attr_show.cocci Fixes: 988676da8375 ("coccinelle: api: add device_attr_show script") CC: Denis Efremov Signed-off-by: kernel test robot --- tree: https://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux.git f= or-5.9 head: 9bba51dafe9fe6bdaa0ef557ea322e981e85bf4c commit: 988676da837516bbfafda5478472fd4265f0de4e [1/3] coccinelle: api: add= device_attr_show script :::::: branch date: 8 hours ago :::::: commit date: 8 hours ago Please take the patch only if it's a positive warning. Thanks! core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2216,7 +2216,7 @@ static ssize_t get_attr_rdpmc(struct dev struct device_attribute *attr, char *buf) { - return snprintf(buf, 40, "%d\n", x86_pmu.attr_rdpmc); + return scnprintf(buf, 40, "%d\n", x86_pmu.attr_rdpmc); } = static ssize_t set_attr_rdpmc(struct device *cdev, @@ -2274,7 +2274,7 @@ static ssize_t max_precise_show(struct d struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu_max_precise()); + return scnprintf(buf, PAGE_SIZE, "%d\n", x86_pmu_max_precise()); } = static DEVICE_ATTR_RO(max_precise); --===============2000137841205546352==--