public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	acme@redhat.com, mingo@elte.hu
Subject: Re: [PATCH] perf: fix perf.data endianness detection
Date: Tue, 20 Sep 2011 13:23:16 -0600	[thread overview]
Message-ID: <4E78E824.4080209@gmail.com> (raw)
In-Reply-To: <CABPqkBRDhKUZf0FvShGbQWoPPAWAHA+XbUUqxDY+M1J9_gDiuQ@mail.gmail.com>

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()



      reply	other threads:[~2011-09-20 19:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19  9:56 [PATCH] perf: fix perf.data endianness detection Stephane Eranian
2011-09-20 18:59 ` David Ahern
2011-09-20 19:02   ` Stephane Eranian
2011-09-20 19:23     ` David Ahern [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=4E78E824.4080209@gmail.com \
    --to=dsahern@gmail.com \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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