Skip to content

Commit 840835c

Browse files
oleremmarckleinebudde
authored andcommitted
can: j1939: transport: add j1939_session_skb_find_by_offset() function
Sometimes it makes no sense to search the skb by pkt.dpo, since we need next the skb within the transaction block. This may happen if we have an ETP session with CTS set to less than 255 packets. After this patch, we will be able to work with ETP sessions where the block size (ETP.CM_CTS byte 2) is less than 255 packets. Reported-by: Henrique Figueira <[email protected]> Reported-by: linux-can/can-utils#228 Fixes: 9d71dd0 ("can: add support of SAE J1939 protocol") Signed-off-by: Oleksij Rempel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent af804b7 commit 840835c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

net/can/j1939/transport.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,16 @@ void j1939_session_skb_queue(struct j1939_session *session,
352352
skb_queue_tail(&session->skb_queue, skb);
353353
}
354354

355-
static struct sk_buff *j1939_session_skb_find(struct j1939_session *session)
355+
static struct
356+
sk_buff *j1939_session_skb_find_by_offset(struct j1939_session *session,
357+
unsigned int offset_start)
356358
{
357359
struct j1939_priv *priv = session->priv;
360+
struct j1939_sk_buff_cb *do_skcb;
358361
struct sk_buff *skb = NULL;
359362
struct sk_buff *do_skb;
360-
struct j1939_sk_buff_cb *do_skcb;
361-
unsigned int offset_start;
362363
unsigned long flags;
363364

364-
offset_start = session->pkt.dpo * 7;
365-
366365
spin_lock_irqsave(&session->skb_queue.lock, flags);
367366
skb_queue_walk(&session->skb_queue, do_skb) {
368367
do_skcb = j1939_skb_to_cb(do_skb);
@@ -382,6 +381,14 @@ static struct sk_buff *j1939_session_skb_find(struct j1939_session *session)
382381
return skb;
383382
}
384383

384+
static struct sk_buff *j1939_session_skb_find(struct j1939_session *session)
385+
{
386+
unsigned int offset_start;
387+
388+
offset_start = session->pkt.dpo * 7;
389+
return j1939_session_skb_find_by_offset(session, offset_start);
390+
}
391+
385392
/* see if we are receiver
386393
* returns 0 for broadcasts, although we will receive them
387394
*/
@@ -766,7 +773,7 @@ static int j1939_session_tx_dat(struct j1939_session *session)
766773
int ret = 0;
767774
u8 dat[8];
768775

769-
se_skb = j1939_session_skb_find(session);
776+
se_skb = j1939_session_skb_find_by_offset(session, session->pkt.tx * 7);
770777
if (!se_skb)
771778
return -ENOBUFS;
772779

@@ -1765,7 +1772,8 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
17651772
__func__, session);
17661773
goto out_session_cancel;
17671774
}
1768-
se_skb = j1939_session_skb_find(session);
1775+
1776+
se_skb = j1939_session_skb_find_by_offset(session, packet * 7);
17691777
if (!se_skb) {
17701778
netdev_warn(priv->ndev, "%s: 0x%p: no skb found\n", __func__,
17711779
session);

0 commit comments

Comments
 (0)