From: Peter Zijlstra <peterz@infradead.org>
To: "Geyslan Gregório Bem" <geyslan@gmail.com>
Cc: paulus@samba.org, Ingo Molnar <mingo@redhat.com>,
acme@ghostprotocols.net, kernel-br <kernel-br@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] Coverity 1128445 - Reliance on integer endianness
Date: Tue, 12 Nov 2013 15:30:24 +0100 [thread overview]
Message-ID: <20131112143024.GR5056@laptop.programming.kicks-ass.net> (raw)
In-Reply-To: <CAGG-pUQrN6D_iSsWVptjQSA4B_oGn5NhbhBp+aLT0GJCFSmYRA@mail.gmail.com>
On Tue, Nov 12, 2013 at 12:19:13PM -0200, Geyslan Gregório Bem wrote:
> Hi,
>
> Coverity detected in 'arch/x86/kernel/cpu/perf_event_intel_uncore.c' a
> possible reliance on integer endianness. Is that a positive one?
>
> static u64 ivt_uncore_irp_read_counter(struct intel_uncore_box *box,
> struct perf_event *event)
> 1369{
> 1370 struct pci_dev *pdev = box->pci_dev;
> 1371 struct hw_perf_event *hwc = &event->hw;
> 1372 u64 count = 0;
> 1373
>
> CID 1128445 (#1 of 1): Reliance on integer endianness
> (INCOMPATIBLE_CAST)incompatible_cast: Pointer "&count" points to an
> object whose effective type is "unsigned long long" (64 bits,
> unsigned) but is dereferenced as a narrower "unsigned int" (32 bits,
> unsigned). This may lead to unexpected results depending on machine
> endianness.[show details]
>
> 1374 pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx],
> (u32 *)&count);
> 1375 pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx]
> + 4, (u32 *)&count + 1);
> 1376
> 1377 return count;
> 1378}
Right, its a bit ugly but since its all arch code (x86) we can indeed
assume endianness (little).
So yes Coverity is right but we can also ignore it since machine
endianness is fixed here.
The code loads the u64 in two pci dword reads and assumes the high dword
lives at the higher address, this is correct for little endian.
next prev parent reply other threads:[~2013-11-12 14:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 14:19 Geyslan Gregório Bem
2013-11-12 14:30 ` Peter Zijlstra [this message]
2013-11-12 14:33 ` Peter Zijlstra
2013-11-12 14:39 ` Geyslan Gregório Bem
2013-11-12 14:36 ` Måns Rullgård
2013-11-12 14:38 ` Geyslan Gregório Bem
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=20131112143024.GR5056@laptop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@ghostprotocols.net \
--cc=geyslan@gmail.com \
--cc=kernel-br@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.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®