lkml.org 
[lkml]   [2017]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] perf tools: Remove redundant variable in perf_header__adds_write
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>
---
tools/perf/util/header.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --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
\
 
 \ /
  Last update: 2017-01-19 17:47    [W:0.033 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site