2020-06-12 05:57:44

by kernel test robot

[permalink] [raw]
Subject: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: b791d1bdf9212d944d749a5c7ff6febdba241771
commit: 26ad340e582d3d5958ed8456a1911d79cfb567b4 can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices
date: 11 months ago
config: m68k-randconfig-s032-20200612 (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-250-g42323db3-dirty
git checkout 26ad340e582d3d5958ed8456a1911d79cfb567b4
# save the attached .config to linux build tree
make W=1 C=1 ARCH=m68k CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)

>> drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression
drivers/net/can/kvaser_pciefd.c:805:17: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32

vim +801 drivers/net/can/kvaser_pciefd.c

764
765 static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb,
766 struct net_device *netdev)
767 {
768 struct kvaser_pciefd_can *can = netdev_priv(netdev);
769 unsigned long irq_flags;
770 struct kvaser_pciefd_tx_packet packet;
771 int nwords;
772 u8 count;
773
774 if (can_dropped_invalid_skb(netdev, skb))
775 return NETDEV_TX_OK;
776
777 nwords = kvaser_pciefd_prepare_tx_packet(&packet, can, skb);
778
779 spin_lock_irqsave(&can->echo_lock, irq_flags);
780
781 /* Prepare and save echo skb in internal slot */
782 can_put_echo_skb(skb, netdev, can->echo_idx);
783
784 /* Move echo index to the next slot */
785 can->echo_idx = (can->echo_idx + 1) % can->can.echo_skb_max;
786
787 /* Write header to fifo */
788 iowrite32(packet.header[0],
789 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
790 iowrite32(packet.header[1],
791 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
792
793 if (nwords) {
794 u32 data_last = ((u32 *)packet.data)[nwords - 1];
795
796 /* Write data to fifo, except last word */
797 iowrite32_rep(can->reg_base +
798 KVASER_PCIEFD_KCAN_FIFO_REG, packet.data,
799 nwords - 1);
800 /* Write last word to end of fifo */
> 801 __raw_writel(data_last, can->reg_base +
802 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
803 } else {
804 /* Complete write to fifo */
805 __raw_writel(0, can->reg_base +
806 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
807 }
808
809 count = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG);
810 /* No room for a new message, stop the queue until at least one
811 * successful transmit
812 */
813 if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||
814 can->can.echo_skb[can->echo_idx])
815 netif_stop_queue(netdev);
816
817 spin_unlock_irqrestore(&can->echo_lock, irq_flags);
818
819 return NETDEV_TX_OK;
820 }
821

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (8.13 kB)
.config.gz (25.46 kB)
Download all attachments

2020-06-12 07:52:03

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression

Hello Greg,

the k-build robot found this sparse problem, triggered by building a CAN driver
for m68k. Is this a problem in our CAN driver or in the m68k headers?

Marc

On 6/12/20 7:28 AM, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: b791d1bdf9212d944d749a5c7ff6febdba241771
> commit: 26ad340e582d3d5958ed8456a1911d79cfb567b4 can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices
> date: 11 months ago
> config: m68k-randconfig-s032-20200612 (attached as .config)
> compiler: m68k-linux-gcc (GCC) 9.3.0
> reproduce:
> # apt-get install sparse
> # sparse version: v0.6.1-250-g42323db3-dirty
> git checkout 26ad340e582d3d5958ed8456a1911d79cfb567b4
> # save the attached .config to linux build tree
> make W=1 C=1 ARCH=m68k CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <[email protected]>
>
>
> sparse warnings: (new ones prefixed by >>)
>
>>> drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression
> drivers/net/can/kvaser_pciefd.c:805:17: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>
> vim +801 drivers/net/can/kvaser_pciefd.c
>
> 764
> 765 static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb,
> 766 struct net_device *netdev)
> 767 {
> 768 struct kvaser_pciefd_can *can = netdev_priv(netdev);
> 769 unsigned long irq_flags;
> 770 struct kvaser_pciefd_tx_packet packet;
> 771 int nwords;
> 772 u8 count;
> 773
> 774 if (can_dropped_invalid_skb(netdev, skb))
> 775 return NETDEV_TX_OK;
> 776
> 777 nwords = kvaser_pciefd_prepare_tx_packet(&packet, can, skb);
> 778
> 779 spin_lock_irqsave(&can->echo_lock, irq_flags);
> 780
> 781 /* Prepare and save echo skb in internal slot */
> 782 can_put_echo_skb(skb, netdev, can->echo_idx);
> 783
> 784 /* Move echo index to the next slot */
> 785 can->echo_idx = (can->echo_idx + 1) % can->can.echo_skb_max;
> 786
> 787 /* Write header to fifo */
> 788 iowrite32(packet.header[0],
> 789 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
> 790 iowrite32(packet.header[1],
> 791 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
> 792
> 793 if (nwords) {
> 794 u32 data_last = ((u32 *)packet.data)[nwords - 1];
> 795
> 796 /* Write data to fifo, except last word */
> 797 iowrite32_rep(can->reg_base +
> 798 KVASER_PCIEFD_KCAN_FIFO_REG, packet.data,
> 799 nwords - 1);
> 800 /* Write last word to end of fifo */
> > 801 __raw_writel(data_last, can->reg_base +
> 802 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
> 803 } else {
> 804 /* Complete write to fifo */
> 805 __raw_writel(0, can->reg_base +
> 806 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
> 807 }
> 808
> 809 count = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG);
> 810 /* No room for a new message, stop the queue until at least one
> 811 * successful transmit
> 812 */
> 813 if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||
> 814 can->can.echo_skb[can->echo_idx])
> 815 netif_stop_queue(netdev);
> 816
> 817 spin_unlock_irqrestore(&can->echo_lock, irq_flags);
> 818
> 819 return NETDEV_TX_OK;
> 820 }
> 821
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/[email protected]
>


--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2020-06-12 15:38:09

by Greg Ungerer

[permalink] [raw]
Subject: Re: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression

Hi Marc,

On 12/6/20 5:48 pm, Marc Kleine-Budde wrote:
> the k-build robot found this sparse problem, triggered by building a CAN driver
> for m68k. Is this a problem in our CAN driver or in the m68k headers?

I suspect a problem with the m68k (specifically non-mmu) headers.


> On 6/12/20 7:28 AM, kernel test robot wrote:
>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>> head: b791d1bdf9212d944d749a5c7ff6febdba241771
>> commit: 26ad340e582d3d5958ed8456a1911d79cfb567b4 can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices
>> date: 11 months ago
>> config: m68k-randconfig-s032-20200612 (attached as .config)
>> compiler: m68k-linux-gcc (GCC) 9.3.0
>> reproduce:
>> # apt-get install sparse
>> # sparse version: v0.6.1-250-g42323db3-dirty
>> git checkout 26ad340e582d3d5958ed8456a1911d79cfb567b4
>> # save the attached .config to linux build tree
>> make W=1 C=1 ARCH=m68k CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
>>
>> If you fix the issue, kindly add following tag as appropriate
>> Reported-by: kernel test robot <[email protected]>
>>
>>
>> sparse warnings: (new ones prefixed by >>)
>>
>>>> drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression
>> drivers/net/can/kvaser_pciefd.c:805:17: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression

I think this one is due to not forcing the volatile cast in __raw_write().
So this change will fix that:

diff --git a/arch/m68k/include/asm/io_no.h b/arch/m68k/include/asm/io_no.h
index 0498192e1d98..1bc739f1f1ad 100644
--- a/arch/m68k/include/asm/io_no.h
+++ b/arch/m68k/include/asm/io_no.h
@@ -14,15 +14,15 @@
* that behavior here first before we include asm-generic/io.h.
*/
#define __raw_readb(addr) \
- ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
+ ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
#define __raw_readw(addr) \
- ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
+ ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
#define __raw_readl(addr) \
- ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
+ ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })

-#define __raw_writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
-#define __raw_writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
-#define __raw_writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
+#define __raw_writeb(b, addr) (void)((*(__force volatile u8 *) (addr)) = (b))
+#define __raw_writew(b, addr) (void)((*(__force volatile u16 *) (addr)) = (b))
+#define __raw_writel(b, addr) (void)((*(__force volatile u32 *) (addr)) = (b))

#if defined(CONFIG_COLDFIRE)
/*


>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32

This one I am not sure about yet.
Still investigating.

Regards
Greg


>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:77:24: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast removes address space '<asn:2>' of expression
>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>>
>> vim +801 drivers/net/can/kvaser_pciefd.c
>>
>> 764
>> 765 static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb,
>> 766 struct net_device *netdev)
>> 767 {
>> 768 struct kvaser_pciefd_can *can = netdev_priv(netdev);
>> 769 unsigned long irq_flags;
>> 770 struct kvaser_pciefd_tx_packet packet;
>> 771 int nwords;
>> 772 u8 count;
>> 773
>> 774 if (can_dropped_invalid_skb(netdev, skb))
>> 775 return NETDEV_TX_OK;
>> 776
>> 777 nwords = kvaser_pciefd_prepare_tx_packet(&packet, can, skb);
>> 778
>> 779 spin_lock_irqsave(&can->echo_lock, irq_flags);
>> 780
>> 781 /* Prepare and save echo skb in internal slot */
>> 782 can_put_echo_skb(skb, netdev, can->echo_idx);
>> 783
>> 784 /* Move echo index to the next slot */
>> 785 can->echo_idx = (can->echo_idx + 1) % can->can.echo_skb_max;
>> 786
>> 787 /* Write header to fifo */
>> 788 iowrite32(packet.header[0],
>> 789 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
>> 790 iowrite32(packet.header[1],
>> 791 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
>> 792
>> 793 if (nwords) {
>> 794 u32 data_last = ((u32 *)packet.data)[nwords - 1];
>> 795
>> 796 /* Write data to fifo, except last word */
>> 797 iowrite32_rep(can->reg_base +
>> 798 KVASER_PCIEFD_KCAN_FIFO_REG, packet.data,
>> 799 nwords - 1);
>> 800 /* Write last word to end of fifo */
>> > 801 __raw_writel(data_last, can->reg_base +
>> 802 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
>> 803 } else {
>> 804 /* Complete write to fifo */
>> 805 __raw_writel(0, can->reg_base +
>> 806 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
>> 807 }
>> 808
>> 809 count = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG);
>> 810 /* No room for a new message, stop the queue until at least one
>> 811 * successful transmit
>> 812 */
>> 813 if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||
>> 814 can->can.echo_skb[can->echo_idx])
>> 815 netif_stop_queue(netdev);
>> 816
>> 817 spin_unlock_irqrestore(&can->echo_lock, irq_flags);
>> 818
>> 819 return NETDEV_TX_OK;
>> 820 }
>> 821
>>
>> ---
>> 0-DAY CI Kernel Test Service, Intel Corporation
>> https://lists.01.org/hyperkitty/list/[email protected]
>>
>
>

2020-06-12 16:40:53

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression

On Sat, Jun 13, 2020 at 01:33:16AM +1000, Greg Ungerer wrote:
> Hi Marc,
>
> On 12/6/20 5:48 pm, Marc Kleine-Budde wrote:
> > the k-build robot found this sparse problem, triggered by building a CAN driver
> > for m68k. Is this a problem in our CAN driver or in the m68k headers?
>
> I suspect a problem with the m68k (specifically non-mmu) headers.

Indeed.

> I think this one is due to not forcing the volatile cast in __raw_write().
> So this change will fix that:
>
> diff --git a/arch/m68k/include/asm/io_no.h b/arch/m68k/include/asm/io_no.h
> index 0498192e1d98..1bc739f1f1ad 100644
> --- a/arch/m68k/include/asm/io_no.h
> +++ b/arch/m68k/include/asm/io_no.h
> @@ -14,15 +14,15 @@
> * that behavior here first before we include asm-generic/io.h.
> */
> #define __raw_readb(addr) \
> - ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
> + ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
> #define __raw_readw(addr) \
> - ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
> + ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
> #define __raw_readl(addr) \
> - ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
> + ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
> -#define __raw_writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
> -#define __raw_writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
> -#define __raw_writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
> +#define __raw_writeb(b, addr) (void)((*(__force volatile u8 *) (addr)) = (b))
> +#define __raw_writew(b, addr) (void)((*(__force volatile u16 *) (addr)) = (b))
> +#define __raw_writel(b, addr) (void)((*(__force volatile u32 *) (addr)) = (b))

Look good to me but isn't easier to leave them undefined and include
asm-generic/io.h?

> > > arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>
> This one I am not sure about yet.
> Still investigating.

swab32(__raw_readl(addr)) ?

Keeping __le32_to_cpu() will only force you to use ugly casts for no benefits
and the comment above explain clearly the situation about the endianness.

Best regards,
-- Luc

2020-06-13 02:26:52

by Greg Ungerer

[permalink] [raw]
Subject: Re: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression


On 13/6/20 2:35 am, Luc Van Oostenryck wrote:
> On Sat, Jun 13, 2020 at 01:33:16AM +1000, Greg Ungerer wrote:
>> On 12/6/20 5:48 pm, Marc Kleine-Budde wrote:
>> I think this one is due to not forcing the volatile cast in __raw_write().
>> So this change will fix that:
>>
>> diff --git a/arch/m68k/include/asm/io_no.h b/arch/m68k/include/asm/io_no.h
>> index 0498192e1d98..1bc739f1f1ad 100644
>> --- a/arch/m68k/include/asm/io_no.h
>> +++ b/arch/m68k/include/asm/io_no.h
>> @@ -14,15 +14,15 @@
>> * that behavior here first before we include asm-generic/io.h.
>> */
>> #define __raw_readb(addr) \
>> - ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
>> + ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
>> #define __raw_readw(addr) \
>> - ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
>> + ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
>> #define __raw_readl(addr) \
>> - ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
>> + ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
>> -#define __raw_writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
>> -#define __raw_writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
>> -#define __raw_writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
>> +#define __raw_writeb(b, addr) (void)((*(__force volatile u8 *) (addr)) = (b))
>> +#define __raw_writew(b, addr) (void)((*(__force volatile u16 *) (addr)) = (b))
>> +#define __raw_writel(b, addr) (void)((*(__force volatile u32 *) (addr)) = (b))
>
> Look good to me but isn't easier to leave them undefined and include
> asm-generic/io.h?

Not so simple at the moment. Although juggling a few things around within
io_no.h will let you use the asm-generic functions it will now throw up
a _lot_ of warnings in many of the architecture files that pass int constant
addresses to the raw_* functions. That is on my todo list.

Regards
Greg

2020-06-15 07:10:05

by Greg Ungerer

[permalink] [raw]
Subject: Re: drivers/net/can/kvaser_pciefd.c:801:17: sparse: sparse: cast removes address space '<asn:2>' of expression


On 13/6/20 2:35 am, Luc Van Oostenryck wrote:
> On Sat, Jun 13, 2020 at 01:33:16AM +1000, Greg Ungerer wrote:
>>>> arch/m68k/include/asm/io_no.h:78:16: sparse: sparse: cast to restricted __le32
>>
>> This one I am not sure about yet.
>> Still investigating.
>
> swab32(__raw_readl(addr)) ?
>
> Keeping __le32_to_cpu() will only force you to use ugly casts for no benefits
> and the comment above explain clearly the situation about the endianness.

That is unfortunate, the use of le32_to_cpu() made it very clear
what was going on - for those that don't choose to read comments.

In any case that would seem to be the cleanest solution.
Patch to follow.

Regards
Greg