Skip to content

Commit f3803d4

Browse files
committed
tree: Use SAFE_FOPEN()
Signed-off-by: Petr Vorel <[email protected]>
1 parent 13dbd83 commit f3803d4

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define _GNU_SOURCE
2222
#include "lapi/mmap.h"
2323
#include "hugetlb.h"
24+
#include "tst_safe_stdio.h"
2425
#include <errno.h>
2526
#include <inttypes.h>
2627
#include <sched.h>
@@ -80,12 +81,9 @@ static void run_test(void)
8081
}
8182

8283
/* Return start address of next mapping or 0 */
83-
static uintptr_t get_next_mapping_start(uintptr_t addr)
84+
static uintptr_t get_next_mapping_start(uintptr_t addr)
8485
{
85-
FILE *fp = fopen("/proc/self/maps", "r");
86-
87-
if (fp == NULL)
88-
tst_brk(TBROK | TERRNO, "Failed to open /proc/self/maps.");
86+
FILE *fp = SAFE_FOPEN("/proc/self/maps", "r");
8987

9088
while (!feof(fp)) {
9189
uintptr_t start, end;
@@ -94,7 +92,7 @@ static uintptr_t get_next_mapping_start(uintptr_t addr)
9492
ret = fscanf(fp, "%"PRIxPTR"-%"PRIxPTR" %*[^\n]\n", &start, &end);
9593
if (ret != 2) {
9694
fclose(fp);
97-
tst_brk(TBROK | TERRNO, "Couldn't parse /proc/self/maps line.");
95+
tst_brk(TBROK | TERRNO, "Couldn't parse /proc/self/maps line");
9896
}
9997

10098
if (start > addr) {

testcases/kernel/mem/vma/vma02.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ int main(int argc, char **argv)
112112

113113
/* /proc/self/maps in the form of
114114
"00400000-00406000 r-xp 00000000". */
115-
fp = fopen("/proc/self/maps", "r");
116-
if (fp == NULL)
117-
tst_brkm(TBROK | TERRNO, NULL, "fopen");
115+
fp = SAFE_FOPEN(NULL, "/proc/self/maps", "r");
118116

119117
while (fgets(buf, BUFSIZ, fp) != NULL) {
120118
if (sscanf(buf, "%p-%p ", &start, &end) != 2)

testcases/kernel/mem/vma/vma04.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ static void get_vmas(char *retbuf, void *addr_s, void *addr_e)
202202

203203
retbuf[0] = '\0';
204204
flag = 0;
205-
fp = fopen("/proc/self/maps", "r");
206-
if (fp == NULL)
207-
tst_brkm(TBROK | TERRNO, cleanup, "fopen");
205+
fp = SAFE_FOPEN(NULL, "/proc/self/maps", "r");
206+
208207
while (fgets(buf, BUFSIZ, fp) != NULL) {
209208
if (sscanf(buf, "%p-%p ", &s, &t) != 2)
210209
continue;

testcases/kernel/security/kallsyms/kallsyms.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ static void read_proc_self_maps(void)
9999
FILE *fp;
100100

101101
ranges_len = 0;
102-
fp = fopen("/proc/self/maps", "r");
103-
if (fp == NULL)
104-
tst_brk(TBROK | TERRNO, "Failed to open /proc/self/maps.");
102+
fp = SAFE_FOPEN("/proc/self/maps", "r");
105103

106104
while (!feof(fp)) {
107105
unsigned long start, end;

0 commit comments

Comments
 (0)