]> git.baikalelectronics.ru Git - kernel.git/commit
video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 16 Sep 2021 13:29:19 +0000 (16:29 +0300)
committerHelge Deller <deller@gmx.de>
Sun, 30 Jan 2022 20:19:22 +0000 (21:19 +0100)
commitae883ea39fe7041699923781167e6258064687d8
treef054c00089fc29c67e6b9d16961ed1fa8ab4c3b5
parent506e0a7aebffa37315c26cbd450a4cf2662d7ad9
video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name()

This code has two bugs:
1) "cnt" is 255 but the size of the buffer is 256 so the last byte is
   not used.
2) If we try to print more than 255 characters then "cnt" will be
   negative and that will trigger a WARN() in snprintf(). The fix for
   this is to use scnprintf() instead of snprintf().

We can re-write this code to be cleaner:
1) Rename "offset" to "off" because that's shorter.
2) Get rid of the "cnt" variable and just use "size - off" directly.
3) Get rid of the "read" variable and just increment "off" directly.

Fixes: 258fd0f0f8d2 ("fbdev: Add VESA Coordinated Video Timings (CVT) support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/fbcvt.c