Skip to content

Commit 7501153

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool, Input: cyapa - Remove undefined behavior in cyapa_update_fw_store()
In cyapa_update_fw_store(), if 'count' is zero, the write to fw_name[count-1] underflows the array. Presumably that's not possible in normal operation, as its caller sysfs_kf_write() already checks for zero. Regardless it's a good idea to check for the error explicitly and avoid undefined behavior. Fixes the following warning with an UBSAN kernel: vmlinux.o: warning: objtool: .text.cyapa_update_fw_store: unexpected end of section Reported-by: kernel test robot <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Dmitry Torokhov <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/73ae0bb3c656735890d914b74c9d6bb40c25d3cd.1742852847.git.jpoimboe@kernel.org Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
1 parent 72c774a commit 7501153

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/input/mouse/cyapa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,8 @@ static ssize_t cyapa_update_fw_store(struct device *dev,
10801080
char fw_name[NAME_MAX];
10811081
int ret, error;
10821082

1083-
if (count >= NAME_MAX) {
1084-
dev_err(dev, "File name too long\n");
1083+
if (!count || count >= NAME_MAX) {
1084+
dev_err(dev, "Bad file name size\n");
10851085
return -EINVAL;
10861086
}
10871087

0 commit comments

Comments
 (0)