All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Accel-config] [PATCH v1 2/6] accel-config: Fix an inconsistent error return value
@ 2021-05-07 19:31 ramesh.thomas
  0 siblings, 0 replies; only message in thread
From: ramesh.thomas @ 2021-05-07 19:31 UTC (permalink / raw
  To: accel-config

[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-07 19:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-07 19:31 [Accel-config] [PATCH v1 2/6] accel-config: Fix an inconsistent error return value ramesh.thomas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.