You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "trns1997 (via GitHub)" <gi...@apache.org> on 2023/10/09 19:42:42 UTC

[PR] add munmap logic to pseudofs [nuttx]

trns1997 opened a new pull request, #10880:
URL: https://github.com/apache/nuttx/pull/10880

   ## Summary
   - Add munmap logic to pseudo fs to prevent munmap from ret EINVAL when called.
   
   ## Impact
   
   ## Testing
   
   


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] add munmap logic to pseudofs [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #10880:
URL: https://github.com/apache/nuttx/pull/10880


-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] add munmap logic to pseudofs [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #10880:
URL: https://github.com/apache/nuttx/pull/10880#discussion_r1352512465


##########
fs/vfs/fs_pseudofile.c:
##########
@@ -309,14 +313,76 @@ static int pseudofile_mmap(FAR struct file *filep,
   FAR struct inode *node = filep->f_inode;
   FAR struct fs_pseudofile_s *pf = node->i_private;
 
-  if (map->offset >= 0 && map->offset < node->i_size &&
-      map->length != 0 && map->offset + map->length <= node->i_size)
+  /* Keep the inode when mmapped, increase refcount */
+
+  int ret = inode_addref(node);
+  if (ret >= 0)
     {
-      map->vaddr = pf->content + map->offset;
-      return OK;
+      if (map->offset >= 0 && map->offset < node->i_size &&
+          map->length != 0 && map->offset + map->length <= node->i_size)
+        {
+          map->vaddr = pf->content + map->offset;
+          map->munmap = pseudofile_munmap;
+          map->priv.p = (FAR void *)node;
+          ret = mm_map_add(get_current_mm(), map);
+        }
+      else
+        {
+          ret = -EINVAL;
+        }
+
+      if (ret < 0)
+        {
+          inode_release(node);
+        }
     }
 
-  return -EINVAL;
+  return ret;
+}
+
+static int pseudofile_munmap(FAR struct task_group_s *group,
+                                 FAR struct mm_map_entry_s *map,

Review Comment:
   alignment



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org