[Accel-config] [PATCH v1 6/8] accel-config: Skip negative fields in listings

ramesh.thomas at intel.com
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Skip printing cdev_minor and group_id if they have negative values
indicating they are invalid or are not initialized.

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 util/json.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/util/json.c b/util/json.c
index b02e336..25514af 100644
--- a/util/json.c
+++ b/util/json.c
@@ -429,9 +429,11 @@ struct json_object *util_wq_to_json(struct accfg_wq *wq,
 			json_object_object_add(jaccfg, "size", jobj);
 	}
 
-	jobj = json_object_new_int(accfg_wq_get_group_id(wq));
-	if (jobj)
-		json_object_object_add(jaccfg, "group_id", jobj);
+	if (accfg_wq_get_group_id(wq) >= 0) {
+		jobj = json_object_new_int(accfg_wq_get_group_id(wq));
+		if (jobj)
+			json_object_object_add(jaccfg, "group_id", jobj);
+	}
 
 	int_val = accfg_wq_get_priority(wq);
 	if (int_val >= 0) {
@@ -452,7 +454,7 @@ struct json_object *util_wq_to_json(struct accfg_wq *wq,
 	if (jobj)
 		json_object_object_add(jaccfg, "max_transfer_size", jobj);
 
-	if (!(flags & UTIL_JSON_SAVE)) {
+	if (!(flags & UTIL_JSON_SAVE) && accfg_wq_get_cdev_minor(wq) >= 0) {
 		jobj = json_object_new_int(accfg_wq_get_cdev_minor(wq));
 		if (jobj)
 			json_object_object_add(jaccfg, "cdev_minor", jobj);
@@ -517,10 +519,12 @@ struct json_object *util_engine_to_json(struct accfg_engine *engine,
 		goto err;
 	json_object_object_add(jaccfg, "dev", jobj);
 
-	jobj = json_object_new_int(accfg_engine_get_group_id(engine));
-	if (!jobj)
-		goto err;
-	json_object_object_add(jaccfg, "group_id", jobj);
+	if (accfg_engine_get_group_id(engine) >= 0) {
+		jobj = json_object_new_int(accfg_engine_get_group_id(engine));
+		if (!jobj)
+			goto err;
+		json_object_object_add(jaccfg, "group_id", jobj);
+	}
 
 	return jaccfg;
 err:
-- 
2.26.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.