Commit 821047c4055cca833c4674f172a9d73003563eb6

Authored by Oliver Hartkopp
Committed by Marc Kleine-Budde
1 parent 4b5b82274a

can: remove CAN FD compatibility for CAN 2.0 sockets

In commit e2d265d3b587 (canfd: add support for CAN FD in CAN_RAW sockets)
CAN FD frames with a payload length up to 8 byte are passed to legacy
sockets where the CAN FD support was not enabled by the application.

After some discussions with developers at a fair this well meant feature
leads to confusion as no clean switch for CAN / CAN FD is provided to the
application programmer. Additionally a compatibility like this for legacy
CAN_RAW sockets requires some compatibility handling for the sending, e.g.
make CAN2.0 frames a CAN FD frame with BRS at transmission time (?!?).

This will become a mess when people start to develop applications with
real CAN FD hardware. This patch reverts the bad compatibility code
together with the documentation describing the removed feature.

Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Showing 2 changed files with 5 additions and 27 deletions Side-by-side Diff

Documentation/networking/can.txt
... ... @@ -554,12 +554,6 @@
554 554 not specified in the struct can_frame and therefore it is only valid in
555 555 CANFD_MTU sized CAN FD frames.
556 556  
557   - As long as the payload length is <=8 the received CAN frames from CAN FD
558   - capable CAN devices can be received and read by legacy sockets too. When
559   - user-generated CAN FD frames have a payload length <=8 these can be send
560   - by legacy CAN network interfaces too. Sending CAN FD frames with payload
561   - length > 8 to a legacy CAN network interface returns an -EMSGSIZE error.
562   -
563 557 Implementation hint for new CAN applications:
564 558  
565 559 To build a CAN FD aware application use struct canfd_frame as basic CAN
... ... @@ -121,14 +121,10 @@
121 121 if (!ro->recv_own_msgs && oskb->sk == sk)
122 122 return;
123 123  
124   - /* do not pass frames with DLC > 8 to a legacy socket */
125   - if (!ro->fd_frames) {
126   - struct canfd_frame *cfd = (struct canfd_frame *)oskb->data;
  124 + /* do not pass non-CAN2.0 frames to a legacy socket */
  125 + if (!ro->fd_frames && oskb->len != CAN_MTU)
  126 + return;
127 127  
128   - if (unlikely(cfd->len > CAN_MAX_DLEN))
129   - return;
130   - }
131   -
132 128 /* clone the given skb to be able to enqueue it into the rcv queue */
133 129 skb = skb_clone(oskb, GFP_ATOMIC);
134 130 if (!skb)
135 131  
... ... @@ -738,9 +734,7 @@
738 734 struct msghdr *msg, size_t size, int flags)
739 735 {
740 736 struct sock *sk = sock->sk;
741   - struct raw_sock *ro = raw_sk(sk);
742 737 struct sk_buff *skb;
743   - int rxmtu;
744 738 int err = 0;
745 739 int noblock;
746 740  
747 741  
... ... @@ -751,20 +745,10 @@
751 745 if (!skb)
752 746 return err;
753 747  
754   - /*
755   - * when serving a legacy socket the DLC <= 8 is already checked inside
756   - * raw_rcv(). Now check if we need to pass a canfd_frame to a legacy
757   - * socket and cut the possible CANFD_MTU/CAN_MTU length to CAN_MTU
758   - */
759   - if (!ro->fd_frames)
760   - rxmtu = CAN_MTU;
761   - else
762   - rxmtu = skb->len;
763   -
764   - if (size < rxmtu)
  748 + if (size < skb->len)
765 749 msg->msg_flags |= MSG_TRUNC;
766 750 else
767   - size = rxmtu;
  751 + size = skb->len;
768 752  
769 753 err = memcpy_toiovec(msg->msg_iov, skb->data, size);
770 754 if (err < 0) {