Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftest/cgroup: fix variable dereferenced before check warning

cg_name(const char *root, const char *name) is always called with
non-empty root and name arguments, so there is no sense in checking
it in the function body (after using in strlen()).

Signed-off-by: Roman Gushchin <guro@fb.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>

authored by

Roman Gushchin and committed by
Shuah Khan (Samsung OSG)
adb31be4 7b04d1e9

+2 -4
+2 -4
tools/testing/selftests/cgroup/cgroup_util.c
··· 59 59 size_t len = strlen(root) + strlen(name) + 2; 60 60 char *ret = malloc(len); 61 61 62 - if (name) 63 - snprintf(ret, len, "%s/%s", root, name); 62 + snprintf(ret, len, "%s/%s", root, name); 64 63 65 64 return ret; 66 65 } ··· 69 70 size_t len = strlen(root) + strlen(name) + 10; 70 71 char *ret = malloc(len); 71 72 72 - if (name) 73 - snprintf(ret, len, "%s/%s_%d", root, name, index); 73 + snprintf(ret, len, "%s/%s_%d", root, name, index); 74 74 75 75 return ret; 76 76 }