Subject: Re: [PATCH] mvebu: fix __iomem on mvebu_pm_store_armadaxp_bootinfo()

From: Russell King - ARM Linux admin <[email-masked]>
Date: Wed, 9 Oct 2019 17:00:19 +0100

On Wed, Oct 09, 2019 at 04:33:42PM +0100, Ben Dooks wrote:
> The mvebu_pm_store_armadaxp_bootinfo() uses writel to
> store data, so the pointer into it should be __iomem
> annotated. Fixes the following sparse warnings:
> 
> arch/arm/mach-mvebu/pm.c:124:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:124:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:124:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:125:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:125:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:125:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:133:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:133:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:133:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:134:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:134:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:134:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:140:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:140:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:140:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:141:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:141:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:141:9:    got unsigned int [usertype] *
> arch/arm/mach-mvebu/pm.c:148:50: warning: incorrect type in argument 1 (different address spaces)
> arch/arm/mach-mvebu/pm.c:148:50:    expected unsigned int [noderef] [usertype] <asn:2> *store_addr
> arch/arm/mach-mvebu/pm.c:148:50:    got unsigned int [usertype] *[assigned] store_addr
> arch/arm/mach-mvebu/pm.c:150:9: warning: incorrect type in argument 2 (different address spaces)
> arch/arm/mach-mvebu/pm.c:150:9:    expected void volatile [noderef] <asn:2> *addr
> arch/arm/mach-mvebu/pm.c:150:9:    got unsigned int [usertype] *[assigned] store_addr
> 
> Note, this doesn't take into account writel() is probably heavy
> handed here and just writing the data and then flushing all the
> caches etc would be good enough.

This is definitely wrong.

> Signed-off-by: Ben Dooks <[email-masked]>
> ---
> Cc: Jason Cooper <[email-masked]>
> Cc: Andrew Lunn <[email-masked]>
> Cc: Gregory Clement <[email-masked]>
> Cc: Sebastian Hesselbarth <[email-masked]>
> Cc: Russell King <[email-masked]>
> Cc: [email-masked]
> ---
>  arch/arm/mach-mvebu/pm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-mvebu/pm.c b/arch/arm/mach-mvebu/pm.c
> index c487be61d6d8..c223f87ed338 100644
> --- a/arch/arm/mach-mvebu/pm.c
> +++ b/arch/arm/mach-mvebu/pm.c
> @@ -106,7 +106,7 @@ static phys_addr_t mvebu_internal_reg_base(void)
>  	return of_translate_address(np, in_addr);
>  }
>  
> -static void mvebu_pm_store_armadaxp_bootinfo(u32 *store_addr)
> +static void mvebu_pm_store_armadaxp_bootinfo(u32 __iomem *store_addr)
>  {
>  	phys_addr_t resume_pc;
>  
> @@ -152,9 +152,9 @@ static void mvebu_pm_store_armadaxp_bootinfo(u32 *store_addr)
>  
>  static int mvebu_pm_store_bootinfo(void)
>  {
> -	u32 *store_addr;
> +	u32 __iomem *store_addr;
>  
> -	store_addr = phys_to_virt(BOOT_INFO_ADDR);
> +	store_addr = (__force __iomem u32*)phys_to_virt(BOOT_INFO_ADDR);

phys_to_virt() does not return an iomem pointer, so the memory pointed
to here is _not_ iomem.  Thus, iomem accessors should not be used - and
that's where the problem actually lies.

>  
>  	if (of_machine_is_compatible("marvell,armadaxp"))
>  		mvebu_pm_store_armadaxp_bootinfo(store_addr);
> -- 
> 2.23.0
> 
> 

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

_______________________________________________
linux-arm-kernel mailing list
[email-masked]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel