Skip to content

Commit b93568d

Browse files
mdouchametan-ucw
authored andcommitted
Unify error handling in lib/tst_mkfs.c
- Properly format caller file:line location Signed-off-by: Martin Doucha <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 0d16237 commit b93568d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

lib/tst_mkfs.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
3333
char extra_opts_str[1024] = "";
3434

3535
if (!dev) {
36-
tst_brkm(TBROK, cleanup_fn,
37-
"%s:%d: No device specified", file, lineno);
36+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
37+
"No device specified");
3838
return;
3939
}
4040

4141
if (!fs_type) {
42-
tst_brkm(TBROK, cleanup_fn,
43-
"%s:%d: No fs_type specified", file, lineno);
42+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
43+
"No fs_type specified");
4444
return;
4545
}
4646

@@ -51,9 +51,8 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
5151
argv[pos++] = fs_opts[i];
5252

5353
if (pos + 2 > OPTS_MAX) {
54-
tst_brkm(TBROK, cleanup_fn,
55-
"%s:%d: Too much mkfs options",
56-
file, lineno);
54+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
55+
"Too many mkfs options");
5756
return;
5857
}
5958

@@ -70,8 +69,8 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
7069
argv[pos++] = extra_opts[i];
7170

7271
if (pos + 1 > OPTS_MAX) {
73-
tst_brkm(TBROK, cleanup_fn,
74-
"%s:%d: Too much mkfs options", file, lineno);
72+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
73+
"Too many mkfs options");
7574
return;
7675
}
7776

@@ -83,24 +82,27 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
8382

8483
argv[pos] = NULL;
8584

86-
if (tst_clear_device(dev))
87-
tst_brkm(TBROK, cleanup_fn, "tst_clear_device() failed");
85+
if (tst_clear_device(dev)) {
86+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
87+
"tst_clear_device() failed");
88+
}
8889

89-
tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
90-
dev, fs_type, fs_opts_str, extra_opts_str);
90+
tst_resm_(file, lineno, TINFO,
91+
"Formatting %s with %s opts='%s' extra opts='%s'",
92+
dev, fs_type, fs_opts_str, extra_opts_str);
9193
ret = tst_cmd(cleanup_fn, argv, "/dev/null", NULL, TST_CMD_PASS_RETVAL |
9294
TST_CMD_TCONF_ON_MISSING);
9395

9496
switch (ret) {
9597
case 0:
9698
break;
9799
case 255:
98-
tst_brkm(TCONF, cleanup_fn,
99-
"%s:%d: %s not found in $PATH", file, lineno, mkfs);
100+
tst_brkm_(file, lineno, TCONF, cleanup_fn,
101+
"%s not found in $PATH", mkfs);
100102
break;
101103
default:
102-
tst_brkm(TBROK, cleanup_fn,
103-
"%s:%d: %s failed with %i", file, lineno, mkfs, ret);
104+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
105+
"%s failed with exit code %i", mkfs, ret);
104106
}
105107
}
106108

0 commit comments

Comments
 (0)