Skip to content

Commit d33ce61

Browse files
committed
Tools: Tune: Common: Add checks for file open failures
This patch adds checks and errors for fopen() failures. The check is useful with setup scripts paths changes. Aborting the script avoids the errors in blob exports to be missed. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 1eae42a commit d33ce61

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

tools/tune/common/alsactl_write.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ function alsactl_write(fn, blob8)
33
%% Write blob
44
check_create_dir(fn);
55
fh = fopen(fn, 'w');
6+
if fh < 0
7+
fprintf(1, 'Error: Could not open file %s\n', fn);
8+
error("Failed.");
9+
end
610

711
%% Pad blob length to multiple of four bytes
812
n_orig = length(blob8);

tools/tune/common/blob_write.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ function blob_write(fn, blob8)
44
%% Write blob
55
check_create_dir(fn);
66
fh = fopen(fn, 'wb');
7+
if fh < 0
8+
fprintf(1, 'Error: Could not open file %s\n', fn);
9+
error("Failed.");
10+
end
11+
712
fwrite(fh, blob8, 'uint8');
813
fclose(fh);
914

tools/tune/common/sof_ucm_blob_write.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ function sof_ucm_blob_write(fn, blob8)
2525
%% Write blob
2626
check_create_dir(fn);
2727
fh = fopen(fn, 'wb');
28+
if fh < 0
29+
fprintf(1, 'Error: Could not open file %s\n', fn);
30+
error("Failed.");
31+
end
32+
2833
fwrite(fh, ublob8, 'uint8');
2934
fclose(fh);
3035

tools/tune/common/tplg2_write.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function tplg2_write(fn, blob8, component, comment, howto)
2424

2525
%% Write blob
2626
fh = fopen(fn, 'w');
27+
if fh < 0
28+
fprintf(1, 'Error: Could not open file %s\n', fn);
29+
error("Failed.");
30+
end
2731
nl = 8;
2832
fprintf(fh, '# %s %s\n', comment, date());
2933
if ~isempty(howto)

tools/tune/common/tplg_write.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ function tplg_write(fn, blob8, name, comment, howto)
1515

1616
%% Write blob
1717
fh = fopen(fn, 'w');
18+
if fh < 0
19+
fprintf(1, 'Error: Could not open file %s\n', fn);
20+
error("Failed.");
21+
end
1822
nl = 8;
1923
fprintf(fh, '# %s %s\n', comment, date());
2024
if ~isempty(howto)

0 commit comments

Comments
 (0)