Content-Type: multipart/mixed; boundary="===============6400153694364736579==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 2/8] accel-config: Fix wrong return values in functions Date: Wed, 05 May 2021 13:44:16 -0400 Message-ID: <20210505174422.837248-3-ramesh.thomas@intel.com> In-Reply-To: 20210505174422.837248-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============6400153694364736579== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas display_xx functions were returning true on success and false. Change to return negitive error code on error and 0 on success. Signed-off-by: Ramesh Thomas --- accfg/list.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/accfg/list.c b/accfg/list.c index a252585..1f75bcf 100644 --- a/accfg/list.c +++ b/accfg/list.c @@ -369,7 +369,7 @@ static int save_config(struct list_filter_arg *lfa, con= st char *saved_file) if (!fd) { fprintf(stderr, "Failed to open %s for save: %s\n", saved_file, strerror(errno)); - return false; + return -EIO; } = if (jdevices) @@ -397,10 +397,10 @@ static int display_device(struct json_object *jdevice= s, util_display_json_array(stdout, jdevices, lfa->flags); = if (!util_param.device) - return true; + return 0; = if (sscanf(util_param.device, "%[a-z]%d", dev_type, &device_id) !=3D 2) - return false; + return -EINVAL; = for (accel_type =3D accfg_basenames; *accel_type !=3D NULL; accel_type++) if (!strcmp(dev_type, *accel_type)) @@ -408,18 +408,18 @@ static int display_device(struct json_object *jdevice= s, = if (*accel_type =3D=3D NULL) { fprintf(stderr, "device type not matched\n"); - return false; + return -EINVAL; } = if (device_id > lfa->dev_num) { fprintf(stderr, "device_id out of range\n"); - return false; + return -EINVAL; } = jdevice =3D json_object_array_get_idx(jdevices, 0); printf("%s\n", json_object_to_json_string_ext(jdevice, jflag)); = - return true; + return 0; } = static int display_group(struct list_filter_arg *lfa, struct accfg_ctx *ct= x) @@ -437,12 +437,12 @@ static int display_group(struct list_filter_arg *lfa,= struct accfg_ctx *ctx) list_for_each(&lfa->jdev_list, iter, list) util_display_json_array(stdout, iter->jgroups, lfa->flags); - return true; + return 0; = } = if (sscanf(util_param.group, "group%d.%d", &device_id, &group_id) !=3D 2) - return false; + return -EINVAL; = accfg_device_foreach(ctx, dev) { if (accfg_device_get_id(dev) !=3D device_id) @@ -452,7 +452,7 @@ static int display_group(struct list_filter_arg *lfa, s= truct accfg_ctx *ctx) if (device_id > lfa->dev_num || group_id > max_groups) { fprintf(stderr, "device_id or group_id out of range\n"); - return false; + return -EINVAL; } = list_for_each(&lfa->jdev_list, iter, list) { @@ -469,7 +469,7 @@ static int display_group(struct list_filter_arg *lfa, s= truct accfg_ctx *ctx) } } = - return true; + return 0; } = static int display_wq(struct list_filter_arg *lfa, struct accfg_ctx *ctx) @@ -495,11 +495,11 @@ static int display_wq(struct list_filter_arg *lfa, st= ruct accfg_ctx *ctx) } = } - return true; + return 0; } = if (sscanf(util_param.wq, "wq%d.%d", &device_id, &wq_id) !=3D 2) - return false; + return -EINVAL; = accfg_device_foreach(ctx, dev) { if (accfg_device_get_id(dev) =3D=3D device_id) { @@ -509,14 +509,14 @@ static int display_wq(struct list_filter_arg *lfa, st= ruct accfg_ctx *ctx) if (device_id > lfa->dev_num || wq_id > max_wqs) { fprintf(stderr, "device_id or wq_id out of range\n"); - return false; + return -EINVAL; } = list_for_each(&lfa->jdev_list, iter, list) if (match_device(dev, iter)) jc =3D iter; if (!jc) - return false; + return -EINVAL; = printf("device %s:\n", jc->device_name); for (index =3D 0; index < max_groups; index++) { @@ -534,7 +534,7 @@ static int display_wq(struct list_filter_arg *lfa, stru= ct accfg_ctx *ctx) } } = - return true; + return 0; } = static int display_engine(struct list_filter_arg *lfa, struct accfg_ctx *c= tx) @@ -561,7 +561,7 @@ static int display_engine(struct list_filter_arg *lfa, = struct accfg_ctx *ctx) } = } - return true; + return 0; } = if (sscanf(util_param.engine, "engine%d.%d", &device_id, &engine_id) != =3D 2) @@ -576,14 +576,14 @@ static int display_engine(struct list_filter_arg *lfa= , struct accfg_ctx *ctx) || engine_id > max_engines) { fprintf(stderr, "dev id or engine id out of range\n"); - return false; + return -EINVAL; } = list_for_each(&lfa->jdev_list, iter, list) if (match_device(dev, iter)) jc =3D iter; if (!jc) - return false; + return -EINVAL; = printf("device %s:\n", jc->device_name); for (index =3D 0; index < max_groups; index++) { @@ -602,7 +602,7 @@ static int display_engine(struct list_filter_arg *lfa, = struct accfg_ctx *ctx) } } = - return true; + return 0; } = static int list_display(struct list_filter_arg *lfa, struct accfg_ctx *ctx) @@ -635,6 +635,8 @@ static int num_list_flags(void) = int cmd_list(int argc, const char **argv, void *ctx) { + int i, rc; + const struct option options[] =3D { OPT_STRING('d', "device", &util_param.device, "device-id", "filter by device"), @@ -662,7 +664,6 @@ int cmd_list(int argc, const char **argv, void *ctx) }; struct util_filter_ctx fctx =3D { 0 }; struct list_filter_arg lfa =3D { 0 }; - int i, rc; = argc =3D parse_options(argc, argv, options, u, 0); for (i =3D 0; i < argc; i++) @@ -694,8 +695,13 @@ int cmd_list(int argc, const char **argv, void *ctx) if (rc) return rc; = - if (list_display(&lfa, ctx) || did_fail) - return -ENOMEM; + rc =3D list_display(&lfa, ctx); + if (rc) + return rc; + + if (did_fail) + return -EINVAL; + return 0; } = -- = 2.26.3 --===============6400153694364736579==--