From 981bda5cf09bf166f1d23e6d708c04478f999fdc Mon Sep 17 00:00:00 2001 From: ligd Date: Thu, 25 Jul 2024 22:52:52 +0800 Subject: [PATCH] ramlog: workaround the unsafe critical section thread1: thread2: ramlog_addbuf() enter_critical_section() ramlog_pollnotify() foreach rl_list --> switch out ramlog_file_close enter_critical_section() list_delete() leave_critical_section() <--- switch back rl_list error leave_critical_section() Signed-off-by: ligd --- drivers/syslog/ramlog.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index 79d2947452c..ba9b3ff8499 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -337,6 +337,13 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv, if (len > 0) { + /* Lock the scheduler do NOT switch out */ + + if (!up_interrupt_context()) + { + sched_lock(); + } + #ifndef CONFIG_RAMLOG_NONBLOCKING /* Are there threads waiting for read data? */ @@ -345,6 +352,13 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv, /* Notify all poll/select waiters that they can read from the FIFO */ ramlog_pollnotify(priv); + + /* Unlock the scheduler */ + + if (!up_interrupt_context()) + { + sched_unlock(); + } } /* We always have to return the number of bytes requested and NOT the