diff mbox series

[net,03/11] can: isotp: TX-path: ensure that CAN frame flags are initialized

Message ID 20210316082104.4027260-4-mkl@pengutronix.de
State New
Headers show
Series None | expand

Commit Message

Marc Kleine-Budde March 16, 2021, 8:20 a.m. UTC
The previous patch ensures that the TX flags (struct
can_isotp_ll_options::tx_flags) are 0 for classic CAN frames or a user
configured value for CAN-FD frames.

This patch sets the CAN frames flags unconditionally to the ISO-TP TX
flags, so that they are initialized to a proper value. Otherwise when
running "candump -x" on a classical CAN ISO-TP stream shows wrongly
set "B" and "E" flags.

| $ candump any,0:0,#FFFFFFFF -extA
| [...]
| can0  TX B E  713   [8]  2B 0A 0B 0C 0D 0E 0F 00
| can0  TX B E  713   [8]  2C 01 02 03 04 05 06 07
| can0  TX B E  713   [8]  2D 08 09 0A 0B 0C 0D 0E
| can0  TX B E  713   [8]  2E 0F 00 01 02 03 04 05

Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Link: https://lore.kernel.org/r/20210218215434.1708249-2-mkl@pengutronix.de
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/isotp.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Oliver Hartkopp March 18, 2021, 10:11 a.m. UTC | #1
Hello Marc,

I obviously missed these patches - but they are fine. Thanks!

After checking your patch I was going after this missing initialization 
and detected that the outgoing CAN frame skbs from isotp.c were not 
properly zero initialized - so I sent a patch for it some minutes ago:

https://lore.kernel.org/linux-can/20210318100233.1693-1-socketcan@hartkopp.net/T/#u

In fact I had

 > CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y

 > CONFIG_INIT_ON_FREE_DEFAULT_ON=y


in my local kernel config therefore I was not able to see it on my own :-/

Best,
Oliver

On 16.03.21 09:20, Marc Kleine-Budde wrote:
> The previous patch ensures that the TX flags (struct

> can_isotp_ll_options::tx_flags) are 0 for classic CAN frames or a user

> configured value for CAN-FD frames.

> 

> This patch sets the CAN frames flags unconditionally to the ISO-TP TX

> flags, so that they are initialized to a proper value. Otherwise when

> running "candump -x" on a classical CAN ISO-TP stream shows wrongly

> set "B" and "E" flags.

> 

> | $ candump any,0:0,#FFFFFFFF -extA

> | [...]

> | can0  TX B E  713   [8]  2B 0A 0B 0C 0D 0E 0F 00

> | can0  TX B E  713   [8]  2C 01 02 03 04 05 06 07

> | can0  TX B E  713   [8]  2D 08 09 0A 0B 0C 0D 0E

> | can0  TX B E  713   [8]  2E 0F 00 01 02 03 04 05

> 

> Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")

> Link: https://lore.kernel.org/r/20210218215434.1708249-2-mkl@pengutronix.de

> Cc: Oliver Hartkopp <socketcan@hartkopp.net>

> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

> ---

>   net/can/isotp.c | 9 +++------

>   1 file changed, 3 insertions(+), 6 deletions(-)

> 

> diff --git a/net/can/isotp.c b/net/can/isotp.c

> index e32d446c121e..430976485d95 100644

> --- a/net/can/isotp.c

> +++ b/net/can/isotp.c

> @@ -215,8 +215,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)

>   	if (ae)

>   		ncf->data[0] = so->opt.ext_address;

>   

> -	if (so->ll.mtu == CANFD_MTU)

> -		ncf->flags = so->ll.tx_flags;

> +	ncf->flags = so->ll.tx_flags;

>   

>   	can_send_ret = can_send(nskb, 1);

>   	if (can_send_ret)

> @@ -790,8 +789,7 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)

>   		so->tx.sn %= 16;

>   		so->tx.bs++;

>   

> -		if (so->ll.mtu == CANFD_MTU)

> -			cf->flags = so->ll.tx_flags;

> +		cf->flags = so->ll.tx_flags;

>   

>   		skb->dev = dev;

>   		can_skb_set_owner(skb, sk);

> @@ -939,8 +937,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)

>   	}

>   

>   	/* send the first or only CAN frame */

> -	if (so->ll.mtu == CANFD_MTU)

> -		cf->flags = so->ll.tx_flags;

> +	cf->flags = so->ll.tx_flags;

>   

>   	skb->dev = dev;

>   	skb->sk = sk;

>
diff mbox series

Patch

diff --git a/net/can/isotp.c b/net/can/isotp.c
index e32d446c121e..430976485d95 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -215,8 +215,7 @@  static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
 	if (ae)
 		ncf->data[0] = so->opt.ext_address;
 
-	if (so->ll.mtu == CANFD_MTU)
-		ncf->flags = so->ll.tx_flags;
+	ncf->flags = so->ll.tx_flags;
 
 	can_send_ret = can_send(nskb, 1);
 	if (can_send_ret)
@@ -790,8 +789,7 @@  static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
 		so->tx.sn %= 16;
 		so->tx.bs++;
 
-		if (so->ll.mtu == CANFD_MTU)
-			cf->flags = so->ll.tx_flags;
+		cf->flags = so->ll.tx_flags;
 
 		skb->dev = dev;
 		can_skb_set_owner(skb, sk);
@@ -939,8 +937,7 @@  static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	}
 
 	/* send the first or only CAN frame */
-	if (so->ll.mtu == CANFD_MTU)
-		cf->flags = so->ll.tx_flags;
+	cf->flags = so->ll.tx_flags;
 
 	skb->dev = dev;
 	skb->sk = sk;