xiaoxiang781216 commented on code in PR #16734:
URL: https://github.com/apache/nuttx/pull/16734#discussion_r2229101591


##########
drivers/misc/optee.c:
##########
@@ -491,6 +488,60 @@ static int optee_shm_close(FAR struct file *filep)
   return 0;
 }
 
+/****************************************************************************
+ * Name: optee_shm_mmap
+ *
+ * Description:
+ *   shm mmap operation
+ *
+ * Parameters:
+ *   filep  - the file instance
+ *   map    - Filled by the userspace, with the mapping parameters.
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int optee_shm_mmap(FAR struct file *filep,
+                          FAR struct mm_map_entry_s *map)
+{
+  FAR struct optee_shm *shm = filep->f_priv;
+  int32_t ret = OK;
+
+  if ((map->flags & MAP_PRIVATE) && (map->flags & MAP_SHARED))
+    {
+      return -EINVAL;
+    }
+
+  /* Forbid multiple mmaps of the same fd. */
+
+  if (shm->vaddr != 0)
+    {
+      return -EBUSY;
+    }
+
+  /* Forbid allocations with bigger size than what registered with
+   * with optee_ioctl_shm_alloc().
+   */
+
+  if (shm->length < map->length)
+    {
+      return -EINVAL;
+    }
+
+  ret = map_anonymous(map, MAP_USER);

Review Comment:
   MAP_USER->false



##########
drivers/misc/optee.c:
##########
@@ -1237,7 +1237,7 @@ static int optee_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
  *
  ****************************************************************************/
 
-int optee_convert_error(uint32_t oterr)
+int optee_convert_from_tee_error(uint32_t oterr)

Review Comment:
   optee_convert_to_errno



##########
drivers/misc/optee.c:
##########
@@ -1218,15 +1239,18 @@ int optee_shm_alloc(FAR struct optee_priv_data *priv, 
FAR void *addr,
       ptr = addr;
     }
 
-  if (ptr == NULL)
+  if (!(flags & TEE_SHM_USER_MAP))
     {
-      goto err;
+      if (ptr == NULL)

Review Comment:
   but not merge yet



##########
drivers/misc/optee.c:
##########
@@ -361,7 +361,7 @@ static int optee_shm_register(FAR struct optee_priv_data 
*priv,
 
   if (msg->ret)
     {
-      ret = optee_convert_error(msg->ret);
+      ret = optee_convert_from_tee_error(msg->ret);

Review Comment:
   merge to previous patch



##########
drivers/misc/optee.c:
##########
@@ -1088,6 +1034,130 @@ optee_ioctl_shm_register(FAR struct optee_priv_data 
*priv,
   return ret;
 }
 
+#ifdef CONFIG_DEV_OPTEE_SUPPLICANT
+static
+int optee_ioctl_supplicant_recv(FAR struct optee_priv_data *priv,
+                                FAR struct tee_ioctl_buf_data  *data)
+{
+  int ret;
+  FAR struct tee_iocl_supp_recv_arg *arg;
+
+  if (!optee_is_valid_range(data, sizeof(*data)))
+    {
+      return -EFAULT;
+    }
+
+  if (!optee_is_valid_range((void *)data->buf_ptr, data->buf_len))
+    {
+      return -EFAULT;
+    }
+
+  if (data->buf_len > TEE_MAX_ARG_SIZE ||
+      data->buf_len < sizeof(struct tee_iocl_supp_recv_arg))
+    {
+      return -EINVAL;
+    }
+
+  arg = (FAR struct tee_iocl_supp_recv_arg *)(uintptr_t)data->buf_ptr;
+
+  if (sizeof(*arg) + TEE_IOCTL_PARAM_SIZE(arg->num_params) !=
+      data->buf_len)
+    {
+      return -EINVAL;
+    }
+
+  if (arg->num_params > OPTEE_MAX_PARAM_NUM)
+    {
+      return -EINVAL;
+    }
+
+  ret = optee_supplicant_recv(&arg->func, &arg->num_params, arg->params);
+
+  if (ret)
+    {
+      goto out;

Review Comment:
   no change



##########
drivers/misc/optee.c:
##########
@@ -1103,6 +1049,126 @@ optee_ioctl_shm_register(FAR struct optee_priv_data 
*priv,
   return ret;
 }
 
+#ifdef CONFIG_DEV_OPTEE_SUPPLICANT
+static int
+optee_ioctl_supplicant_recv(FAR struct optee_priv_data *priv,
+                            FAR struct tee_ioctl_buf_data  *data)

Review Comment:
   remove extra space before *data



##########
drivers/misc/optee_supplicant.c:
##########
@@ -463,7 +463,7 @@ int32_t optee_supplicant_cmd_alloc(FAR struct 
optee_priv_data *priv,
   ret = optee_supplicant_request(OPTEE_MSG_RPC_CMD_SHM_ALLOC, 1, &param);
   if (ret)
     {
-      return optee_convert_error(ret);
+      return optee_convert_from_tee_error(ret);

Review Comment:
   change return type from int32_t to int



##########
include/nuttx/fs/fs.h:
##########
@@ -574,6 +574,15 @@ struct streamlist
 };
 #endif /* CONFIG_FILE_STREAM */
 
+/* A memory mapping type definition */
+
+enum mm_map_type_e

Review Comment:
   don't need move to public



##########
drivers/misc/optee.c:
##########
@@ -980,49 +1031,34 @@ optee_ioctl_shm_alloc(FAR struct optee_priv_data *priv,
                       FAR struct tee_ioctl_shm_alloc_data *data)
 {
   FAR struct optee_shm *shm;
-  FAR void *addr;
-  int memfd;
   int ret;
 
   if (!optee_is_valid_range(data, sizeof(*data)))
     {
       return -EFAULT;
     }
 
-  memfd = memfd_create(OPTEE_SERVER_PATH, O_CREAT | O_CLOEXEC);
-  if (memfd < 0)
+  ret = optee_shm_alloc(priv, NULL, data->size, TEE_SHM_USER_MAP, &shm);
+  if (ret < 0)
     {
-      return get_errno();
+      return ret;
     }
 
-  if (ftruncate(memfd, data->size) < 0)
-    {
-      ret = get_errno();
-      goto err;
-    }
+  ret = file_allocate_from_inode(&g_optee_shm_inode,
+                                 O_CLOEXEC | O_RDOK, 0, shm, 0);

Review Comment:
   should we use O_RDWR



-- 
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]

Reply via email to