All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Josenhans <michael.josenhans@web.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Subject: Re: [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
Date: Sat, 28 Jan 2017 17:42:54 +0100	[thread overview]
Message-ID: <7ded2bd2-45af-e4e1-63d9-e9959d8db2e3@web.de> (raw)
In-Reply-To: <20170118203051.16192-1-socketcan@hartkopp.net>



When removing a bcm tx operation either a hrtimer or a tasklet might run.
As the hrtimer triggers its associated tasklet and vice versa we need to
take care to mutually terminate both handlers.

Reported-by: Michael Josenhans <michael.josenhans@web.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Michael Josenhans <michael.josenhans@web.de>
> ---
>  net/can/bcm.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 21ac75390e3d..a7dc80c8e724 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct list_head *ops,
>
>  static void bcm_remove_op(struct bcm_op *op)
>  {
> -	hrtimer_cancel(&op->timer);
> -	hrtimer_cancel(&op->thrtimer);
> -
> -	if (op->tsklet.func)
> -		tasklet_kill(&op->tsklet);
> +	if (op->tsklet.func) {
> +		while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
> +		       test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
> +		       hrtimer_active(&op->timer)) {
> +			hrtimer_cancel(&op->timer);
> +			tasklet_kill(&op->tsklet);
> +		}
> +	}
>
> -	if (op->thrtsklet.func)
> -		tasklet_kill(&op->thrtsklet);
> +	if (op->thrtsklet.func) {
> +		while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
> +		       test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
> +		       hrtimer_active(&op->thrtimer)) {
> +			hrtimer_cancel(&op->thrtimer);
> +			tasklet_kill(&op->thrtsklet);
> +		}
> +	}
>
>  	if ((op->frames) && (op->frames != &op->sframe))
>  		kfree(op->frames);
> --

  parent reply	other threads:[~2017-01-28 16:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 20:30 [PATCH] can: fix hrtimer/tasklet termination in bcm op removal Oliver Hartkopp
2017-01-18 20:40 ` Oliver Hartkopp
2017-01-28 16:42 ` Michael Josenhans [this message]
2017-01-28 17:25   ` Oliver Hartkopp
2017-01-30 10:06     ` 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=7ded2bd2-45af-e4e1-63d9-e9959d8db2e3@web.de \
    --to=michael.josenhans@web.de \
    --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.