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

3 messages, 3 authors, 2021-02-11 · open the first message on its own page

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

From: kernel test robot <hidden>
Date: 2021-02-10 21:51:06

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


"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
quoted
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	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

From: Rafał Miłecki <rafal@milecki.pl>
Date: 2021-02-11 06:46:01

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


"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
quoted
quoted
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?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

From: Arnd Bergmann <arnd@kernel.org>
Date: 2021-02-11 11:07:33

On Thu, Feb 11, 2021 at 7:44 AM Rafał Miłecki [off-list ref] wrote:
On 10.02.2021 22:48, kernel test robot wrote:

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?
I'm fairly sure the logic is incorrect.
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.
The problem is that readl() assumes that a register is little-endian in
hardware, and it performs a byteswap when running on a big-endian
machine (on most architectures).

The usual way to encode this is to use

      if (device->big_endian)
                 return ioread32be(device->reg + offset);
     else
                 return ioread32(device->reg + offset);

You can treat ioread32() as an alias for readl() in practice, while
ioread32be() produces the byte-reversed result of that.

If you however also need to run this on big-endian mips, you
might need to wrap this in another #ifdef that accounts for
the different behavior on that architecture, where readl()
sometimes sometimes assumes the register is cpu-endian
rather than little-endian.

        Arnd

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help