[PATCH 11/25] perf tools: Introduce swap_header function

From: Jiri Olsa
Date: Sun Sep 01 2013 - 06:38:30 EST


Introducing swap_header function to make the swapping
code more clear and extensible.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
---
tools/perf/util/header.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 164510e..fba6a9a 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2548,6 +2548,22 @@ static void swap_features(unsigned long *adds_features)
}
}

+static int swap_header(struct perf_file_header *header)
+{
+ mem_bswap_64(header, offsetof(struct perf_file_header, adds_features));
+
+ if (header->size != sizeof(*header)) {
+ /* Support the previous format */
+ if (header->size == offsetof(typeof(*header), adds_features))
+ bitmap_zero(header->adds_features, HEADER_FEAT_BITS);
+ else
+ return -1;
+ } else
+ swap_features(header->adds_features);
+
+ return 0;
+}
+
int perf_file_header__read(struct perf_file_header *header,
struct perf_header *ph, int fd)
{
@@ -2565,19 +2581,8 @@ int perf_file_header__read(struct perf_file_header *header,
return -1;
}

- if (ph->needs_swap) {
- mem_bswap_64(header, offsetof(struct perf_file_header,
- adds_features));
- }
-
- if (header->size != sizeof(*header)) {
- /* Support the previous format */
- if (header->size == offsetof(typeof(*header), adds_features))
- bitmap_zero(header->adds_features, HEADER_FEAT_BITS);
- else
- return -1;
- } else if (ph->needs_swap)
- swap_features(header->adds_features);
+ if (ph->needs_swap && swap_header(header))
+ return -1;

memcpy(&ph->adds_features, &header->adds_features,
sizeof(ph->adds_features));
--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/