Skip to content

Commit af4948b

Browse files
ktrzcinxjajanusz
authored andcommitted
logger: Check fprintf return value for trace format text
log format text comes from ldc file (may be invalid), so error check is needed. Don't treat it as fatal error, because this error may not impact following logs, when formatting text is root cause of the issue. Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
1 parent 823dbae commit af4948b

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

tools/logger/convert.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ static void print_entry_params(const struct log_entry_header *dma_log,
323323
float dt = to_usecs(dma_log->timestamp - last_timestamp);
324324
struct proc_ldc_entry proc_entry;
325325
static char time_fmt[32];
326+
int ret;
326327

327328
if (raw_output)
328329
use_colors = 0;
@@ -401,24 +402,32 @@ static void print_entry_params(const struct log_entry_header *dma_log,
401402

402403
switch (proc_entry.header.params_num) {
403404
case 0:
404-
fprintf(out_fd, "%s", proc_entry.text);
405+
ret = fprintf(out_fd, "%s", proc_entry.text);
405406
break;
406407
case 1:
407-
fprintf(out_fd, proc_entry.text, proc_entry.params[0]);
408+
ret = fprintf(out_fd, proc_entry.text, proc_entry.params[0]);
408409
break;
409410
case 2:
410-
fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1]);
411+
ret = fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1]);
411412
break;
412413
case 3:
413-
fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1],
414-
proc_entry.params[2]);
414+
ret = fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1],
415+
proc_entry.params[2]);
415416
break;
416417
case 4:
417-
fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1],
418-
proc_entry.params[2], proc_entry.params[3]);
418+
ret = fprintf(out_fd, proc_entry.text, proc_entry.params[0], proc_entry.params[1],
419+
proc_entry.params[2], proc_entry.params[3]);
420+
break;
421+
default:
422+
log_err("Unsupported number of arguments for '%s'", proc_entry.text);
423+
ret = 0; /* don't log ferror */
419424
break;
420425
}
421426
free_proc_ldc_entry(&proc_entry);
427+
/* log format text comes from ldc file (may be invalid), so error check is needed here */
428+
if (ret < 0)
429+
log_err("trace fprintf failed for '%s', %d '%s'",
430+
proc_entry.text, ferror(out_fd), strerror(ferror(out_fd)));
422431
fprintf(out_fd, "%s\n", use_colors ? KNRM : "");
423432
fflush(out_fd);
424433
}

0 commit comments

Comments
 (0)