From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============1428739229660536576==" MIME-Version: 1.0 From: kernel test robot Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings Date: Fri, 03 Jul 2020 19:35:50 +0800 Message-ID: <20200703113550.GA18509@bf425ecdd42c> In-Reply-To: <202007031941.um9p1FRJ%lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============1428739229660536576== 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: Alex Deucher CC: "Christian K=C3=B6nig" CC: David Airlie CC: Daniel Vetter CC: Evan Quan CC: Hawking Zhang CC: Andrey Grodzovsky CC: Monk Liu From: kernel test robot drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:134:8-16: WARNING: use scnprintf= or sprintf drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:158:8-16: WARNING: use scnprintf= or sprintf drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:180:8-16: WARNING: use scnprintf= or sprintf drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:202: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: 5502a4eb3af819792a6c43b418c401f613a39d02 commit: 988676da837516bbfafda5478472fd4265f0de4e [1/3] coccinelle: api: add= device_attr_show script :::::: branch date: 8 days ago :::::: commit date: 9 days ago Please take the patch only if it's a positive warning. Thanks! amdgpu_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -131,7 +131,7 @@ static ssize_t amdgpu_device_get_pcie_re struct amdgpu_device *adev =3D ddev->dev_private; uint64_t cnt =3D amdgpu_asic_get_pcie_replay_count(adev); = - return snprintf(buf, PAGE_SIZE, "%llu\n", cnt); + return scnprintf(buf, PAGE_SIZE, "%llu\n", cnt); } = static DEVICE_ATTR(pcie_replay_count, S_IRUGO, @@ -155,7 +155,7 @@ static ssize_t amdgpu_device_get_product struct drm_device *ddev =3D dev_get_drvdata(dev); struct amdgpu_device *adev =3D ddev->dev_private; = - return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_name); + return scnprintf(buf, PAGE_SIZE, "%s\n", adev->product_name); } = static DEVICE_ATTR(product_name, S_IRUGO, @@ -177,7 +177,7 @@ static ssize_t amdgpu_device_get_product struct drm_device *ddev =3D dev_get_drvdata(dev); struct amdgpu_device *adev =3D ddev->dev_private; = - return snprintf(buf, PAGE_SIZE, "%s\n", adev->product_number); + return scnprintf(buf, PAGE_SIZE, "%s\n", adev->product_number); } = static DEVICE_ATTR(product_number, S_IRUGO, @@ -199,7 +199,7 @@ static ssize_t amdgpu_device_get_serial_ struct drm_device *ddev =3D dev_get_drvdata(dev); struct amdgpu_device *adev =3D ddev->dev_private; = - return snprintf(buf, PAGE_SIZE, "%s\n", adev->serial); + return scnprintf(buf, PAGE_SIZE, "%s\n", adev->serial); } = static DEVICE_ATTR(serial_number, S_IRUGO, --===============1428739229660536576==--