acassis commented on code in PR #17010:
URL: https://github.com/apache/nuttx/pull/17010#discussion_r2406711078
##########
boards/boardctl.c:
##########
@@ -133,16 +133,14 @@ static inline int
case BOARDIOC_USBDEV_CONNECT: /* Connect the CDC/ACM device */
#ifndef CONFIG_CDCACM_COMPOSITE
{
- DEBUGASSERT(ctrl->handle != NULL);
ret = cdcacm_initialize(ctrl->instance, ctrl->handle);
}
#endif
break;
case BOARDIOC_USBDEV_DISCONNECT: /* Disconnect the CDC/ACM device
*/
{
- DEBUGASSERT(ctrl->handle != NULL && *ctrl->handle != NULL);
- cdcacm_uninitialize(*ctrl->handle);
+ ret = cdcacm_uninitialize_instance(ctrl->instance, NULL);
Review Comment:
@jlaitine why did you remove the DEBUGASSERT() here and in the previous
block? What is already done in the higher layer? I didn't see you including it,
so I assume it was already there
##########
drivers/usbdev/cdcacm.c:
##########
@@ -3430,8 +3443,60 @@ void cdcacm_uninitialize(FAR struct usbdevclass_driver_s
*classdev)
{
FAR struct cdcacm_driver_s *drvr = (FAR struct cdcacm_driver_s *)classdev;
FAR struct cdcacm_dev_s *priv = drvr->dev;
- char devname[CDCACM_DEVNAME_SIZE];
+
+ cdcacm_uninitialize_instance(priv->minor, classdev);
+}
+
+/****************************************************************************
+ * Name: cdcacm_uninitialize_instance
+ *
+ * Description:
+ * Function to uninitialize specific cdcacm instance
+ *
+ * Input Parameters:
+ * minor - CDCACM node minor number
+ *
+ * Returned Value:
+ * OK when successful, -ENODEV if cdcacm is not initialized
+ *
+ ****************************************************************************/
+
+int cdcacm_uninitialize_instance(int minor,
+ FAR struct usbdevclass_driver_s *classdev)
+{
int ret;
+ FAR struct cdcacm_driver_s *drvr = (FAR struct cdcacm_driver_s *)classdev;
+ FAR struct cdcacm_dev_s *priv;
+ char devname[CDCACM_DEVNAME_SIZE];
+
+ /* Create device node path from minor number */
+
+ snprintf(devname, sizeof(devname), CDCACM_DEVNAME_FORMAT, minor);
+
+ ret = nxmutex_lock(&g_init_lock);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* If classdev is not provided, find it from the file system */
+
+ if (!classdev)
+ {
+ FAR struct cdcacm_alloc_s *cdcacm_alloc = find_driver(devname);
+ if (cdcacm_alloc)
Review Comment:
```suggestion
if (cdcacm_alloc != NULL)
##########
drivers/usbdev/cdcacm.c:
##########
@@ -3430,8 +3443,60 @@ void cdcacm_uninitialize(FAR struct usbdevclass_driver_s
*classdev)
{
FAR struct cdcacm_driver_s *drvr = (FAR struct cdcacm_driver_s *)classdev;
FAR struct cdcacm_dev_s *priv = drvr->dev;
- char devname[CDCACM_DEVNAME_SIZE];
+
+ cdcacm_uninitialize_instance(priv->minor, classdev);
+}
+
+/****************************************************************************
+ * Name: cdcacm_uninitialize_instance
+ *
+ * Description:
+ * Function to uninitialize specific cdcacm instance
+ *
+ * Input Parameters:
+ * minor - CDCACM node minor number
+ *
+ * Returned Value:
+ * OK when successful, -ENODEV if cdcacm is not initialized
+ *
+ ****************************************************************************/
+
+int cdcacm_uninitialize_instance(int minor,
+ FAR struct usbdevclass_driver_s *classdev)
+{
int ret;
+ FAR struct cdcacm_driver_s *drvr = (FAR struct cdcacm_driver_s *)classdev;
+ FAR struct cdcacm_dev_s *priv;
+ char devname[CDCACM_DEVNAME_SIZE];
+
+ /* Create device node path from minor number */
+
+ snprintf(devname, sizeof(devname), CDCACM_DEVNAME_FORMAT, minor);
+
+ ret = nxmutex_lock(&g_init_lock);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* If classdev is not provided, find it from the file system */
+
+ if (!classdev)
Review Comment:
```suggestion
if (classdev == NULL)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]