From: Felipe Balbi <me@felipebalbi.com>
To: linux-kernel@vger.kernel.org
Subject: Question of resource_size() implementation
Date: Wed, 30 Dec 2009 01:43:54 +0200 [thread overview]
Message-ID: <1262130234.28789.112.camel@gandalf> (raw)
Hi all,
I'm wondering whether the +1 in resource_size() is actually necessary.
To illustrate the problem imagine we have two subsequent 4k memory areas
which should be passed to ioremap(). When passing those address spaces
to the drivers we will use struct resource and define something like:
#define MEM_AREA1_BASE 0x480ab000
#define MEM_AREA2_BASE 0x480ac000
struct resource my_device_resources = {
{
.start = MEM_AREA1_BASE,
.end = MEM_AREA1_BASE + SZ_4K - 1,
.flags = IORESOURCE_MEM,
},
{
.start = MEM_AREA2_BASE,
.end = MEM_AREA2_BASE + SZ_4K - 1,
.flags = IORESOURCE_MEM,
},
};
that -1 would cause us to pass the correct end for each area,
respectively 0x480abfff and 0x480acffff, right ?
But resource_size() is defined as:
static inline resource_size_t resource_size(const struct resource *res)
{
return res->end - res->start + 1;
}
then we put +1 again and the end addresses would then become
respectively 0x480ac000 and 0x480ad0000. Wouldn't we then fail ioremap()
of the second area ? wouldn't it return -EBUSY ? Are we off-by-one
here ? Or is this all expected ?
I have to say, I didn't test this on real hw yet...
--
balbi
next reply other threads:[~2009-12-29 23:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-29 23:43 Felipe Balbi [this message]
[not found] ` <1262131932.1888.202.camel@Joe-Laptop.home>
2009-12-30 0:16 ` Felipe Balbi
2009-12-30 1:04 ` Ben Nizette
2009-12-30 1:08 ` Ben Nizette
2009-12-30 1:11 ` Felipe Balbi
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=1262130234.28789.112.camel@gandalf \
--to=me@felipebalbi.com \
--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 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®