Skip to content

Commit cda4173

Browse files
xile273jfvogel
authored andcommitted
can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero
commit 44de577 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: 9d71dd0 ("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> (cherry picked from commit 759e4e94a3c97298f14d5b9812eb71d2ad56df71) Signed-off-by: Jack Vogel <jack.vogel@oracle.com>
1 parent bcdfae5 commit cda4173

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

net/can/j1939/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv, struct sock *sk,
11321132

11331133
todo_size = size;
11341134

1135-
while (todo_size) {
1135+
do {
11361136
struct j1939_sk_buff_cb *skcb;
11371137

11381138
segment_size = min_t(size_t, J1939_MAX_TP_PACKET_SIZE,
@@ -1177,7 +1177,7 @@ static int j1939_sk_send_loop(struct j1939_priv *priv, struct sock *sk,
11771177

11781178
todo_size -= segment_size;
11791179
session->total_queued_size += segment_size;
1180-
}
1180+
} while (todo_size);
11811181

11821182
switch (ret) {
11831183
case 0: /* OK */

net/can/j1939/transport.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ sk_buff *j1939_session_skb_get_by_offset(struct j1939_session *session,
382382
skb_queue_walk(&session->skb_queue, do_skb) {
383383
do_skcb = j1939_skb_to_cb(do_skb);
384384

385-
if (offset_start >= do_skcb->offset &&
386-
offset_start < (do_skcb->offset + do_skb->len)) {
385+
if ((offset_start >= do_skcb->offset &&
386+
offset_start < (do_skcb->offset + do_skb->len)) ||
387+
(offset_start == 0 && do_skcb->offset == 0 && do_skb->len == 0)) {
387388
skb = do_skb;
388389
}
389390
}

0 commit comments

Comments
 (0)