diff mbox

[v2] xen/arm: ioremap_attr: return NULL is __vmap failed

Message ID 1384780103-10183-1-git-send-email-julien.grall@linaro.org
State Accepted, archived
Headers show

Commit Message

Julien Grall Nov. 18, 2013, 1:08 p.m. UTC
Most of ioremap_* caller check if ioremap returns NULL. Actually, if the
physical address is non-aligned, Xen will return the pointer given by
__vmap plus the offset in the page. So if ioremap_* fails, the caller
will retrieve an non-NULL address and continue as if there was no error.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---
    Changes in v2:
        - remove brackets for return
        - don't split declaration and initialisation of ptr
---
 xen/arch/arm/mm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Ian Campbell Nov. 19, 2013, 2:45 p.m. UTC | #1
On Mon, 2013-11-18 at 13:08 +0000, Julien Grall wrote:
> Most of ioremap_* caller check if ioremap returns NULL. Actually, if the
> physical address is non-aligned, Xen will return the pointer given by
> __vmap plus the offset in the page. So if ioremap_* fails, the caller
> will retrieve an non-NULL address and continue as if there was no error.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>
Ian Campbell Nov. 19, 2013, 4:42 p.m. UTC | #2
On Tue, 2013-11-19 at 14:45 +0000, Ian Campbell wrote:
> On Mon, 2013-11-18 at 13:08 +0000, Julien Grall wrote:
> > Most of ioremap_* caller check if ioremap returns NULL. Actually, if the
> > physical address is non-aligned, Xen will return the pointer given by
> > __vmap plus the offset in the page. So if ioremap_* fails, the caller
> > will retrieve an non-NULL address and continue as if there was no error.
> > 
> > Signed-off-by: Julien Grall <julien.grall@linaro.org>
> > Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

Applied this + 
xen/arm: Panic if platform initialization failed
xen/arm: Panic if we are unable to initialize platform timer

from the first posting.
diff mbox

Patch

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 26c6768..d5b22a4 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -742,8 +742,12 @@  void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes)
     unsigned long pfn = PFN_DOWN(pa);
     unsigned int offs = pa & (PAGE_SIZE - 1);
     unsigned int nr = PFN_UP(offs + len);
+    void *ptr = __vmap(&pfn, nr, 1, 1, attributes);
 
-    return (__vmap(&pfn, nr, 1, 1, attributes) + offs);
+    if ( ptr == NULL )
+        return NULL;
+
+    return ptr + offs;
 }
 
 void *ioremap(paddr_t pa, size_t len)