Re: [kbuild-all] Re: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings
On Tue, 8 Sep 2020, Bartlomiej Zolnierkiewicz wrote: > > Hi, > > On 8/10/20 11:21 AM, kernel test robot wrote: > > From: kernel test robot > > > > drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or > > sprintf > > drivers/video/fbdev/core/fbcon.c:3484: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: abfc19ff202d ("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/torvalds/linux.git > > master > > head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7 > > commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add > > device_attr_show script > > > > Please take the patch only if it's a positive warning. Thanks! > > > > fbcon.c |4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > --- a/drivers/video/fbdev/core/fbcon.c > > +++ b/drivers/video/fbdev/core/fbcon.c > > @@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device > > rotate = fbcon_get_rotate(info); > > err: > > console_unlock(); > > - return snprintf(buf, PAGE_SIZE, "%d\n", rotate); > > + return scnprintf(buf, PAGE_SIZE, "%d\n", rotate); > > buf length is at least PAGE_SIZE and rotate val is an int so > shouldn't this be converted to use sprintf() instead? The rule is evolving in this direction. Thanks for the feedback. julia > > > } > > > > static ssize_t show_cursor_blink(struct device *device, > > @@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct > > blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0; > > err: > > console_unlock(); > > - return snprintf(buf, PAGE_SIZE, "%d\n", blink); > > + return scnprintf(buf, PAGE_SIZE, "%d\n", blink); > > ditto for blink val > > > } > > > > static ssize_t store_cursor_blink(struct device *device, > > > > Best regards, > -- > Bartlomiej Zolnierkiewicz > Samsung R Institute Poland > Samsung Electronics > ___ > kbuild-all mailing list -- kbuild-...@lists.01.org > To unsubscribe send an email to kbuild-all-le...@lists.01.org >
Re: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings
Hi, On 8/10/20 11:21 AM, kernel test robot wrote: > From: kernel test robot > > drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or sprintf > drivers/video/fbdev/core/fbcon.c:3484: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: abfc19ff202d ("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/torvalds/linux.git > master > head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7 > commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add > device_attr_show script > > Please take the patch only if it's a positive warning. Thanks! > > fbcon.c |4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > --- a/drivers/video/fbdev/core/fbcon.c > +++ b/drivers/video/fbdev/core/fbcon.c > @@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device > rotate = fbcon_get_rotate(info); > err: > console_unlock(); > - return snprintf(buf, PAGE_SIZE, "%d\n", rotate); > + return scnprintf(buf, PAGE_SIZE, "%d\n", rotate); buf length is at least PAGE_SIZE and rotate val is an int so shouldn't this be converted to use sprintf() instead? > } > > static ssize_t show_cursor_blink(struct device *device, > @@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct > blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0; > err: > console_unlock(); > - return snprintf(buf, PAGE_SIZE, "%d\n", blink); > + return scnprintf(buf, PAGE_SIZE, "%d\n", blink); ditto for blink val > } > > static ssize_t store_cursor_blink(struct device *device, > Best regards, -- Bartlomiej Zolnierkiewicz Samsung R Institute Poland Samsung Electronics
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-kone.c:406:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kone.c:397:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kone.c:438:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kone.c:550:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kone.c:448:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kone.c:429: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-kone.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -394,7 +394,7 @@ static ssize_t kone_sysfs_show_actual_pr { struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); } static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL); @@ -403,7 +403,7 @@ static ssize_t kone_sysfs_show_actual_dp { struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); + return scnprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); } static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); @@ -426,7 +426,7 @@ static ssize_t kone_sysfs_show_weight(st if (retval) return retval; - return snprintf(buf, PAGE_SIZE, "%d\n", weight); + return scnprintf(buf, PAGE_SIZE, "%d\n", weight); } static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL); @@ -435,7 +435,7 @@ static ssize_t kone_sysfs_show_firmware_ { struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); + return scnprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); } static DEVICE_ATTR(firmware_version, 0440, kone_sysfs_show_firmware_version, NULL); @@ -445,7 +445,7 @@ static ssize_t kone_sysfs_show_tcu(struc { struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); + return scnprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu); } static int kone_tcu_command(struct usb_device *usb_dev, int number) @@ -547,7 +547,7 @@ static ssize_t kone_sysfs_show_startup_p { struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile); } static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/acpi/dock.c:563:8-16: WARNING: use scnprintf or sprintf drivers/acpi/dock.c:544:8-16: WARNING: use scnprintf or sprintf drivers/acpi/dock.c:495:8-16: WARNING: use scnprintf or sprintf drivers/acpi/dock.c:506: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! dock.c |8 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -492,7 +492,7 @@ static ssize_t show_docked(struct device struct acpi_device *adev = NULL; acpi_bus_get_device(dock_station->handle, ); - return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev)); + return scnprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev)); } static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); @@ -503,7 +503,7 @@ static ssize_t show_flags(struct device struct device_attribute *attr, char *buf) { struct dock_station *dock_station = dev->platform_data; - return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); + return scnprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); } static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); @@ -541,7 +541,7 @@ static ssize_t show_dock_uid(struct devi if (ACPI_FAILURE(status)) return 0; - return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf); + return scnprintf(buf, PAGE_SIZE, "%llx\n", lbuf); } static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); @@ -560,7 +560,7 @@ static ssize_t show_dock_type(struct dev else type = "unknown"; - return snprintf(buf, PAGE_SIZE, "%s\n", type); + return scnprintf(buf, PAGE_SIZE, "%s\n", type); } static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-pyra.c:289:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-pyra.c:306:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-pyra.c:327: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-pyra.c |6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -286,7 +286,7 @@ static ssize_t pyra_sysfs_show_actual_cp { struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); + return scnprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); } static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL); @@ -303,7 +303,7 @@ static ssize_t pyra_sysfs_show_actual_pr , PYRA_SIZE_SETTINGS); mutex_unlock(>pyra_lock); - return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile); } static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL); static DEVICE_ATTR(startup_profile, 0440, pyra_sysfs_show_actual_profile, NULL); @@ -324,7 +324,7 @@ static ssize_t pyra_sysfs_show_firmware_ , PYRA_SIZE_INFO); mutex_unlock(>pyra_lock); - return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); + return scnprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } static DEVICE_ATTR(firmware_version, 0440, pyra_sysfs_show_firmware_version, NULL);
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-koneplus.c:247:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-koneplus.c:314: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-koneplus.c |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hid/hid-roccat-koneplus.c +++ b/drivers/hid/hid-roccat-koneplus.c @@ -244,7 +244,7 @@ static ssize_t koneplus_sysfs_show_actua { struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile); } static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev, @@ -311,7 +311,7 @@ static ssize_t koneplus_sysfs_show_firmw , KONEPLUS_SIZE_INFO); mutex_unlock(>koneplus_lock); - return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); + return scnprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } static DEVICE_ATTR(firmware_version, 0440, koneplus_sysfs_show_firmware_version, NULL);
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-arvo.c:149:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-arvo.c:95:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-arvo.c:45: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-arvo.c |6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/hid/hid-roccat-arvo.c +++ b/drivers/hid/hid-roccat-arvo.c @@ -42,7 +42,7 @@ static ssize_t arvo_sysfs_show_mode_key( if (retval) return retval; - return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.state); + return scnprintf(buf, PAGE_SIZE, "%d\n", temp_buf.state); } static ssize_t arvo_sysfs_set_mode_key(struct device *dev, @@ -92,7 +92,7 @@ static ssize_t arvo_sysfs_show_key_mask( if (retval) return retval; - return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.key_mask); + return scnprintf(buf, PAGE_SIZE, "%d\n", temp_buf.key_mask); } static ssize_t arvo_sysfs_set_key_mask(struct device *dev, @@ -146,7 +146,7 @@ static ssize_t arvo_sysfs_show_actual_pr struct arvo_device *arvo = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", arvo->actual_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", arvo->actual_profile); } static ssize_t arvo_sysfs_set_actual_profile(struct device *dev,
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-sony.c:611:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-sony.c:648:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-sony.c:660: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-sony.c |6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -608,7 +608,7 @@ static ssize_t ds4_show_poll_interval(st struct hid_device *hdev = to_hid_device(dev); struct sony_sc *sc = hid_get_drvdata(hdev); - return snprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval); + return scnprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval); } static ssize_t ds4_store_poll_interval(struct device *dev, @@ -645,7 +645,7 @@ static ssize_t sony_show_firmware_versio struct hid_device *hdev = to_hid_device(dev); struct sony_sc *sc = hid_get_drvdata(hdev); - return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version); + return scnprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version); } static DEVICE_ATTR(firmware_version, 0444, sony_show_firmware_version, NULL); @@ -657,7 +657,7 @@ static ssize_t sony_show_hardware_versio struct hid_device *hdev = to_hid_device(dev); struct sony_sc *sc = hid_get_drvdata(hdev); - return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version); + return scnprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version); } static DEVICE_ATTR(hardware_version, 0444, sony_show_hardware_version, NULL);
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-isku.c:66: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-isku.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/hid/hid-roccat-isku.c +++ b/drivers/hid/hid-roccat-isku.c @@ -63,7 +63,7 @@ static ssize_t isku_sysfs_show_actual_pr { struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", isku->actual_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", isku->actual_profile); } static ssize_t isku_sysfs_set_actual_profile(struct device *dev,
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/hid/hid-roccat-kovaplus.c:330:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kovaplus.c:277:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kovaplus.c:339:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kovaplus.c:349:8-16: WARNING: use scnprintf or sprintf drivers/hid/hid-roccat-kovaplus.c:370: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: abfc19ff202d ("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/torvalds/linux.git master head: 7c2a69f610e64c8dec6a06a66e721f4ce1dd783a commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! hid-roccat-kovaplus.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c @@ -274,7 +274,7 @@ static ssize_t kovaplus_sysfs_show_actua { struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile); + return scnprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile); } static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev, @@ -327,7 +327,7 @@ static ssize_t kovaplus_sysfs_show_actua { struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi); + return scnprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi); } static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL); @@ -336,7 +336,7 @@ static ssize_t kovaplus_sysfs_show_actua { struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity); + return scnprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity); } static DEVICE_ATTR(actual_sensitivity_x, 0440, kovaplus_sysfs_show_actual_sensitivity_x, NULL); @@ -346,7 +346,7 @@ static ssize_t kovaplus_sysfs_show_actua { struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); - return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity); + return scnprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity); } static DEVICE_ATTR(actual_sensitivity_y, 0440, kovaplus_sysfs_show_actual_sensitivity_y, NULL); @@ -367,7 +367,7 @@ static ssize_t kovaplus_sysfs_show_firmw , KOVAPLUS_SIZE_INFO); mutex_unlock(>kovaplus_lock); - return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); + return scnprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } static DEVICE_ATTR(firmware_version, 0440, kovaplus_sysfs_show_firmware_version, NULL);
[PATCH] coccinelle: api: fix device_attr_show.cocci warnings
From: kernel test robot drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or sprintf drivers/video/fbdev/core/fbcon.c:3484: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: abfc19ff202d ("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/torvalds/linux.git master head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7 commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script Please take the patch only if it's a positive warning. Thanks! fbcon.c |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device rotate = fbcon_get_rotate(info); err: console_unlock(); - return snprintf(buf, PAGE_SIZE, "%d\n", rotate); + return scnprintf(buf, PAGE_SIZE, "%d\n", rotate); } static ssize_t show_cursor_blink(struct device *device, @@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0; err: console_unlock(); - return snprintf(buf, PAGE_SIZE, "%d\n", blink); + return scnprintf(buf, PAGE_SIZE, "%d\n", blink); } static ssize_t store_cursor_blink(struct device *device,