diskutil: fix segfault for both json and terse output
[fio.git] / diskutil.c
index f83fc47569cff5e0206c5f621919b1e5b1dbe4d0..074f1307d32212421f20833a8c73ee01b97fc5ab 100644 (file)
@@ -695,6 +695,7 @@ void show_disk_util(int terse, struct json_object *parent,
 {
        struct flist_head *entry;
        struct disk_util *du;
+       bool do_json;
 
        if (!disk_util_mutex)
                return;
@@ -706,15 +707,17 @@ void show_disk_util(int terse, struct json_object *parent,
                return;
        }
 
-       if (output_format & FIO_OUTPUT_JSON)
-               assert(parent);
+       if ((output_format & FIO_OUTPUT_JSON) && parent)
+               do_json = true;
+       else
+               do_json = false;
 
-       if (!terse && !(output_format & FIO_OUTPUT_JSON))
+       if (!terse && !do_json)
                log_buf(out, "\nDisk stats (read/write):\n");
 
-       if (output_format & FIO_OUTPUT_JSON)
+       if (do_json)
                json_object_add_disk_utils(parent, &disk_list);
-       if (output_format & ~(FIO_OUTPUT_JSON)) {
+       if (output_format & ~(FIO_OUTPUT_JSON | FIO_OUTPUT_JSON_PLUS)) {
                flist_for_each(entry, &disk_list) {
                        du = flist_entry(entry, struct disk_util, list);