From: Arnd Bergmann <arnd@arndb.de>
To: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
'Greg KH' <greg@kroah.com>
Subject: Re: [PATCH 10/12] unicore32 machine related files: pci bus handling
Date: Thu, 17 Feb 2011 18:19:52 +0100 [thread overview]
Message-ID: <201102171819.52845.arnd@arndb.de> (raw)
In-Reply-To: <015501cbcdae$6961c5d0$3c255170$@mprc.pku.edu.cn>
On Wednesday 16 February 2011, Guan Xuetao wrote:
> +{
> + PCICFG_ADDR = CONFIG_CMD(bus, devfn, where);
> + switch (size) {
> + case 1:
> + *value = (PCICFG_DATA >> ((where & 3) * 8)) & 0xFF;
> + break;
> + case 2:
It took me a while to figure out what this actually does. PCICFG_ADDR
and PCICFG_DATA are pointers to MMIO registers, which you should not
simply dereference. A lot of things can go wrong there, especially
if future machines move to weakly ordered I/O subsystem or have
multiple CPUs, but even for the simple case, the compiler has
a lot of ways to mess this up.
As explained in my reply to the "hardware registers" patch, all these
pointers should be marked as __iomem, so that sparse warns about
dangerous accesses such as the one here.
The code above should be written as
{
writel(CONFIG_CMD(bus, devfn, where), PCICFG_ADDR);
switch (size) {
case 1:
*value = readl(PCICFG_DATA >> ((where & 3) * 8)) & 0xFF;
break;
case 2:
Arnd
next prev parent reply other threads:[~2011-02-17 17:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-16 7:52 [PATCH 10/12] unicore32 machine related files: pci bus handling Guan Xuetao
2011-02-16 7:52 ` Guan Xuetao
2011-02-17 17:19 ` Arnd Bergmann [this message]
2011-02-22 14:11 ` Guan Xuetao
2011-02-22 14:11 ` Guan Xuetao
2011-02-22 14:19 ` Arnd Bergmann
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=201102171819.52845.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=greg@kroah.com \
--cc=gxt@mprc.pku.edu.cn \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.