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

commit 2c18e609a669f497abcb3a1decb042391e760c4f
Author: wangshaoxin <[email protected]>
AuthorDate: Tue Mar 18 17:06:19 2025 +0800

    rpmsgblk: add rpmsgblk_unregister function
    
    Add rpmsgblk_unregister() to allow the client CPU to tear down an
    rpmsg block device proxy during board uninitialize.  The function
    looks up the block driver inode, unregisters it, tears down the
    rpmsg callback, and frees the driver resources.
    
    Signed-off-by: wangshaoxin <[email protected]>
---
 drivers/misc/rpmsgblk.c          | 58 ++++++++++++++++++++++++++++++++++++++++
 include/nuttx/drivers/rpmsgblk.h | 21 ++++++++++++++-
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/rpmsgblk.c b/drivers/misc/rpmsgblk.c
index afdf611fdd9..224a3165b07 100644
--- a/drivers/misc/rpmsgblk.c
+++ b/drivers/misc/rpmsgblk.c
@@ -24,6 +24,7 @@
  * Included Files
  ****************************************************************************/
 
+#include <sys/mount.h>
 #include <sys/types.h>
 
 #include <stdio.h>
@@ -1330,3 +1331,60 @@ fail:
   kmm_free(dev);
   return ret;
 }
+
+/****************************************************************************
+ * Name: rpmsgblk_unregister
+ *
+ * Description:
+ *   Rpmsg-blk client uninitialize function, the client cpu should call
+ *   this function in the board uninitialize process.
+ *
+ * Parameters:
+ *   localpath - the device you want to unregister in the local cpu
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int rpmsgblk_unregister(FAR const char *localpath)
+{
+  FAR struct rpmsgblk_s *dev;
+  FAR struct inode *inode;
+  int ret;
+
+  ret = find_blockdriver(localpath, MS_RDONLY, &inode);
+  if (ret < 0)
+    {
+      ferr("ERROR: Failed to find blkdriver, ret=%d\n", ret);
+      return ret;
+    }
+
+  dev = inode->i_private;
+  ret = close_blockdriver(inode);
+  if (ret < 0)
+    {
+      ferr("ERROR: Failed to close blkdriver, ret=%d\n", ret);
+      return ret;
+    }
+
+  ret = unregister_blockdriver(localpath);
+  if (ret < 0)
+    {
+      ferr("ERROR: unregister driver failed, ret=%d\n", ret);
+      return ret;
+    }
+
+  /* Unregister the rpmsg callback */
+
+  rpmsg_unregister_callback(dev,
+                            rpmsgblk_device_created,
+                            rpmsgblk_device_destroy,
+                            NULL,
+                            NULL);
+
+  nxsem_destroy(&dev->wait);
+  nxmutex_destroy(&dev->lock);
+  kmm_free(dev);
+  return ret;
+}
diff --git a/include/nuttx/drivers/rpmsgblk.h b/include/nuttx/drivers/rpmsgblk.h
index 310c6c24a49..43792227c73 100644
--- a/include/nuttx/drivers/rpmsgblk.h
+++ b/include/nuttx/drivers/rpmsgblk.h
@@ -81,8 +81,27 @@ int rpmsgblk_register(FAR const char *remotecpu, FAR const 
char *remotepath,
                       FAR const char *localpath);
 #endif
 
+/****************************************************************************
+ * Name: rpmsgblk_unregister
+ *
+ * Description:
+ *   Rpmsg-device client uninitialize function, the client cpu should call
+ *   this function in the board uninitialize process.
+ *
+ * Parameters:
+ *   localpath  - the device path
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BLK_RPMSG
+int rpmsgblk_unregister(FAR const char *localpath);
+#endif
+
 #if defined(__cplusplus)
 }
 #endif
 
-#endif /* __INCLUDE_NUTTX_DRIVERS_RPMSGDEV_H */
+#endif /* __INCLUDE_NUTTX_DRIVERS_RPMSGBLK_H */

Reply via email to