]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/resctrl: Fix null pointer dereference on open failed
authorColin Ian King <colin.i.king@gmail.com>
Tue, 26 Apr 2022 12:25:31 +0000 (13:25 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 26 Apr 2022 15:20:00 +0000 (09:20 -0600)
commit258e83a17029fc0633be73a6001b70ab0473e708
tree33b334994df733d8f2a6f69acdca66d1312c0072
parent173466d64491ef2e32cff48b88ce699e56a3d31a
selftests/resctrl: Fix null pointer dereference on open failed

Currently if opening /dev/null fails to open then file pointer fp
is null and further access to fp via fprintf will cause a null
pointer dereference. Fix this by returning a negative error value
when a null fp is detected.

Detected using cppcheck static analysis:
tools/testing/selftests/resctrl/fill_buf.c:124:6: note: Assuming
that condition '!fp' is not redundant
 if (!fp)
     ^
tools/testing/selftests/resctrl/fill_buf.c:126:10: note: Null
pointer dereference
 fprintf(fp, "Sum: %d ", ret);

Fixes: a0ccd5372f3a ("selftests/resctrl: Add built in benchmark")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/fill_buf.c