All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] can: isotp: return -ECOMM on FC timeout on TX path
@ 2021-04-28 11:43 Sottas Guillaume (LMB)
  2021-04-28 11:48 ` Oliver Hartkopp
  0 siblings, 1 reply; 11+ messages in thread
From: Sottas Guillaume (LMB) @ 2021-04-28 11:43 UTC (permalink / raw)
  To: mkl; +Cc: Sottas Guillaume (LMB), linux-can, socketcan

Hello,

First of all thank you for your fast reply.

From my point of view, I think it would make sense to return an error to the user when CAN_ISOTP_WAIT_TX_DONE option is set. Otherwise, I don't understand the use case of this option?
If the CAN_ISOTP_WAIT_TX_DONE option is not set, then not receiving an error on timeout could be the expected behavior, as the user does not explicitly ask for completion.

Concerning the way of reporting the error, setting the errno would be a nice solution, as it would not require that much modifications. However, as Mark mentioned, the errno is not set.
I'm not an expert in how this sk_error_report works internally, but I will try to get more infos about it.

In both cases, the documentation in the isotp.c (https://elixir.bootlin.com/linux/latest/source/net/can/isotp.c#L7) file is not correct, as it is not the actual behavior (most likely the expected).
Additionally, I guess the -ETIMEOUT, -EILSEQ, -EBADMSG,... described in the same documentation are most likely not working that way either, but would be fixed if the errno is reported correctly.

Best Regards,

Guillaume



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] can: isotp: return -ECOMM on FC timeout on TX path
@ 2021-05-06 12:45 Sottas Guillaume (LMB)
  2021-05-06 13:38 ` Marc Kleine-Budde
  0 siblings, 1 reply; 11+ messages in thread
From: Sottas Guillaume (LMB) @ 2021-05-06 12:45 UTC (permalink / raw)
  To: mkl; +Cc: Sottas Guillaume (LMB), linux-can, socketcan

Hello Marc,

Thank you for your investigations, seems to be the way to go? What is the next step, could I help in any way or are you going to merge your patch directly?
I'm not really sure how we should go further in order to inegrate your fix in the code...

Thank you in advance for your feedback,

Best Regards,

Guillaume


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] can: isotp: return -ECOMM on FC timeout on TX path
@ 2021-04-28  9:09 Marc Kleine-Budde
  2021-04-28  9:12 ` Marc Kleine-Budde
  0 siblings, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-04-28  9:09 UTC (permalink / raw)
  To: linux-can; +Cc: Sottas Guillaume (LMB), Oliver Hartkopp, Marc Kleine-Budde

From: "Sottas Guillaume (LMB)" <Guillaume.Sottas@liebherr.com>

Link: https://github.com/hartkopp/can-isotp/pull/43
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Not-Signed-off-by: Sottas Guillaume (LMB) <Guillaume.Sottas@liebherr.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---

Hello,

for better reviewing I'm posting Sottas's patch here. While porting to
current net/master I've fixed up the indention.

regards,
Marc

 net/can/isotp.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/net/can/isotp.c b/net/can/isotp.c
index 9f94ad3caee9..d02e8f1f240f 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -110,6 +110,11 @@ MODULE_ALIAS("can-proto-6");
 #define ISOTP_FC_WT 1		/* wait */
 #define ISOTP_FC_OVFLW 2	/* overflow */
 
+enum {
+	ISOTP_ERR_NO_ERROR = 0,
+	ISOTP_ERR_FC_TIMEOUT,
+};
+
 enum {
 	ISOTP_IDLE = 0,
 	ISOTP_WAIT_FIRST_FC,
@@ -122,6 +127,7 @@ struct tpcon {
 	int idx;
 	int len;
 	u8 state;
+	u8 error;
 	u8 bs;
 	u8 sn;
 	u8 ll_dl;
@@ -756,6 +762,10 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
 		if (!sock_flag(sk, SOCK_DEAD))
 			sk->sk_error_report(sk);
 
+		/* set error flag in order to consume it later in the
+		 * isotp_sendmsg function */
+		so->tx.error = ISOTP_ERR_FC_TIMEOUT;
+
 		/* reset tx state */
 		so->tx.state = ISOTP_IDLE;
 		wake_up_interruptible(&so->wait);
@@ -954,6 +964,13 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	if (wait_tx_done) {
 		/* wait for complete transmission of current pdu */
 		wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
+
+		/* check if an error has been raised in the timer
+		 * function handler */
+		if (so->tx.error == ISOTP_ERR_FC_TIMEOUT) {
+			so->tx.error = ISOTP_ERR_NO_ERROR;
+			return -ECOMM;
+		}
 	}
 
 	return size;
@@ -1371,6 +1388,9 @@ static int isotp_init(struct sock *sk)
 	so->tx.state = ISOTP_IDLE;
 
 	hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
+
+	so->tx.error = ISOTP_ERR_NO_ERROR;
+	so->rx.error = ISOTP_ERR_NO_ERROR;
 	so->rxtimer.function = isotp_rx_timer_handler;
 	hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
 	so->txtimer.function = isotp_tx_timer_handler;
-- 
2.30.2



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

end of thread, other threads:[~2021-05-06 13:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 11:43 [PATCH] can: isotp: return -ECOMM on FC timeout on TX path Sottas Guillaume (LMB)
2021-04-28 11:48 ` Oliver Hartkopp
  -- strict thread matches above, loose matches on Subject: below --
2021-05-06 12:45 Sottas Guillaume (LMB)
2021-05-06 13:38 ` Marc Kleine-Budde
2021-04-28  9:09 Marc Kleine-Budde
2021-04-28  9:12 ` Marc Kleine-Budde
2021-04-28  9:26   ` Oliver Hartkopp
2021-04-28 10:24     ` Oliver Hartkopp
2021-04-28 10:47       ` Marc Kleine-Budde
2021-04-28 11:45         ` Oliver Hartkopp
2021-04-28 12:07           ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.