[soc:broadcom/drivers 2/4] drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:45: sparse: sparse: cast to restricted __le32

Rafał Miłecki rafal at milecki.pl
Thu Feb 11 01:44:00 EST 2021


On 10.02.2021 22:48, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git broadcom/drivers
> head:   8b8f095b9076ca61107c0910c9273afd1dfa1f04
> commit: 8bcac4011ebe0dbdd46fd55b036ee855c95702d3 [2/4] soc: bcm: add PM driver for Broadcom's PMB
> config: i386-randconfig-s002-20210211 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> reproduce:
>          # apt-get install sparse
>          # sparse version: v0.6.3-215-g0fb77bb6-dirty
>          # https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/commit/?id=8bcac4011ebe0dbdd46fd55b036ee855c95702d3
>          git remote add soc https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git
>          git fetch --no-tags soc broadcom/drivers
>          git checkout 8bcac4011ebe0dbdd46fd55b036ee855c95702d3
>          # save the attached .config to linux build tree
>          make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp at intel.com>
> 
> 
> "sparse warnings: (new ones prefixed by >>)"
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:65: sparse: sparse: cast to restricted __be32
>>> drivers/soc/bcm/bcm63xx/bcm-pmb.c:103:45: sparse: sparse: cast to restricted __le32
>>> drivers/soc/bcm/bcm63xx/bcm-pmb.c:115:36: sparse: sparse: restricted __le32 degrades to integer
>     drivers/soc/bcm/bcm63xx/bcm-pmb.c:115:55: sparse: sparse: restricted __be32 degrades to integer
> 
> vim +103 drivers/soc/bcm/bcm63xx/bcm-pmb.c
> 
>      90	
>      91	static int bcm_pmb_bpcm_read(struct bcm_pmb *pmb, int bus, u8 device,
>      92				     int offset, u32 *val)
>      93	{
>      94		void __iomem *base = pmb->base + bus * 0x20;
>      95		unsigned long flags;
>      96		int err;
>      97	
>      98		spin_lock_irqsave(&pmb->lock, flags);
>      99		err = bpcm_rd(base, device, offset, val);
>     100		spin_unlock_irqrestore(&pmb->lock, flags);
>     101	
>     102		if (!err)
>   > 103			*val = pmb->little_endian ? le32_to_cpu(*val) : be32_to_cpu(*val);
>     104	
>     105		return err;
>     106	}
>     107	
>     108	static int bcm_pmb_bpcm_write(struct bcm_pmb *pmb, int bus, u8 device,
>     109				      int offset, u32 val)
>     110	{
>     111		void __iomem *base = pmb->base + bus * 0x20;
>     112		unsigned long flags;
>     113		int err;
>     114	
>   > 115		val = pmb->little_endian ? cpu_to_le32(val) : cpu_to_be32(val);
>     116	
>     117		spin_lock_irqsave(&pmb->lock, flags);
>     118		err = bpcm_wr(base, device, offset, val);
>     119		spin_unlock_irqrestore(&pmb->lock, flags);
>     120	
>     121		return err;
>     122	}
>     123	

Florian: can you review above code & verify my logic is correct there?
That I need to use le32_to_cpu() / be32_to_cpu() on the readl() value?

Assuming my logic is correct, above code doesn't use __le32 / __be32 as
that would require extra variables and code paths. Current code is quite
simple & clear.

Is there any way of avoiding those sparse warnings?



More information about the linux-arm-kernel mailing list