Skip to content

Commit

Permalink
accel-config: Don't list attributes not present
Browse files Browse the repository at this point in the history
Fixes a bug which was listing max_batch_size and max_transfer_size in
platforms the attributes were not present. If reading the attribute
returns error do not add to json array.

Signed-off-by: Ramesh Thomas <[email protected]>
  • Loading branch information
ramesh-thomas committed May 7, 2024
1 parent c039a9b commit ea015cc
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions util/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ struct json_object *util_device_to_json(struct accfg_device *device,
uint64_t iaa_cap;
enum accfg_device_state dev_state;
int int_val;
uint64_t ulong_val;
uint64_t ullong_val;
bool new_bool;
int evls;

Expand Down Expand Up @@ -291,14 +289,6 @@ struct json_object *util_device_to_json(struct accfg_device *device,
if (accfg_device_get_type(device) != ACCFG_DEVICE_IAX)
json_object_object_add(jdevice, "max_read_buffers", jobj);

ulong_val = accfg_device_get_max_batch_size(device);
if (ulong_val > 0) {
jobj = json_object_new_int(ulong_val);
if (!jobj)
goto err;
json_object_object_add(jdevice, "max_batch_size", jobj);
}

int_val = accfg_device_get_ims_size(device);
if (int_val >= 0) {
jobj = json_object_new_int(int_val);
Expand All @@ -315,9 +305,9 @@ struct json_object *util_device_to_json(struct accfg_device *device,
json_object_object_add(jdevice, "max_batch_size", jobj);
}

ullong_val = accfg_device_get_max_transfer_size(device);
if (ullong_val > 0) {
jobj = json_object_new_int64(ullong_val);
int_val = accfg_device_get_max_transfer_size(device);
if (int_val >= 0) {
jobj = json_object_new_int64(int_val);
if (!jobj)
goto err;
json_object_object_add(jdevice, "max_transfer_size", jobj);
Expand Down Expand Up @@ -414,13 +404,19 @@ struct json_object *util_wq_to_json(struct accfg_wq *wq,
if (jobj)
json_object_object_add(jaccfg, "block_on_fault", jobj);

jobj = json_object_new_int(accfg_wq_get_max_batch_size(wq));
if (jobj)
json_object_object_add(jaccfg, "max_batch_size", jobj);
int_val = accfg_wq_get_max_batch_size(wq);
if (int_val >= 0) {
jobj = json_object_new_int(int_val);
if (jobj)
json_object_object_add(jaccfg, "max_batch_size", jobj);
}

jobj = json_object_new_int64(accfg_wq_get_max_transfer_size(wq));
if (jobj)
json_object_object_add(jaccfg, "max_transfer_size", jobj);
int_val = accfg_wq_get_max_transfer_size(wq);
if (int_val >= 0) {
jobj = json_object_new_int64(int_val);
if (jobj)
json_object_object_add(jaccfg, "max_transfer_size", jobj);
}

if (!(flags & UTIL_JSON_SAVE) && accfg_wq_get_cdev_minor(wq) >= 0) {
jobj = json_object_new_int(accfg_wq_get_cdev_minor(wq));
Expand Down

0 comments on commit ea015cc

Please sign in to comment.