Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ef81c55 authored by Mamatha Inamdar's avatar Mamatha Inamdar Committed by Arnaldo Carvalho de Melo
Browse files

perf session: Return error code for perf_session__new() function on failure



This patch is to return error code of perf_new_session function on
failure instead of NULL.

Test Results:

Before Fix:

  $ perf c2c report -input
  failed to open nput: No such file or directory

  $ echo $?
  0
  $

After Fix:

  $ perf c2c report -input
  failed to open nput: No such file or directory

  $ echo $?
  254
  $

Committer notes:

Fix 'perf tests topology' case, where we use that TEST_ASSERT_VAL(...,
session), i.e. we need to pass zero in case of failure, which was the
case before when NULL was returned by perf_session__new() for failure,
but now we need to negate the result of IS_ERR(session) to respect that
TEST_ASSERT_VAL) expectation of zero meaning failure.

Reported-by: default avatarNageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Signed-off-by: default avatarMamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: default avatarNageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Acked-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
Reviewed-by: default avatarMukesh Ojha <mojha@codeaurora.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shawn Landden <shawn@git.icu>
Cc: Song Liu <songliubraving@fb.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Link: http://lore.kernel.org/lkml/20190822071223.17892.45782.stgit@localhost.localdomain


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9e6124d9
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <dlfcn.h>
#include <errno.h>
#include <linux/bitmap.h>
#include <linux/err.h>

struct perf_annotate {
	struct perf_tool tool;
@@ -584,8 +585,8 @@ int cmd_annotate(int argc, const char **argv)
	data.path = input_name;

	annotate.session = perf_session__new(&data, false, &annotate.tool);
	if (annotate.session == NULL)
		return -1;
	if (IS_ERR(annotate.session))
		return PTR_ERR(annotate.session);

	annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
						      HEADER_BRANCH_STACK);
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "util/util.h"
#include "util/probe-file.h"
#include <linux/string.h>
#include <linux/err.h>

static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
{
@@ -422,8 +423,8 @@ int cmd_buildid_cache(int argc, const char **argv)
		data.force = force;

		session = perf_session__new(&data, false, NULL);
		if (session == NULL)
			return -1;
		if (IS_ERR(session))
			return PTR_ERR(session);
	}

	if (symbol__init(session ? &session->header.env : NULL) < 0)
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "util/symbol.h"
#include "util/data.h"
#include <errno.h>
#include <linux/err.h>

static int sysfs__fprintf_build_id(FILE *fp)
{
@@ -65,8 +66,8 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
		goto out;

	session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops);
	if (session == NULL)
		return -1;
	if (IS_ERR(session))
		return PTR_ERR(session);

	/*
	 * We take all buildids when the file contains AUX area tracing data
+4 −2
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include <errno.h>
#include <inttypes.h>
#include <linux/compiler.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
#include <linux/zalloc.h>
@@ -2781,8 +2782,9 @@ static int perf_c2c__report(int argc, const char **argv)
	}

	session = perf_session__new(&data, 0, &c2c.tool);
	if (session == NULL) {
		pr_debug("No memory for session\n");
	if (IS_ERR(session)) {
		err = PTR_ERR(session);
		pr_debug("Error creating perf session\n");
		goto out;
	}

+5 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "util/time-utils.h"
#include "util/annotate.h"
#include "util/map.h"
#include <linux/err.h>
#include <linux/zalloc.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
@@ -1153,9 +1154,9 @@ static int check_file_brstack(void)

	data__for_each_file(i, d) {
		d->session = perf_session__new(&d->data, false, &pdiff.tool);
		if (!d->session) {
		if (IS_ERR(d->session)) {
			pr_err("Failed to open %s\n", d->data.path);
			return -1;
			return PTR_ERR(d->session);
		}

		has_br_stack = perf_header__has_feat(&d->session->header,
@@ -1185,9 +1186,9 @@ static int __cmd_diff(void)

	data__for_each_file(i, d) {
		d->session = perf_session__new(&d->data, false, &pdiff.tool);
		if (!d->session) {
		if (IS_ERR(d->session)) {
			ret = PTR_ERR(d->session);
			pr_err("Failed to open %s\n", d->data.path);
			ret = -1;
			goto out_delete;
		}

Loading