lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1258688237-3797-1-git-send-email-mitake@dcl.info.waseda.ac.jp>
Date:	Fri, 20 Nov 2009 12:37:17 +0900
From:	Hitoshi Mitake <mitake@....info.waseda.ac.jp>
To:	Ingo Molnar <mingo@...e.hu>
Cc:	linux-kernel@...r.kernel.org,
	Hitoshi Mitake <mitake@....info.waseda.ac.jp>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Mackerras <paulus@...ba.org>,
	Frederic Weisbecker <fweisbec@...il.com>
Subject: [PATCH] perf bench: Make mem/memcpy more friendly

mem-memcpy.c uses perf event system calls to obtain CPU clocks.
And it suddenly dies with BUG_ON() when it running on Linux
doesn't support perf event.

Also fail at calloc() can occur easily when too large
length is passed. Fail of calloc() causes sudden death
with assert().

These behaviours are not friendly. So I fixed the treat of error.

Signed-off-by: Hitoshi Mitake <mitake@....info.waseda.ac.jp>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Frederic Weisbecker <fweisbec@...il.com>
---
 tools/perf/bench/mem-memcpy.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c
index d4f4f98..1252d42 100644
--- a/tools/perf/bench/mem-memcpy.c
+++ b/tools/perf/bench/mem-memcpy.c
@@ -67,6 +67,11 @@ static struct perf_event_attr clock_attr = {
 static void init_clock(void)
 {
 	clock_fd = sys_perf_event_open(&clock_attr, getpid(), -1, -1, 0);
+	if (clock_fd < 0 && errno == ENOSYS) {
+		fprintf(stderr, "! Your Linux doesn't support perf events!\n");
+		fprintf(stderr, "! Measuring clock is impossible. Aborting.\n");
+		exit(1);
+	}
 	BUG_ON(clock_fd < 0);
 }
 
@@ -124,9 +129,17 @@ int bench_mem_memcpy(int argc, const char **argv,
 	}
 
 	dst = calloc(length, sizeof(char));
-	assert(dst);
+	if (!dst) {
+		fprintf(stderr, "Allocating memory failed.\n");
+		fprintf(stderr, "Maybe length is too large.\n");
+		exit(1);
+	}
 	src = calloc(length, sizeof(char));
-	assert(src);
+	if (!src) {
+		fprintf(stderr, "Allocating memory failed.\n");
+		fprintf(stderr, "Maybe length is too large.\n");
+		exit(1);
+	}
 
 	if (bench_format == BENCH_FORMAT_DEFAULT) {
 		printf("# Copying %s Bytes from %p to %p ...\n\n",
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ