]> git.baikalelectronics.ru Git - kernel.git/commit
HID: hid-debug: clean up snprintf() checks in hid_resolv_usage()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 16 Sep 2021 13:21:54 +0000 (16:21 +0300)
committerJiri Kosina <jkosina@suse.cz>
Wed, 22 Sep 2021 09:49:17 +0000 (11:49 +0200)
commit1416af4d8960b6f51061d1bd4af2f83be5f1a275
tree67d6803feceac1578b37d77849e024a114afe170
parent3ce837aacc2d2a9caf574a6af6fc114f2e0eb1fe
HID: hid-debug: clean up snprintf() checks in hid_resolv_usage()

The snprintf() limits are complicated and slightly wrong when it does:

max(0, HID_DEBUG_BUFSIZE - len - 1)

The "- 1" should not be there.  It means we can't use the last
byte of the buffer.  If we change the first snprintf() to scnprintf()
then we can remove the max().

At the start of the function the strlen(buf) is going always going to
be < HID_DEBUG_BUFSIZE so that is safe.  If it were > HID_DEBUG_BUFSIZE
then that would result in a WARN().

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-debug.c