Commit 31bbf66eaaaf50ba79e50ab7d3c89531b31c0614
Committed by
Linus Torvalds
1 parent
0c57effe27
Exists in
master
and in
7 other branches
page-types: introduce checked_open()
This helps merge duplicate code (now and future) and outstand the main logic. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 14 additions and 10 deletions Side-by-side Diff
Documentation/vm/page-types.c
... | ... | @@ -214,7 +214,19 @@ |
214 | 214 | exit(EXIT_FAILURE); |
215 | 215 | } |
216 | 216 | |
217 | +int checked_open(const char *pathname, int flags) | |
218 | +{ | |
219 | + int fd = open(pathname, flags); | |
217 | 220 | |
221 | + if (fd < 0) { | |
222 | + perror(pathname); | |
223 | + exit(EXIT_FAILURE); | |
224 | + } | |
225 | + | |
226 | + return fd; | |
227 | +} | |
228 | + | |
229 | + | |
218 | 230 | /* |
219 | 231 | * page flag names |
220 | 232 | */ |
... | ... | @@ -534,11 +546,7 @@ |
534 | 546 | { |
535 | 547 | int i; |
536 | 548 | |
537 | - kpageflags_fd = open(PROC_KPAGEFLAGS, O_RDONLY); | |
538 | - if (kpageflags_fd < 0) { | |
539 | - perror(PROC_KPAGEFLAGS); | |
540 | - exit(EXIT_FAILURE); | |
541 | - } | |
549 | + kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); | |
542 | 550 | |
543 | 551 | if (!nr_addr_ranges) |
544 | 552 | add_addr_range(0, ULONG_MAX); |
... | ... | @@ -631,11 +639,7 @@ |
631 | 639 | opt_pid = parse_number(str); |
632 | 640 | |
633 | 641 | sprintf(buf, "/proc/%d/pagemap", opt_pid); |
634 | - pagemap_fd = open(buf, O_RDONLY); | |
635 | - if (pagemap_fd < 0) { | |
636 | - perror(buf); | |
637 | - exit(EXIT_FAILURE); | |
638 | - } | |
642 | + pagemap_fd = checked_open(buf, O_RDONLY); | |
639 | 643 | |
640 | 644 | sprintf(buf, "/proc/%d/maps", opt_pid); |
641 | 645 | file = fopen(buf, "r"); |