From: Soramichi AKIYAMA <akiyama@m.soramichi.jp>
To: linux-kernel@vger.kernel.org
Cc: acme@kernel.org, peterz@infradead.org, mingo@redhat.com,
alexander.shishkin@linux.intel.com
Subject: [PATCH] perf tools: Remove redundant variable in perf_header__adds_write
Date: Thu, 19 Jan 2017 22:55:08 +0900 [thread overview]
Message-ID: <20170119225508.7ffdff3cc8762f63c2c81ed3@m.soramichi.jp> (raw)
The reason why p exists in perf_header__adds_write(), even though it is
initialized to point the same address as feat_sec points, is that p is
increamented in do_write_feat() while feat_sec is not.
Note:(*p)++ in do_write_feat() is equivalent to p++ in perf_header__adds_write().
However for this purpose feat_sec can be copied as a local variable of do_write_feat()
by being passed as an argument, because p is never used outside of do_write_feat().
Signed-off-by: Soramichi Akiyama <akiyama@m.soramichi.jp>
---
| 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 00fd8a8..d373661 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2278,7 +2278,7 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
}
static int do_write_feat(int fd, struct perf_header *h, int type,
- struct perf_file_section **p,
+ struct perf_file_section *p,
struct perf_evlist *evlist)
{
int err;
@@ -2288,19 +2288,19 @@ static int do_write_feat(int fd, struct perf_header *h, int type,
if (!feat_ops[type].write)
return -1;
- (*p)->offset = lseek(fd, 0, SEEK_CUR);
+ p->offset = lseek(fd, 0, SEEK_CUR);
err = feat_ops[type].write(fd, h, evlist);
if (err < 0) {
pr_debug("failed to write feature %s\n", feat_ops[type].name);
/* undo anything written */
- lseek(fd, (*p)->offset, SEEK_SET);
+ lseek(fd, p->offset, SEEK_SET);
return -1;
}
- (*p)->size = lseek(fd, 0, SEEK_CUR) - (*p)->offset;
- (*p)++;
+ p->size = lseek(fd, 0, SEEK_CUR) - p->offset;
+ p++;
}
return ret;
}
@@ -2309,7 +2309,7 @@ static int perf_header__adds_write(struct perf_header *header,
struct perf_evlist *evlist, int fd)
{
int nr_sections;
- struct perf_file_section *feat_sec, *p;
+ struct perf_file_section *feat_sec;
int sec_size;
u64 sec_start;
int feat;
@@ -2319,7 +2319,7 @@ static int perf_header__adds_write(struct perf_header *header,
if (!nr_sections)
return 0;
- feat_sec = p = calloc(nr_sections, sizeof(*feat_sec));
+ feat_sec = calloc(nr_sections, sizeof(*feat_sec));
if (feat_sec == NULL)
return -ENOMEM;
@@ -2329,7 +2329,7 @@ static int perf_header__adds_write(struct perf_header *header,
lseek(fd, sec_start + sec_size, SEEK_SET);
for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) {
- if (do_write_feat(fd, header, feat, &p, evlist))
+ if (do_write_feat(fd, header, feat, feat_sec, evlist))
perf_header__clear_feat(header, feat);
}
--
2.1.4
reply other threads:[~2017-01-19 16:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20170119225508.7ffdff3cc8762f63c2c81ed3@m.soramichi.jp \
--to=akiyama@m.soramichi.jp \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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
all inboxes | Powered by JetHome®