[Accel-config] [PATCH v1 2/6] accel-config: Fix an inconsistent error return value
ramesh.thomas at intel.com
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
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 = 0. Updated one place where it was getting called.
Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
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 accfg_device *device,
rc = 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 != 4) {
- free(read_error);
- return 0;
- }
free(read_error);
- return 1;
+
+ if (rc != 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_device *device,
goto err;
json_object_object_add(jdevice, "numa_node", jobj);
- if (accfg_device_get_errors(device, error) == 1
+ if (!accfg_device_get_errors(device, error)
&& (error->val[0] || error->val[1]
|| error->val[2] || error->val[3])) {
jobj = json_object_new_array();
--
2.26.3