From: Kamalesh Babulal Date: Wed, 16 Mar 2022 15:24:30 +0000 (+0530) Subject: cgdelete.c: fix checkpatch.pl warnings X-Git-Tag: v3.0~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=323653409e99a29f02c6d6cad5161750323d71ea;p=thirdparty%2Flibcgroup.git cgdelete.c: fix checkpatch.pl warnings 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, 6 warnings, 303 lines checked Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c index 653f6cdb..790c910b 100644 --- a/src/tools/cgdelete.c +++ b/src/tools/cgdelete.c @@ -5,23 +5,22 @@ * Authors: Jan Safranek */ +#include "tools-common.h" + #include #include -#include #include #include -#include #include #include +#include +#include -#include "tools-common.h" - -static struct option const long_options[] = -{ - {"recursive", no_argument, NULL, 'r'}, - {"help", no_argument, NULL, 'h'}, - {"group", required_argument, NULL, 'g'}, +static const struct option long_options[] = { + {"recursive", no_argument, NULL, 'r'}, + {"help", no_argument, NULL, 'h'}, + {"group", required_argument, NULL, 'g'}, {NULL, 0, NULL, 0} }; @@ -35,19 +34,20 @@ struct ext_cgroup_record { 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 [-h] [-r] [[-g] :] ...\n", program_name); printf("Remove control group(s)\n"); - printf(" -g : Control group to be removed "\ - "(-g is optional)\n"); + printf(" -g : Control group to be removed "); + printf("(-g is optional)\n"); printf(" -h, --help Display this help\n"); - printf(" -r, --recursive Recursively remove "\ - "all subgroups\n"); + printf(" -r, --recursive Recursively remove "); + printf("all subgroups\n"); } /* @@ -56,15 +56,16 @@ static void usage(int status, const char *program_name) * cgroup and hierarchy number is same */ static int skip_add_controller(int counter, int *skip, - struct ext_cgroup_record *ecg_list) + struct ext_cgroup_record *ecg_list) { - int k; struct controller_data info; void *handle; int ret = 0; + int k; /* find out hierarchy number of added cgroup */ ecg_list[counter].h_number = 0; + ret = cgroup_get_all_controller_begin(&handle, &info); while (ret == 0) { if (!strcmp(info.name, ecg_list[counter].name)) { @@ -89,10 +90,10 @@ static int skip_add_controller(int counter, int *skip, *skip = 0; for (k = 0; k < counter; k++) { if ((!strcmp(ecg_list[k].name, ecg_list[counter].name)) && - (ecg_list[k].h_number == ecg_list[counter].h_number)) { + (ecg_list[k].h_number == ecg_list[counter].h_number)) { /* we found a control group in the same hierarchy */ if (strcmp(ecg_list[k].controller, - ecg_list[counter].controller)) { + ecg_list[counter].controller)) { /* * it is a different controller -> * if there is not one cgroup for the same @@ -116,26 +117,23 @@ static int skip_add_controller(int counter, int *skip, int main(int argc, char *argv[]) { - int ret = 0; - int i, j; - int c; - int flags = 0; - int final_ret = 0; + struct cgroup_group_spec **cgroup_list = NULL; + struct ext_cgroup_record *ecg_list = NULL; + struct cgroup_controller *cgc; + struct cgroup *cgroup; + int final_ret = 0; int counter = 0; + int flags = 0; int max = 0; - struct ext_cgroup_record *ecg_list = NULL; + int ret = 0; + int i, j, c; int skip; - struct cgroup_group_spec **cgroup_list = NULL; - struct cgroup *cgroup; - struct cgroup_controller *cgc; - /* initialize libcg */ ret = cgroup_init(); if (ret) { - fprintf(stderr, "%s: " - "libcgroup initialization failed: %s\n", + fprintf(stderr, "%s: libcgroup initialization failed: %s\n", argv[0], cgroup_strerror(ret)); goto err; } @@ -154,9 +152,7 @@ int main(int argc, char *argv[]) goto err; } - /* - * Parse arguments - */ + /* Parse arguments */ while ((c = getopt_long(argc, argv, "rhg:", long_options, NULL)) > 0) { switch (c) { @@ -166,9 +162,8 @@ int main(int argc, char *argv[]) case 'g': ret = parse_cgroup_spec(cgroup_list, optarg, argc); if (ret != 0) { - fprintf(stderr, - "%s: error parsing cgroup '%s'\n", - argv[0], optarg); + fprintf(stderr, "%s: error parsing ", argv[0]); + fprintf(stderr, "cgroup '%s'\n", optarg); ret = -1; goto err; } @@ -189,7 +184,7 @@ int main(int argc, char *argv[]) ret = parse_cgroup_spec(cgroup_list, argv[i], argc); if (ret != 0) { fprintf(stderr, "%s: error parsing cgroup '%s'\n", - argv[0], argv[i]); + argv[0], argv[i]); ret = -1; goto err; } @@ -225,7 +220,7 @@ int main(int argc, char *argv[]) max = max + argc; ecg_list = (struct ext_cgroup_record *) realloc(ecg_list, - max * sizeof(struct ext_cgroup_record)); + max * sizeof(struct ext_cgroup_record)); if (!ecg_list) { fprintf(stderr, "%s: ", argv[0]); fprintf(stderr, "not enough memory\n"); @@ -236,9 +231,12 @@ int main(int argc, char *argv[]) strncpy(ecg_list[counter].controller, cgroup_list[i]->controllers[j], FILENAME_MAX); + ecg_list[counter].controller[FILENAME_MAX - 1] = '\0'; + strncpy(ecg_list[counter].name, cgroup_list[i]->path, FILENAME_MAX); + ecg_list[counter].name[FILENAME_MAX - 1] = '\0'; ret = skip_add_controller(counter, &skip, ecg_list); @@ -251,12 +249,11 @@ int main(int argc, char *argv[]) } cgc = cgroup_add_controller(cgroup, - cgroup_list[i]->controllers[j]); + cgroup_list[i]->controllers[j]); if (!cgc) { ret = ECGFAIL; - fprintf(stderr, "%s: " - "controller %s can't be added\n", - argv[0], + fprintf(stderr, "%s: ", argv[0]); + fprintf(stderr, "controller %s can't be added\n", cgroup_list[i]->controllers[j]); cgroup_free(&cgroup); goto err; @@ -267,19 +264,17 @@ next: } ret = cgroup_delete_cgroup_ext(cgroup, flags); - /* - * Remember the errors and continue, try to remove all groups. - */ + /* Remember the errors and continue, try to remove all groups. */ if (ret != 0) { fprintf(stderr, "%s: cannot remove group '%s': %s\n", - argv[0], cgroup->name, - cgroup_strerror(ret)); + argv[0], cgroup->name, cgroup_strerror(ret)); final_ret = ret; } cgroup_free(&cgroup); } ret = final_ret; + err: if (ecg_list) free(ecg_list); @@ -291,5 +286,6 @@ err: } free(cgroup_list); } + return ret; }