Re: [PATCH v2 01/11] mm/ioremap: change the return value of io[re|un]map_allowed and rename

From: Alexander Gordeev
Date: Sun Aug 28 2022 - 04:36:56 EST


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.

> 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.

Probably arch_iounmap() returning error would look better too,
though not sure about that.

Thanks!