mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] j1939: fix unable to send messages with data length zero
@ 2025-01-07 13:32 Alexander Hölzl
  2025-01-07 13:48 ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Hölzl @ 2025-01-07 13:32 UTC (permalink / raw)
  To: robin, socketcan, mkl, davem, edumazet, kuba, pabeni, corbet
  Cc: kernel, linux-can, linux-kernel, Alexander Hölzl

The J1939 standard requires the transmission of messages of length 0.
For example the proprietary messages are specified with a data length
of 0 to 1785. The transmission of such messages was not possible.
Sending such a message resulted in no error being returned but no
corresponding can frame being generated.

Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>
---
 net/can/j1939/socket.c    | 4 ++--
 net/can/j1939/transport.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 305dd72c844c..17226b2341d0 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -1132,7 +1132,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,
@@ -1177,7 +1177,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 319f47df3330..99832e60c08d 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -382,8 +382,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;
 		}
 	}
--
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] j1939: fix unable to send messages with data length zero
  2025-01-07 13:32 [PATCH] j1939: fix unable to send messages with data length zero Alexander Hölzl
@ 2025-01-07 13:48 ` Marc Kleine-Budde
  2025-01-07 17:17   ` Alexander Hölzl
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2025-01-07 13:48 UTC (permalink / raw)
  To: Alexander Hölzl
  Cc: robin, socketcan, davem, edumazet, kuba, pabeni, corbet, kernel,
	linux-can, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2339 bytes --]

On 07.01.2025 14:32:17, Alexander Hölzl wrote:
> The J1939 standard requires the transmission of messages of length 0.
> For example the proprietary messages are specified with a data length
> of 0 to 1785. The transmission of such messages was not possible.
> Sending such a message resulted in no error being returned but no
> corresponding can frame being generated.

What does your patch do? Please describe it here.

Marc

> Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>
> ---
>  net/can/j1939/socket.c    | 4 ++--
>  net/can/j1939/transport.c | 5 +++--
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 305dd72c844c..17226b2341d0 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -1132,7 +1132,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,
> @@ -1177,7 +1177,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 319f47df3330..99832e60c08d 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
> @@ -382,8 +382,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;
>  		}
>  	}
> --
> 2.43.0
> 
> 
> 

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] j1939: fix unable to send messages with data length zero
  2025-01-07 13:48 ` Marc Kleine-Budde
@ 2025-01-07 17:17   ` Alexander Hölzl
  2025-01-16  8:37     ` Oleksij Rempel
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Hölzl @ 2025-01-07 17:17 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: robin, socketcan, davem, edumazet, kuba, pabeni, corbet, kernel,
	linux-can, linux-kernel

On 1/7/25 14:48, Marc Kleine-Budde wrote:
> On 07.01.2025 14:32:17, Alexander Hölzl wrote:
>> The J1939 standard requires the transmission of messages of length 0.
>> For example the proprietary messages are specified with a data length
>> of 0 to 1785. The transmission of such messages was not possible.
>> Sending such a message resulted in no error being returned but no
>> corresponding can frame being generated.
>
> What does your patch do? Please describe it here.
>
> Marc
The patch enables the transmission of zero length J1939 messages.
In order to facilitate this two changes were necessary.

First when the transmission of a new message is requested from userspace
the message is segmented in j1939_sk_send_loop. The segmentation did
account for zero length messages and terminated immediately without
queuing the corresponding skb.

Second when selecting the next skb in j1939_session_skb_get_by_offset to
transmit for a session, it was not checked that there now might be a
zero length skb in the queue.

Also as this is my first real patch I'm submitting please don't hesitate
to tell me if I'm doing something wrong.
>
>> Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>
>> ---
>>   net/can/j1939/socket.c    | 4 ++--
>>   net/can/j1939/transport.c | 5 +++--
>>   2 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
>> index 305dd72c844c..17226b2341d0 100644
>> --- a/net/can/j1939/socket.c
>> +++ b/net/can/j1939/socket.c
>> @@ -1132,7 +1132,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,
>> @@ -1177,7 +1177,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 319f47df3330..99832e60c08d 100644
>> --- a/net/can/j1939/transport.c
>> +++ b/net/can/j1939/transport.c
>> @@ -382,8 +382,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;
>>   		}
>>   	}
>> --
>> 2.43.0
>>
>>
>>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] j1939: fix unable to send messages with data length zero
  2025-01-07 17:17   ` Alexander Hölzl
@ 2025-01-16  8:37     ` Oleksij Rempel
  0 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2025-01-16  8:37 UTC (permalink / raw)
  To: Alexander Hölzl
  Cc: Marc Kleine-Budde, robin, socketcan, davem, edumazet, kuba,
	pabeni, corbet, kernel, linux-can, linux-kernel

Hi Alexander,

On Tue, Jan 07, 2025 at 06:17:13PM +0100, Alexander Hölzl wrote:
> On 1/7/25 14:48, Marc Kleine-Budde wrote:
> > On 07.01.2025 14:32:17, Alexander Hölzl wrote:
> > > The J1939 standard requires the transmission of messages of length 0.
> > > For example the proprietary messages are specified with a data length
> > > of 0 to 1785. The transmission of such messages was not possible.
> > > Sending such a message resulted in no error being returned but no
> > > corresponding can frame being generated.
> > 
> > What does your patch do? Please describe it here.
> > 
> > Marc
> The patch enables the transmission of zero length J1939 messages.
> In order to facilitate this two changes were necessary.
> 
> First when the transmission of a new message is requested from userspace
> the message is segmented in j1939_sk_send_loop. The segmentation did
> account for zero length messages and terminated immediately without
> queuing the corresponding skb.
> 
> Second when selecting the next skb in j1939_session_skb_get_by_offset to
> transmit for a session, it was not checked that there now might be a
> zero length skb in the queue.
> 
> Also as this is my first real patch I'm submitting please don't hesitate
> to tell me if I'm doing something wrong.

Please resend this patch with updated, more detailed, commit message.

> > > Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] j1939: fix unable to send messages with data length zero
  2025-02-05 17:46 Alexander Hölzl
@ 2025-02-06  7:57 ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2025-02-06  7:57 UTC (permalink / raw)
  To: Alexander Hölzl
  Cc: robin, socketcan, davem, edumazet, kuba, pabeni, corbet, kernel,
	linux-can, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2737 bytes --]

On 05.02.2025 18:46:51, Alexander Hölzl wrote:
> The J1939 standard requires the transmission of messages of length 0.
> For example the proprietary messages are specified with a data length
> of 0 to 1785. The transmission of such messages was not possible.
> Sending such a message resulted in no error being returned but no
> corresponding can frame being generated.
> This patch enables the transmission of zero length J1939 messages.
> In order to facilitate this two changes were necessary.
>
> First when the transmission of a new message is requested from userspace
> the message is segmented in j1939_sk_send_loop. The segmentation did
> account for zero length messages and terminated immediately without
> queuing the corresponding skb.
>
> Second in j1939_session_skb_get_by_offset, when selecting the next skb to
> transmit for a session, it was not checked that there now might be a
> zero length skb in the queue.
>
> Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>

Rephrased commit message to imperative style and added Oleksij's
Acked-by:

    can: j1939: j1939_sk_send_loop(): fix unable to send messages with data length zero

    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")
    [mkl: commit message rephrased]
    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Added to linux-can.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] j1939: fix unable to send messages with data length zero
@ 2025-02-05 17:46 Alexander Hölzl
  2025-02-06  7:57 ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Hölzl @ 2025-02-05 17:46 UTC (permalink / raw)
  To: robin, socketcan, mkl, davem, edumazet, kuba, pabeni, corbet
  Cc: kernel, linux-can, linux-kernel, Alexander Hölzl

The J1939 standard requires the transmission of messages of length 0.
For example the proprietary messages are specified with a data length
of 0 to 1785. The transmission of such messages was not possible.
Sending such a message resulted in no error being returned but no
corresponding can frame being generated.
This patch enables the transmission of zero length J1939 messages.
In order to facilitate this two changes were necessary.

First when the transmission of a new message is requested from userspace
the message is segmented in j1939_sk_send_loop. The segmentation did
account for zero length messages and terminated immediately without
queuing the corresponding skb.

Second in j1939_session_skb_get_by_offset, when selecting the next skb to
transmit for a session, it was not checked that there now might be a
zero length skb in the queue.

Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>
---
 net/can/j1939/socket.c    | 4 ++--
 net/can/j1939/transport.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 305dd72c844c..17226b2341d0 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -1132,7 +1132,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,
@@ -1177,7 +1177,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 319f47df3330..99832e60c08d 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -382,8 +382,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;
 		}
 	}
--
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-02-06  7:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-07 13:32 [PATCH] j1939: fix unable to send messages with data length zero Alexander Hölzl
2025-01-07 13:48 ` Marc Kleine-Budde
2025-01-07 17:17   ` Alexander Hölzl
2025-01-16  8:37     ` Oleksij Rempel
2025-02-05 17:46 Alexander Hölzl
2025-02-06  7:57 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®