public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <andi@firstfloor.org>
Subject: [PATCH 4/8] page-types: introduce checked_open()
Date: Wed, 16 Sep 2009 18:01:23 +0800	[thread overview]
Message-ID: <20090916100657.375753309@intel.com> (raw)
In-Reply-To: 20090916100119.275066569@intel.com

[-- Attachment #1: page-types-checked-open.patch --]
[-- Type: text/plain, Size: 1419 bytes --]

This helps merge duplicate code (now and future)
and outstand the main logic.

CC: Andi Kleen <andi@firstfloor.org> 
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 Documentation/vm/page-types.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

--- linux-mm.orig/Documentation/vm/page-types.c	2009-09-16 17:13:24.000000000 +0800
+++ linux-mm/Documentation/vm/page-types.c	2009-09-16 17:14:07.000000000 +0800
@@ -211,6 +211,18 @@ static void fatal(const char *x, ...)
 	exit(EXIT_FAILURE);
 }
 
+int checked_open(const char *pathname, int flags)
+{
+	int fd = open(pathname, flags);
+
+	if (fd < 0) {
+		perror(pathname);
+		exit(EXIT_FAILURE);
+	}
+
+	return fd;
+}
+
 
 /*
  * page flag names
@@ -531,11 +543,7 @@ static void walk_addr_ranges(void)
 {
 	int i;
 
-	kpageflags_fd = open(PROC_KPAGEFLAGS, O_RDONLY);
-	if (kpageflags_fd < 0) {
-		perror(PROC_KPAGEFLAGS);
-		exit(EXIT_FAILURE);
-	}
+	kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY);
 
 	if (!nr_addr_ranges)
 		add_addr_range(0, ULONG_MAX);
@@ -628,11 +636,7 @@ static void parse_pid(const char *str)
 	opt_pid = parse_number(str);
 
 	sprintf(buf, "/proc/%d/pagemap", opt_pid);
-	pagemap_fd = open(buf, O_RDONLY);
-	if (pagemap_fd < 0) {
-		perror(buf);
-		exit(EXIT_FAILURE);
-	}
+	pagemap_fd = checked_open(buf, O_RDONLY);
 
 	sprintf(buf, "/proc/%d/maps", opt_pid);
 	file = fopen(buf, "r");

-- 


  parent reply	other threads:[~2009-09-16 10:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16 10:01 [PATCH 0/8] page-types tool updates Wu Fengguang
2009-09-16 10:01 ` [PATCH 1/8] pagemap: export KPF_HWPOISON Wu Fengguang
2009-09-16 10:01 ` [PATCH 2/8] pagemap: document KPF_KSM and show it in page-types Wu Fengguang
2009-09-16 10:01 ` [PATCH 3/8] page-types: add GPL note Wu Fengguang
2009-09-16 10:01 ` Wu Fengguang [this message]
2009-09-16 10:01 ` [PATCH 5/8] page-types: make standalone pagemap/kpageflags read routines Wu Fengguang
2009-09-16 10:01 ` [PATCH 6/8] page-types: make voffset local variables Wu Fengguang
2009-09-16 10:01 ` [PATCH 7/8] page-types: introduce kpageflags_flags() Wu Fengguang
2009-09-16 10:01 ` [PATCH 8/8] page-types: add hwpoison/unpoison feature Wu Fengguang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090916100657.375753309@intel.com \
    --to=fengguang.wu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox