This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b5d58f4251 drivers/rptun/rptun_bmp: clear the resource table version 
on reboot
9b5d58f4251 is described below

commit 9b5d58f42511dd7f83590e57aed73db402ee0f24
Author: Yongrong Wang <[email protected]>
AuthorDate: Thu Dec 4 20:20:50 2025 +0800

    drivers/rptun/rptun_bmp: clear the resource table version on reboot
    
    rptun_bmp_get_resource() waits for a non-zero version in the shared
    resource table before using it. The table lives in memory that survives
    a soft reset, so after one core reboots the version written in the
    previous boot is still there: the core that waits sees it at once and
    parses a table the owner has not set up again yet.
    
    Register a reboot notifier that writes 0 to the version, so the waiting
    side holds off until the table is initialized again. The error paths in
    rptun_bmp_init() now unregister it.
    
    Signed-off-by: Yongrong Wang <[email protected]>
---
 drivers/rptun/rptun_bmp.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/rptun/rptun_bmp.c b/drivers/rptun/rptun_bmp.c
index e319b78dcd6..1bb1f2522af 100644
--- a/drivers/rptun/rptun_bmp.c
+++ b/drivers/rptun/rptun_bmp.c
@@ -25,6 +25,8 @@
  ****************************************************************************/
 
 #include <nuttx/kmalloc.h>
+#include <nuttx/nuttx.h>
+#include <nuttx/reboot_notifier.h>
 #include <nuttx/rptun/rptun.h>
 #include <nuttx/rptun/rptun_bmp.h>
 #include <nuttx/sched.h>
@@ -48,6 +50,7 @@ struct rptun_bmp_dev_s
   int                     irq_event;
   int                     irq_trigger;
   cpu_set_t               cpuset;
+  struct notifier_block   rebootnb;
 };
 
 /****************************************************************************
@@ -66,6 +69,8 @@ static int rptun_bmp_notify(FAR struct rptun_dev_s *dev,
 static int rptun_bmp_register_callback(FAR struct rptun_dev_s *dev,
                                        rptun_callback_t callback,
                                        FAR void *arg);
+static int rptun_bmp_notifier(FAR struct notifier_block *nb,
+                              unsigned long action, FAR void *data);
 
 /****************************************************************************
  * Private Data
@@ -87,6 +92,16 @@ static const struct rptun_ops_s g_rptun_bmp_ops =
  * Private Functions
  ****************************************************************************/
 
+static int rptun_bmp_notifier(FAR struct notifier_block *nb,
+                              unsigned long action, FAR void *data)
+{
+  FAR struct rptun_bmp_dev_s *dev;
+
+  dev = container_of(nb, struct rptun_bmp_dev_s, rebootnb);
+  dev->rsc->rsc_tbl_hdr.ver = 0;
+  return 0;
+}
+
 static FAR const char *rptun_bmp_get_cpuname(FAR struct rptun_dev_s *dev)
 {
   FAR struct rptun_bmp_dev_s *priv = (FAR struct rptun_bmp_dev_s *)dev;
@@ -212,21 +227,28 @@ int rptun_bmp_init(FAR const char *cpuname, bool master,
 
   strlcpy(dev->cpuname, cpuname, sizeof(dev->cpuname));
 
+  dev->rebootnb.notifier_call = rptun_bmp_notifier;
+  register_reboot_notifier(&dev->rebootnb);
+
   ret = irq_attach(dev->irq_event,
                    rptun_bmp_interrupt, dev);
   if (ret < 0)
     {
-      kmm_free(dev);
-      return ret;
+      goto err_irq;
     }
 
   ret = rptun_initialize(&dev->rptun);
   if (ret < 0)
     {
-      irq_detach(dev->irq_event);
-      kmm_free(dev);
-      return ret;
+      goto err_init;
     }
 
   return ret;
+
+err_init:
+  irq_detach(dev->irq_event);
+err_irq:
+  unregister_reboot_notifier(&dev->rebootnb);
+  kmm_free(dev);
+  return ret;
 }

Reply via email to