Re: [PATCH] perf: fix perf.data endianness detection

From: David Ahern
Date: Tue Sep 20 2011 - 15:23:29 EST


On 09/20/2011 01:02 PM, Stephane Eranian wrote:
>>> +static int check_magic_endian(u64 *magic, struct perf_file_header *header,
>>> + struct perf_header *ph)
>>> +{
>>> + int ret;
>>> +
>>> + /* check for legacy format */
>>> + ret = memcmp(magic, __perf_magic1, sizeof(*magic));
>>> + if (ret == 0) {
>>> + pr_debug("legacy perf.data format\n");
>>> + if (!header)
>>> + return -1;
>>> +
>>> + if (header->attr_size != sizeof(struct perf_file_attr)) {
>>> + u64 attr_size = bswap_64(header->attr_size);
>>> +
>>> + if (attr_size != sizeof(struct perf_file_attr))
>>> + return -1;
>>> +
>>> + mem_bswap_64(header, offsetof(struct perf_file_header,
>>> + adds_features));
>>> + ph->needs_swap = true;
>>> + }
>>> + return 0;
>>> + }
>>> +
>>> + /* check for our magic (same endianness) */
>>> + if (*magic == __perf_magic2)
>>> + return 0;
>>> +
>>> + /* check for our magic (opposite endianness) */
>>> + if (*magic != __perf_magic2_sw)
>>> + return -1;
>>> +
>>> + ph->needs_swap = true;

--> goes here too
|
|

>>> +
>>> + return 0;
>>> +}
>>> +
>>> int perf_file_header__read(struct perf_file_header *header,
>>> struct perf_header *ph, int fd)
>>> {
>>> + int ret;
>>> +
>>> lseek(fd, 0, SEEK_SET);
>>>
>>> - if (readn(fd, header, sizeof(*header)) <= 0 ||
>>> - memcmp(&header->magic, __perf_magic, sizeof(header->magic)))
>>> + ret = readn(fd, header, sizeof(*header));
>>> + if (ret <= 0)
>>> return -1;
>>>
>>> - if (header->attr_size != sizeof(struct perf_file_attr)) {
>>> - u64 attr_size = bswap_64(header->attr_size);
>>> -
>>> - if (attr_size != sizeof(struct perf_file_attr))
>>> - return -1;
>>> -
>>> - mem_bswap_64(header, offsetof(struct perf_file_header,
>>> - adds_features));

|
|---- the mem_bswap_64()


--
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/