LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: tip-bot for Donald Yandt <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: yanmin_zhang@linux.intel.com, jolsa@redhat.com, hpa@zytor.com,
	mingo@kernel.org, donald.yandt@gmail.com,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	alexander.shishkin@linux.intel.com, peterz@infradead.org,
	acme@redhat.com
Subject: [tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array
Date: Thu, 30 May 2019 01:14:46 -0700	[thread overview]
Message-ID: <tip-34b65affe18daad31fed83e50d1f3b817786a2b7@git.kernel.org> (raw)
In-Reply-To: <20190528134128.30841-1-donald.yandt@gmail.com>

Commit-ID:  34b65affe18daad31fed83e50d1f3b817786a2b7
Gitweb:     https://git.kernel.org/tip/34b65affe18daad31fed83e50d1f3b817786a2b7
Author:     Donald Yandt <donald.yandt@gmail.com>
AuthorDate: Tue, 28 May 2019 09:41:28 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 28 May 2019 18:37:44 -0300

perf machine: Return NULL instead of null-terminating /proc/version array

Return NULL instead of null-terminating version char array when fgets
fails due to end-of-file or error.

Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
Fixes: 30ba5b0e66c8 ("perf machine: Null-terminate version char array upon fgets(/proc/version) error")
Link: http://lkml.kernel.org/r/20190528134128.30841-1-donald.yandt@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index f5569f005cf3..17eec39e775e 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1241,9 +1241,9 @@ static char *get_kernel_version(const char *root_dir)
 		return NULL;
 
 	tmp = fgets(version, sizeof(version), file);
-	if (!tmp)
-		*version = '\0';
 	fclose(file);
+	if (!tmp)
+		return NULL;
 
 	name = strstr(version, prefix);
 	if (!name)

      reply	other threads:[~2019-05-30  8:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 13:41 [PATCH resend] tools/perf/util/machine: Return NULL instead of null-terminating Donald Yandt
2019-05-30  8:14 ` tip-bot for Donald Yandt [this message]

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=tip-34b65affe18daad31fed83e50d1f3b817786a2b7@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=donald.yandt@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=yanmin_zhang@linux.intel.com \
    --subject='Re: [tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).