Skip to content

Commit c72c66f

Browse files
tmedicciAlan Carvalho de Assis
authored andcommitted
espressif: Fix deadlock in RT timer caused by critical section
This commit fixes a deadlock in `esp32s3-devkit:sta_softap` defconfig: `spin_lock_irqsave` was being used to enter a critical section that calls `nxsem_post`. In this case, it's recommended to use `[enter|leave]_critical_section` to avoid deadlocks when a context switch may happen, for instance.
1 parent e8b1876 commit c72c66f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

arch/risc-v/src/common/espressif/esp_hr_timer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int IRAM_ATTR esp_hr_timer_isr(int irq, void *context, void *arg)
216216

217217
systimer_ll_clear_alarm_int(priv->hal.dev, SYSTIMER_ALARM_ESPTIMER);
218218

219-
flags = spin_lock_irqsave(&priv->lock);
219+
flags = enter_critical_section();
220220

221221
/* Check if there is a timer running */
222222

@@ -286,7 +286,7 @@ static int IRAM_ATTR esp_hr_timer_isr(int irq, void *context, void *arg)
286286
}
287287
}
288288

289-
spin_unlock_irqrestore(&priv->lock, flags);
289+
leave_critical_section(flags);
290290

291291
return OK;
292292
}
@@ -576,7 +576,7 @@ void esp_hr_timer_delete(struct esp_hr_timer_s *timer)
576576

577577
struct esp_hr_timer_context_s *priv = &g_hr_timer_context;
578578

579-
flags = spin_lock_irqsave(&priv->lock);
579+
flags = enter_critical_section();
580580

581581
if (timer->state == HR_TIMER_READY)
582582
{
@@ -603,7 +603,7 @@ void esp_hr_timer_delete(struct esp_hr_timer_s *timer)
603603
}
604604

605605
exit:
606-
spin_unlock_irqrestore(&priv->lock, flags);
606+
leave_critical_section(flags);
607607
}
608608

609609
/****************************************************************************

arch/xtensa/src/esp32/esp32_rt_timer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
263263
irqstate_t flags;
264264
struct esp32_rt_priv_s *priv = &g_rt_priv;
265265

266-
flags = spin_lock_irqsave(&priv->lock);
266+
flags = enter_critical_section();
267267

268268
if (timer->state == RT_TIMER_READY)
269269
{
@@ -282,7 +282,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
282282
timer->state = RT_TIMER_DELETE;
283283

284284
exit:
285-
spin_unlock_irqrestore(&priv->lock, flags);
285+
leave_critical_section(flags);
286286
}
287287

288288
/****************************************************************************
@@ -709,7 +709,7 @@ int esp32_rt_timer_init(void)
709709
priv->timer = tim;
710710
priv->pid = (pid_t)pid;
711711

712-
flags = spin_lock_irqsave(&priv->lock);
712+
flags = enter_critical_section();
713713

714714
/* ESP32 hardware timer configuration:
715715
* - 1 counter = 1us
@@ -727,7 +727,7 @@ int esp32_rt_timer_init(void)
727727

728728
ESP32_TIM_START(tim);
729729

730-
spin_unlock_irqrestore(&priv->lock, flags);
730+
leave_critical_section(flags);
731731

732732
return 0;
733733
}

arch/xtensa/src/esp32s3/esp32s3_rt_timer.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
611611

612612
modifyreg32(SYSTIMER_INT_CLR_REG, 0, SYSTIMER_TARGET2_INT_CLR);
613613

614-
flags = spin_lock_irqsave(&priv->lock);
614+
flags = enter_critical_section();
615615

616616
/* Check if there is a timer running */
617617

@@ -672,7 +672,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
672672
}
673673
}
674674

675-
spin_unlock_irqrestore(&priv->lock, flags);
675+
leave_critical_section(flags);
676676

677677
return OK;
678678
}
@@ -805,7 +805,7 @@ void esp32s3_rt_timer_delete(struct rt_timer_s *timer)
805805
irqstate_t flags;
806806
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
807807

808-
flags = spin_lock_irqsave(&priv->lock);
808+
flags = enter_critical_section();
809809

810810
if (timer->state == RT_TIMER_READY)
811811
{
@@ -832,7 +832,7 @@ void esp32s3_rt_timer_delete(struct rt_timer_s *timer)
832832
}
833833

834834
exit:
835-
spin_unlock_irqrestore(&priv->lock, flags);
835+
leave_critical_section(flags);
836836
}
837837

838838
/****************************************************************************
@@ -965,7 +965,7 @@ int esp32s3_rt_timer_init(void)
965965

966966
priv->pid = (pid_t)pid;
967967

968-
flags = spin_lock_irqsave(&priv->lock);
968+
flags = enter_critical_section();
969969

970970
/* ESP32-S3 hardware timer configuration:
971971
* 1 count = 1/16 us
@@ -1007,7 +1007,7 @@ int esp32s3_rt_timer_init(void)
10071007

10081008
modifyreg32(SYSTIMER_CONF_REG, 0, SYSTIMER_TIMER_UNIT1_WORK_EN);
10091009

1010-
spin_unlock_irqrestore(&priv->lock, flags);
1010+
leave_critical_section(flags);
10111011

10121012
return OK;
10131013
}

0 commit comments

Comments
 (0)