Content-Type: multipart/mixed; boundary="===============7314161417221953716==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 2/6] accel-config: Fix an inconsistent error return value Date: Fri, 07 May 2021 15:31:22 -0400 Message-ID: <20210507193126.841998-3-ramesh.thomas@intel.com> In-Reply-To: 20210507193126.841998-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============7314161417221953716== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas accfg_device_get_errors was returning 0 even when sscanf has not read the 4 error values. It was returning 1 on success which is inconsistent with the success =3D 0. Updated one place where it was getting called. Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 14 +++++--------- util/json.c | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index 24ae65c..57e6d1f 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -1290,17 +1290,13 @@ ACCFG_EXPORT int accfg_device_get_errors(struct acc= fg_device *device, rc =3D sscanf(read_error, "%" SCNx64 " %" SCNx64 " %" SCNx64 " %" SCNx64, &error->val[0], &error->val[1], &error->val[2], &error->val[3]); - if (rc < 0) { - free(read_error); - return -errno; - } - else if (rc !=3D 4) { - free(read_error); - return 0; - } = free(read_error); - return 1; + + if (rc !=3D 4) + return errno ? -errno : -EIO; + + return 0; } = ACCFG_EXPORT enum accfg_device_state accfg_device_get_state( diff --git a/util/json.c b/util/json.c index fd30383..0ce7848 100644 --- a/util/json.c +++ b/util/json.c @@ -212,7 +212,7 @@ struct json_object *util_device_to_json(struct accfg_de= vice *device, goto err; json_object_object_add(jdevice, "numa_node", jobj); = - if (accfg_device_get_errors(device, error) =3D=3D 1 + if (!accfg_device_get_errors(device, error) && (error->val[0] || error->val[1] || error->val[2] || error->val[3])) { jobj =3D json_object_new_array(); -- = 2.26.3 --===============7314161417221953716==--