From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============3890760925013184507==" 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:56 +0800 Message-ID: <20200703113556.GA18857@bf425ecdd42c> In-Reply-To: <202007031941.um9p1FRJ%lkp@intel.com> List-Id: To: kbuild@lists.01.org --===============3890760925013184507== 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: Keith Busch CC: Jens Axboe CC: Christoph Hellwig CC: Sagi Grimberg CC: linux-nvme(a)lists.infradead.org CC: linux-kernel(a)vger.kernel.org From: kernel test robot drivers/nvme/host/core.c:2671:8-16: WARNING: use scnprintf or sprintf drivers/nvme/host/core.c:3388:8-16: WARNING: use scnprintf or sprintf drivers/nvme/host/core.c:3378:8-16: WARNING: use scnprintf or sprintf drivers/nvme/host/core.c:3368:8-16: WARNING: use scnprintf or sprintf drivers/nvme/host/core.c:3335: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! core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2668,7 +2668,7 @@ static ssize_t nvme_subsys_show_nqn(stru struct nvme_subsystem *subsys =3D container_of(dev, struct nvme_subsystem, dev); = - return snprintf(buf, PAGE_SIZE, "%s\n", subsys->subnqn); + return scnprintf(buf, PAGE_SIZE, "%s\n", subsys->subnqn); } static SUBSYS_ATTR_RO(subsysnqn, S_IRUGO, nvme_subsys_show_nqn); = @@ -3332,7 +3332,7 @@ static ssize_t nvme_sysfs_show_transport { struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); = - return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->ops->name); + return scnprintf(buf, PAGE_SIZE, "%s\n", ctrl->ops->name); } static DEVICE_ATTR(transport, S_IRUGO, nvme_sysfs_show_transport, NULL); = @@ -3365,7 +3365,7 @@ static ssize_t nvme_sysfs_show_subsysnqn { struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); = - return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->subsys->subnqn); + return scnprintf(buf, PAGE_SIZE, "%s\n", ctrl->subsys->subnqn); } static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL); = @@ -3375,7 +3375,7 @@ static ssize_t nvme_sysfs_show_hostnqn(s { struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); = - return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn); + return scnprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn); } static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL); = @@ -3385,7 +3385,7 @@ static ssize_t nvme_sysfs_show_hostid(st { struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); = - return snprintf(buf, PAGE_SIZE, "%pU\n", &ctrl->opts->host->id); + return scnprintf(buf, PAGE_SIZE, "%pU\n", &ctrl->opts->host->id); } static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL); =20 --===============3890760925013184507==--