]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgxset.c: fix checkpatch.pl warnings
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 16 Mar 2022 15:45:01 +0000 (21:15 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 16 Mar 2022 21:38:20 +0000 (15:38 -0600)
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types.  It
also introduces reverse xmas tree local variable declarations and header
file reordering.

In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 1 errors, 20 warnings, 385 lines checked

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgxset.c

index 47fecab8d7dec90c6cd90e9afab1b0d257bccf10..26703f1bf3da2a31687e9ffcb34f3cc522350f48 100644 (file)
@@ -5,19 +5,17 @@
  * Copyright (c) 2021-2022 Oracle and/or its affiliates.
  * Author: Tom Hromatka <tom.hromatka@oracle.com>
  */
+#include "tools-common.h"
+#include "abstraction-common.h"
 
 #include <libcgroup.h>
 #include <libcgroup-internal.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <getopt.h>
-
-#include "tools-common.h"
-
-#include "abstraction-common.h"
+#include <stdio.h>
 
 #define FL_RULES       1
 #define FL_COPY                2
@@ -27,14 +25,13 @@ enum {
 };
 
 #ifndef UNIT_TEST
-static struct option const long_options[] =
-{
-       {"v1", no_argument, NULL, '1'},
-       {"v2", no_argument, NULL, '2'},
-       {"ignore-unmappable", no_argument, NULL, 'i'},
-       {"rule", required_argument, NULL, 'r'},
-       {"help", no_argument, NULL, 'h'},
-       {"copy-from", required_argument, NULL, COPY_FROM_OPTION},
+static const struct option long_options[] = {
+       {"v1",                        no_argument, NULL, '1'},
+       {"v2",                        no_argument, NULL, '2'},
+       {"ignore-unmappable",         no_argument, NULL, 'i'},
+       {"rule",                required_argument, NULL, 'r'},
+       {"help",                      no_argument, NULL, 'h'},
+       {"copy-from",           required_argument, NULL, COPY_FROM_OPTION},
        {NULL, 0, NULL, 0}
 };
 
@@ -42,8 +39,8 @@ int flags; /* used input method */
 
 static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX])
 {
-       int ret = 0;
        struct cgroup *src_cgroup;
+       int ret = 0;
 
        /* create source cgroup */
        src_cgroup = cgroup_new_cgroup(src_cg_path);
@@ -56,7 +53,7 @@ static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX]
        /* copy the name-version values to the cgroup structure */
        ret = cgroup_get_cgroup(src_cgroup);
        if (ret != 0) {
-               fprintf(stderr, "cgroup %s error: %s \n",
+               fprintf(stderr, "cgroup %s error: %s\n",
                        src_cg_path, cgroup_strerror(ret));
                goto scgroup_err;
        }
@@ -65,32 +62,34 @@ static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX]
 
 scgroup_err:
        cgroup_free(&src_cgroup);
+
        return NULL;
 }
 
-
 static void usage(int status, const char *program_name)
 {
        if (status != 0) {
-               fprintf(stderr, "Wrong input parameters,"
-                       " try %s --help' for more information.\n",
+               fprintf(stderr, "Wrong input parameters,");
+               fprintf(stderr, " try %s --help' for more information.\n",
                        program_name);
                return;
        }
-       printf("Usage: %s [-r <name=value>] <cgroup_path> ...\n"
-               "   or: %s --copy-from <source_cgroup_path> "\
-               "<cgroup_path> ...\n", program_name, program_name);
+
+       printf("Usage: %s [-r <name=value>] <cgroup_path> ...\n",
+              program_name);
+       printf("   or: %s --copy-from <source_cgroup_path> ", program_name);
+       printf("<cgroup_path> ...\n");
        printf("Set the parameters of given cgroup(s)\n");
-       printf("  -1, --v1                      Provided parameters are in "
-              "v1 format\n");
-       printf("  -2, --v2                      Provided parameters are in "
-              "v2 format\n");
-       printf("  -i, --ignore-unmappable       Do not return an error for settings "
-              "that cannot be converted\n");
-       printf("  -r, --variable <name>                 Define parameter "\
-               "to set\n");
-       printf("  --copy-from <source_cgroup_path>      Control group whose "\
-               "parameters will be copied\n");
+       printf("  -1, --v1                      Provided parameters are in ");
+       printf("v1 format\n");
+       printf("  -2, --v2                      Provided parameters are in ");
+       printf("v2 format\n");
+       printf("  -i, --ignore-unmappable       Do not return an error for settings ");
+       printf("that cannot be converted\n");
+       printf("  -r, --variable <name>                 Define parameter ");
+       printf("to set\n");
+       printf("  --copy-from <source_cgroup_path>      Control group whose ");
+       printf("parameters will be copied\n");
 }
 #endif /* !UNIT_TEST */
 
@@ -98,8 +97,8 @@ STATIC int parse_r_flag(const char * const program_name,
                        const char * const name_value_str,
                        struct control_value * const name_value)
 {
-       int ret = 0;
        char *copy, *buf;
+       int ret = 0;
 
        copy = strdup(name_value_str);
        if (copy == NULL) {
@@ -111,8 +110,7 @@ STATIC int parse_r_flag(const char * const program_name,
        /* parse optarg value */
        buf = strtok(copy, "=");
        if (buf == NULL) {
-               fprintf(stderr, "%s: "
-                       "wrong parameter of option -r: %s\n",
+               fprintf(stderr, "%s: wrong parameter of option -r: %s\n",
                        program_name, optarg);
                ret = -1;
                goto err;
@@ -122,14 +120,14 @@ STATIC int parse_r_flag(const char * const program_name,
        name_value->name[FILENAME_MAX-1] = '\0';
 
        buf = strchr(name_value_str, '=');
-       /* we don't need to check the return value of strchr because we
+       /*
+        * we don't need to check the return value of strchr because we
         * know there's already an '=' character in the string.
         */
        buf++;
 
        if (strlen(buf) == 0) {
-               fprintf(stderr, "%s: "
-                       "wrong parameter of option -r: %s\n",
+               fprintf(stderr, "%s: wrong parameter of option -r: %s\n",
                        program_name, optarg);
                ret = -1;
                goto err;
@@ -148,24 +146,24 @@ err:
 #ifndef UNIT_TEST
 int main(int argc, char *argv[])
 {
-       int ret = 0;
-       int c;
-
        struct control_value *name_value = NULL;
        int nv_number = 0;
        int nv_max = 0;
 
+       struct cgroup *converted_src_cgroup;
        char src_cg_path[FILENAME_MAX];
        struct cgroup *src_cgroup;
        struct cgroup *cgroup;
-       struct cgroup *converted_src_cgroup;
+
        enum cg_version_t src_version = CGROUP_UNK;
        bool ignore_unmappable = false;
+       int ret = 0;
+       int c;
 
        /* no parametr on input */
        if (argc < 2) {
-               fprintf(stderr, "Usage is %s -r <name=value> "
-                       "<relative path to cgroup>\n", argv[0]);
+               fprintf(stderr, "Usage is %s -r <name=value> ", argv[0]);
+               fprintf(stderr, "<relative path to cgroup>\n");
                return -1;
        }
 
@@ -177,8 +175,6 @@ int main(int argc, char *argv[])
                        usage(0, argv[0]);
                        ret = 0;
                        goto err;
-                       break;
-
                case 'r':
                        if ((flags &  FL_COPY) != 0) {
                                usage(1, argv[0]);
@@ -187,17 +183,18 @@ int main(int argc, char *argv[])
                        }
                        flags |= FL_RULES;
 
-                       /* add name-value pair to buffer
-                               (= name_value variable) */
+                       /*
+                        * add name-value pair to buffer
+                        * (= name_value variable)
+                        */
                        if (nv_number >= nv_max) {
                                nv_max += CG_NV_MAX;
                                name_value = (struct control_value *)
                                        realloc(name_value,
                                        nv_max * sizeof(struct control_value));
                                if (!name_value) {
-                                       fprintf(stderr, "%s: "
-                                               "not enough memory\n",
-                                               argv[0]);
+                                       fprintf(stderr, "%s: ", argv[0]);
+                                       fprintf(stderr, "not enough memory\n");
                                        ret = -1;
                                        goto err;
                                }
@@ -233,7 +230,6 @@ int main(int argc, char *argv[])
                        usage(1, argv[0]);
                        ret = -1;
                        goto err;
-                       break;
                }
        }
 
@@ -261,7 +257,7 @@ int main(int argc, char *argv[])
        /* copy the name-value pairs from -r options */
        if ((flags & FL_RULES) != 0) {
                src_cgroup = create_cgroup_from_name_value_pairs(
-                       "tmp", name_value, nv_number);
+                                               "tmp", name_value, nv_number);
                if (src_cgroup == NULL)
                        goto err;
        }
@@ -286,7 +282,7 @@ int main(int argc, char *argv[])
                /* copy the values from the source cgroup to new one */
                ret = cgroup_copy_cgroup(cgroup, src_cgroup);
                if (ret != 0) {
-                       fprintf(stderr, "%s: cgroup %s error: %s \n",
+                       fprintf(stderr, "%s: cgroup %s error: %s\n",
                                argv[0], src_cg_path, cgroup_strerror(ret));
                        goto cgroup_free_err;
                }
@@ -300,7 +296,8 @@ int main(int argc, char *argv[])
                ret = cgroup_convert_cgroup(converted_src_cgroup, CGROUP_DISK,
                                            src_cgroup, src_version);
                if (ret == ECGNOVERSIONCONVERT && ignore_unmappable)
-                       /* The user has specified that we should ignore
+                       /*
+                        * The user has specified that we should ignore
                         * any errors due to being unable to map from v1 to
                         * v2 or vice versa
                         */
@@ -314,7 +311,7 @@ int main(int argc, char *argv[])
                /* modify cgroup based on values of the new one */
                ret = cgroup_modify_cgroup(cgroup);
                if (ret) {
-                       fprintf(stderr, "%s: cgroup modify error: %s \n",
+                       fprintf(stderr, "%s: cgroup modify error: %s\n",
                                argv[0], cgroup_strerror(ret));
                        goto cgroup_free_err;
                }
@@ -327,9 +324,9 @@ cgroup_free_err:
        if (cgroup)
                cgroup_free(&cgroup);
        cgroup_free(&src_cgroup);
-
 err:
        free(name_value);
+
        return ret;
 }
 #endif /* !UNIT_TEST */
@@ -350,7 +347,8 @@ int cgroup_cgxset(const struct cgroup * const cgroup,
        ret = cgroup_convert_cgroup(converted_cgroup, CGROUP_DISK,
                                    cgroup, version);
        if (ret == ECGNOVERSIONCONVERT && ignore_unmappable)
-               /* The user has specified that we should ignore
+               /*
+                * The user has specified that we should ignore
                 * any errors due to being unable to map from v1 to
                 * v2 or vice versa
                 */
@@ -360,9 +358,8 @@ int cgroup_cgxset(const struct cgroup * const cgroup,
 
        /* modify cgroup based on values of the new one */
        ret = cgroup_modify_cgroup(converted_cgroup);
-       if (ret) {
+       if (ret)
                goto err;
-       }
 
 err:
        if (converted_cgroup)