kselftest/cgroup: fix variable dereferenced before check warning
authorRoman Gushchin <guro@fb.com>
Tue, 22 May 2018 10:10:31 +0000 (11:10 +0100)
committerShuah Khan (Samsung OSG) <shuah@kernel.org>
Wed, 30 May 2018 21:29:07 +0000 (15:29 -0600)
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>
tools/testing/selftests/cgroup/cgroup_util.c

index 41cc3b5..b69bdeb 100644 (file)
@@ -59,8 +59,7 @@ char *cg_name(const char *root, const char *name)
        size_t len = strlen(root) + strlen(name) + 2;
        char *ret = malloc(len);
 
-       if (name)
-               snprintf(ret, len, "%s/%s", root, name);
+       snprintf(ret, len, "%s/%s", root, name);
 
        return ret;
 }
@@ -70,8 +69,7 @@ char *cg_name_indexed(const char *root, const char *name, int index)
        size_t len = strlen(root) + strlen(name) + 10;
        char *ret = malloc(len);
 
-       if (name)
-               snprintf(ret, len, "%s/%s_%d", root, name, index);
+       snprintf(ret, len, "%s/%s_%d", root, name, index);
 
        return ret;
 }