Re: can: m_can: m_can_read_fifo, can_fd_dlc2len returns sometimes cf->len=0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12.11.2021 13:11:06, Michael Anochin wrote:
> Hello,
> 
> I use tcan4x5x over m_can driver with CANFD tcan4450 chip. Sometimes after
> continuous communication I get in dmesg
> tcan4x5x spi4.0 can1: FIFO read returned -22 . After that nothing works.
> 
> I have followed this behavior up to can_fd_dlc2len and found the following:
> 1. in m_can.c,  function m_can_read_fifo does
>     cf->len = can_fd_dlc2len((fifo_header.dlc >> 16) & 0x0F);
>     cf->len = 0
>     DIV_ROUND_UP(cf->len, 4)
> 
> 2. m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA, cf->data,
> DIV_ROUND_UP(cf->len, 4)) returns error because val_count=0
> 3. Following further chain with val_count=0:
>     cdev->ops->read_fifo(cdev, addr_offset, val, val_count) ->
> tcan4x5x_read_fifo -> regmap_bulk_read -> ret -EINVAL
> 
> I can try to look deeper at fifo_header. Perhaps someone has the possible
> cause of this behavior.

It seems the driver break when trying to send CAN frame with 0 length.
First try to reproduce if 'cansend can0 abc#' breaks the driver. Then
check if this patch helps:

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index ab4371aa4ff1..4278009c3eea 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -336,6 +336,9 @@ m_can_fifo_read(struct m_can_classdev *cdev,
        u32 addr_offset = cdev->mcfg[MRAM_RXF0].off + fgi * RXF0_ELEMENT_SIZE +
                offset;
 
+       if (val_count == 0)
+               return 0;
+
        return cdev->ops->read_fifo(cdev, addr_offset, val, val_count);
 }
 
@@ -346,6 +349,9 @@ m_can_fifo_write(struct m_can_classdev *cdev,
        u32 addr_offset = cdev->mcfg[MRAM_TXB].off + fpi * TXB_ELEMENT_SIZE +
                offset;
 
+       if (val_count == 0)
+               return 0;
+
        return cdev->ops->write_fifo(cdev, addr_offset, val, val_count);
 }

regards,
Marc

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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux