All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ameer Hamza <amhamza.mgc@gmail.com>
To: mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	rickyman7@gmail.com, alexey.v.bayduraev@linux.intel.com,
	adrian.hunter@intel.com, leo.yan@linaro.org,
	german.gomez@arm.com, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org, amhamza.mgc@gmail.com,
	James Clark <james.clark@arm.com>
Subject: [PATCH v2] perf session: check for null pointer before derefernce
Date: Tue, 25 Jan 2022 17:11:41 +0500	[thread overview]
Message-ID: <20220125121141.18347-1-amhamza.mgc@gmail.com> (raw)
In-Reply-To: <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com>

Move null pointer check before dereferncing the variable

Addresses-Coverity: 1497622 ("Derereference before null check")

Reviewed-by: James Clark <james.clark@arm.com>

Signed-off-by: Ameer Hamza <amhamza.mgc@gmail.com>

---
v1 -> v2: It should be possible to dump stuff if machine is NULL.
---
 tools/perf/util/session.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index f19348dddd55..210eeee3dd70 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1503,11 +1503,12 @@ static int machines__deliver_event(struct machines *machines,
 			++evlist->stats.nr_unknown_id;
 			return 0;
 		}
-		dump_sample(evsel, event, sample, perf_env__arch(machine->env));
 		if (machine == NULL) {
 			++evlist->stats.nr_unprocessable_samples;
+			dump_sample(evsel, event, sample, perf_env__arch(NULL));
 			return 0;
 		}
+		dump_sample(evsel, event, sample, perf_env__arch(machine->env));
 		return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
 	case PERF_RECORD_MMAP:
 		return tool->mmap(tool, event, sample, machine);
-- 
2.25.1


  reply	other threads:[~2022-01-25 12:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 15:00 [PATCH] perf session: check for null pointer before derefernce Ameer Hamza
2022-01-24 15:30 ` James Clark
2022-01-24 20:29   ` Ameer Hamza
2022-01-25  9:35     ` James Clark
2022-01-25 12:11       ` Ameer Hamza [this message]
2022-02-06 11:41       ` Arnaldo Carvalho de Melo

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=20220125121141.18347-1-amhamza.mgc@gmail.com \
    --to=amhamza.mgc@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.v.bayduraev@linux.intel.com \
    --cc=german.gomez@arm.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@redhat.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.