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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:40:06 +0000 (14:40 +0200)
commitbf4bad1114a396f441daa83a0e368b9a6a9ec8e6
tree8f91bbd0aed4146888d22acf2934c906b0e3df51
parent6de6a64f23a67c16369f3d02c914e10df14c7332
video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name()

[ Upstream commit 78482af095abd9f4f29f1aa3fe575d25c6ae3028 ]

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: 96fe6a2109db ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/video/fbdev/core/fbcvt.c