Skip to content

Commit aa57725

Browse files
Hans Verkuilgregkh
authored andcommitted
media: cec-pin: fix interrupt en/disable handling
commit 713bdfa upstream. The en/disable_irq() functions keep track of the 'depth': i.e. if interrupts are disabled twice, then it needs to enable_irq() calls to enable them again. The cec-pin framework didn't take this into accound and could disable irqs multiple times, and it expected that a single enable_irq() would enable them again. Move all calls to en/disable_irq() to the kthread where it is easy to keep track of the current irq state and ensure that multiple en/disable_irq calls never happen. If interrupts where disabled twice, then they would never turn on again, leaving the CEC adapter in a dead state. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Fixes: 865463f (media: cec-pin: add error injection support) Cc: <stable@vger.kernel.org> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2e566ca commit aa57725

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

‎drivers/media/cec/core/cec-pin.c‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ static int cec_pin_thread_func(void *_adap)
10331033
{
10341034
struct cec_adapter *adap = _adap;
10351035
struct cec_pin *pin = adap->pin;
1036+
bool irq_enabled = false;
10361037

10371038
for (;;) {
10381039
wait_event_interruptible(pin->kthread_waitq,
@@ -1060,6 +1061,7 @@ static int cec_pin_thread_func(void *_adap)
10601061
ns_to_ktime(pin->work_rx_msg.rx_ts));
10611062
msg->len = 0;
10621063
}
1064+
10631065
if (pin->work_tx_status) {
10641066
unsigned int tx_status = pin->work_tx_status;
10651067

@@ -1083,27 +1085,39 @@ static int cec_pin_thread_func(void *_adap)
10831085
switch (atomic_xchg(&pin->work_irq_change,
10841086
CEC_PIN_IRQ_UNCHANGED)) {
10851087
case CEC_PIN_IRQ_DISABLE:
1086-
pin->ops->disable_irq(adap);
1088+
if (irq_enabled) {
1089+
pin->ops->disable_irq(adap);
1090+
irq_enabled = false;
1091+
}
10871092
cec_pin_high(pin);
10881093
cec_pin_to_idle(pin);
10891094
hrtimer_start(&pin->timer, ns_to_ktime(0),
10901095
HRTIMER_MODE_REL);
10911096
break;
10921097
case CEC_PIN_IRQ_ENABLE:
1098+
if (irq_enabled)
1099+
break;
10931100
pin->enable_irq_failed = !pin->ops->enable_irq(adap);
10941101
if (pin->enable_irq_failed) {
10951102
cec_pin_to_idle(pin);
10961103
hrtimer_start(&pin->timer, ns_to_ktime(0),
10971104
HRTIMER_MODE_REL);
1105+
} else {
1106+
irq_enabled = true;
10981107
}
10991108
break;
11001109
default:
11011110
break;
11021111
}
1103-
11041112
if (kthread_should_stop())
11051113
break;
11061114
}
1115+
if (pin->ops->disable_irq && irq_enabled)
1116+
pin->ops->disable_irq(adap);
1117+
hrtimer_cancel(&pin->timer);
1118+
cec_pin_read(pin);
1119+
cec_pin_to_idle(pin);
1120+
pin->state = CEC_ST_OFF;
11071121
return 0;
11081122
}
11091123

@@ -1130,13 +1144,7 @@ static int cec_pin_adap_enable(struct cec_adapter *adap, bool enable)
11301144
hrtimer_start(&pin->timer, ns_to_ktime(0),
11311145
HRTIMER_MODE_REL);
11321146
} else {
1133-
if (pin->ops->disable_irq)
1134-
pin->ops->disable_irq(adap);
1135-
hrtimer_cancel(&pin->timer);
11361147
kthread_stop(pin->kthread);
1137-
cec_pin_read(pin);
1138-
cec_pin_to_idle(pin);
1139-
pin->state = CEC_ST_OFF;
11401148
}
11411149
return 0;
11421150
}
@@ -1157,11 +1165,8 @@ void cec_pin_start_timer(struct cec_pin *pin)
11571165
if (pin->state != CEC_ST_RX_IRQ)
11581166
return;
11591167

1160-
atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_UNCHANGED);
1161-
pin->ops->disable_irq(pin->adap);
1162-
cec_pin_high(pin);
1163-
cec_pin_to_idle(pin);
1164-
hrtimer_start(&pin->timer, ns_to_ktime(0), HRTIMER_MODE_REL);
1168+
atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_DISABLE);
1169+
wake_up_interruptible(&pin->kthread_waitq);
11651170
}
11661171

11671172
static int cec_pin_adap_transmit(struct cec_adapter *adap, u8 attempts,

0 commit comments

Comments
 (0)