• Colin Ian King's avatar
    selftests/resctrl: Fix null pointer dereference on open failed · c7b607fa
    Colin Ian King authored
    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: a2561b12 ("selftests/resctrl: Add built in benchmark")
    Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
    Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
    c7b607fa
fill_buf.c 3.95 KB