xiaoxiang781216 commented on a change in pull request #5204: URL: https://github.com/apache/incubator-nuttx/pull/5204#discussion_r815457612
########## File path: drivers/input/ajoystick.c ########## @@ -526,12 +461,7 @@ static ssize_t ajoy_read(FAR struct file *filep, FAR char *buffer, /* Get exclusive access to the driver structure */ - ret = ajoy_takesem(&priv->au_exclsem); - if (ret < 0) - { - ierr("ERROR: ajoy_takesem failed: %d\n", ret); - return ret; - } + flags = enter_critical_section(); Review comment: vfs layer can't handle this case correctly in the complex case. To avoid the used after free, the better solution is: 1. Add a reference count to struct file 2. Initialize the reference count to 1 in file_open 3. Decrease the reference count in file_close 4. Increase count before call file_xxx and decrease after 5. Release the resource only when the reference count become zero This way, the real release happen(delayed) after file_read return when file_close is called during file_read is executing. -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org