Re: [PATCH v2 01/11] mm/ioremap: change the return value of io[re|un]map_allowed and rename
From: Baoquan He
Date: Sun Aug 28 2022 - 05:58:04 EST
On 08/28/22 at 10:36am, Alexander Gordeev wrote:
> On Sat, Aug 20, 2022 at 08:31:15AM +0800, Baoquan He wrote:
>
> Hi Baoquan,
>
> > arch_ioremap() return a bool,
> > - IS_ERR means return an error
> > - NULL means continue to remap
> > - a non-NULL, non-IS_ERR pointer is returned directly
> > arch_iounmap() return a bool,
> > - 0 means continue to vunmap
> > - error code means skip vunmap and return directly
>
> It would make more sense if the return values were described
> from the prospective of an architecture, not the caller.
> I.e true - unmapped, false - not supported, etc.
Yes, sounds reasonable to me, thanks.
While ChristopheL suggested to take another way. Please see below link.
I will reply to Christophe to discuss that.
https://lore.kernel.org/all/8df89136-a7f2-9b66-d522-a4fb9860bf22@xxxxxxxxxx/T/#u
If the current arch_ioremap() way is taken, I will change the
description as you said.
>
> > diff --git a/mm/ioremap.c b/mm/ioremap.c
> > index 8652426282cc..99fde69becc7 100644
> > --- a/mm/ioremap.c
> > +++ b/mm/ioremap.c
> > @@ -17,6 +17,13 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
> > unsigned long offset, vaddr;
> > phys_addr_t last_addr;
> > struct vm_struct *area;
> > + void __iomem *ioaddr;
> > +
> > + ioaddr = arch_ioremap(phys_addr, size, prot);
> > + if (IS_ERR(ioaddr))
> > + return NULL;
> > + else if (ioaddr)
> > + return ioaddr;
>
> It seems to me arch_ioremap() could simply return an address
> or an error. Then IOMEM_ERR_PTR(-ENOSYS) if the architecture
> does not support it reads much better than the cryptic NULL.
I may not follow. Returning NULL means arch_ioremap() doesn't give out a
mapped address and doesn't encounter wrong thing. NULL is a little
twisting, maybe '0' is better?
>
> Probably arch_iounmap() returning error would look better too,
> though not sure about that.
Don't follow either. arch_iounmap() is returning error now.