All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: "Sottas Guillaume (LMB)" <Guillaume.Sottas@liebherr.com>,
	Oliver Hartkopp <socketcan@hartkopp.net>
Subject: Re: [PATCH] can: isotp: return -ECOMM on FC timeout on TX path
Date: Wed, 28 Apr 2021 11:12:24 +0200	[thread overview]
Message-ID: <20210428091224.lsqf4tttd7uijdms@pengutronix.de> (raw)
In-Reply-To: <20210428090914.252967-1-mkl@pengutronix.de>

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

On 28.04.2021 11:09:14, Marc Kleine-Budde wrote:
> 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)

>               sk->sk_err = ECOMM;
>  		if (!sock_flag(sk, SOCK_DEAD))
>  			sk->sk_error_report(sk);

I think the idea is that sk_error_report takes care of propagation of
the error to the user space. I don't know why it's not working as
expected.

>  
> +		/* 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;


Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2021-04-28  9:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  9:09 [PATCH] can: isotp: return -ECOMM on FC timeout on TX path Marc Kleine-Budde
2021-04-28  9:12 ` Marc Kleine-Budde [this message]
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
2021-04-28 11:43 Sottas Guillaume (LMB)
2021-04-28 11:48 ` Oliver Hartkopp
2021-05-06 12:45 Sottas Guillaume (LMB)
2021-05-06 13:38 ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210428091224.lsqf4tttd7uijdms@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=Guillaume.Sottas@liebherr.com \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.