Skip to content

Commit a06393e

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: bcm: fix hrtimer/tasklet termination in bcm op removal
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> Cc: linux-stable <stable@vger.kernel.org> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent d1156b4 commit a06393e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

net/can/bcm.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct list_head *ops,
734734

735735
static void bcm_remove_op(struct bcm_op *op)
736736
{
737-
hrtimer_cancel(&op->timer);
738-
hrtimer_cancel(&op->thrtimer);
739-
740-
if (op->tsklet.func)
741-
tasklet_kill(&op->tsklet);
737+
if (op->tsklet.func) {
738+
while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
739+
test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
740+
hrtimer_active(&op->timer)) {
741+
hrtimer_cancel(&op->timer);
742+
tasklet_kill(&op->tsklet);
743+
}
744+
}
742745

743-
if (op->thrtsklet.func)
744-
tasklet_kill(&op->thrtsklet);
746+
if (op->thrtsklet.func) {
747+
while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
748+
test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
749+
hrtimer_active(&op->thrtimer)) {
750+
hrtimer_cancel(&op->thrtimer);
751+
tasklet_kill(&op->thrtsklet);
752+
}
753+
}
745754

746755
if ((op->frames) && (op->frames != &op->sframe))
747756
kfree(op->frames);

0 commit comments

Comments
 (0)