summaryrefslogtreecommitdiff
path: root/net/can
diff options
context:
space:
mode:
authorAlexander Hölzl <alexander.hoelzl@gmx.net>2025-02-05 18:46:51 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-03-13 12:43:16 +0100
commit1abecca55d863e2ee8c31a167b918fed5dcec004 (patch)
tree57c4e7935ab2bc060d113aef92b4eecc80aa6d42 /net/can
parent85069553d1715b34af0f1e818959d07af75ff5f4 (diff)
downloadlinux-1abecca55d863e2ee8c31a167b918fed5dcec004.tar.gz
linux-1abecca55d863e2ee8c31a167b918fed5dcec004.tar.bz2
linux-1abecca55d863e2ee8c31a167b918fed5dcec004.zip
can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero
commit 44de577e61ed239db09f0da9d436866bef9b77dd upstream. The J1939 standard requires the transmission of messages of length 0. For example proprietary messages are specified with a data length of 0 to 1785. The transmission of such messages is not possible. Sending results in no error being returned but no corresponding can frame being generated. Enable the transmission of zero length J1939 messages. In order to facilitate this two changes are necessary: 1) If the transmission of a new message is requested from user space the message is segmented in j1939_sk_send_loop(). Let the segmentation take into account zero length messages, do not terminate immediately, queue the corresponding skb. 2) j1939_session_skb_get_by_offset() selects the next skb to transmit for a session. Take into account that there might be zero length skbs in the queue. Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://patch.msgid.link/20250205174651.103238-1-alexander.hoelzl@gmx.net Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: stable@vger.kernel.org [mkl: commit message rephrased] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/can')
-rw-r--r--net/can/j1939/socket.c4
-rw-r--r--net/can/j1939/transport.c5
2 files changed, 5 insertions, 4 deletions
diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 2e3dc74fea21..29f9a343b0db 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -1055,7 +1055,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv, struct sock *sk,
todo_size = size;
- while (todo_size) {
+ do {
struct j1939_sk_buff_cb *skcb;
segment_size = min_t(size_t, J1939_MAX_TP_PACKET_SIZE,
@@ -1100,7 +1100,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv, struct sock *sk,
todo_size -= segment_size;
session->total_queued_size += segment_size;
- }
+ } while (todo_size);
switch (ret) {
case 0: /* OK */
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 7cef19287a3f..d75b71f6491a 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -378,8 +378,9 @@ sk_buff *j1939_session_skb_get_by_offset(struct j1939_session *session,
skb_queue_walk(&session->skb_queue, do_skb) {
do_skcb = j1939_skb_to_cb(do_skb);
- if (offset_start >= do_skcb->offset &&
- offset_start < (do_skcb->offset + do_skb->len)) {
+ if ((offset_start >= do_skcb->offset &&
+ offset_start < (do_skcb->offset + do_skb->len)) ||
+ (offset_start == 0 && do_skcb->offset == 0 && do_skb->len == 0)) {
skb = do_skb;
}
}