TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context) { int error; struct tf_connection *connection = NULL; error = tf_open(tf_get_device(), NULL, &connection); if (error != 0) { dprintk(KERN_ERR "TEEC_InitializeContext(%s): " "tf_open failed (error %d)!\n", (name == NULL ? "(null)" : name), error); goto error; } BUG_ON(connection == NULL); connection->owner = TF_CONNECTION_OWNER_KERNEL; error = tf_create_device_context(connection); if (error != 0) { dprintk(KERN_ERR "TEEC_InitializeContext(%s): " "tf_create_device_context failed (error %d)!\n", (name == NULL ? "(null)" : name), error); goto error; } context->imp._connection = connection; /*spin_lock_init(&context->imp._operations_lock);*/ return S_SUCCESS; error: tf_close(connection); return TEEC_encode_error(error); }
static int tf_device_open(struct inode *inode, struct file *file) { int error; struct tf_device *dev = &g_tf_dev; struct tf_connection *connection = NULL; dprintk(KERN_INFO "tf_device_open(%u:%u, %p)\n", imajor(inode), iminor(inode), file); /* Dummy lseek for non-seekable driver */ error = nonseekable_open(inode, file); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "nonseekable_open failed (error %d)!\n", file, error); goto error; } #ifndef CONFIG_ANDROID /* * Check file flags. We only autthorize the O_RDWR access */ if (file->f_flags != O_RDWR) { dprintk(KERN_ERR "tf_device_open(%p): " "Invalid access mode %u\n", file, file->f_flags); error = -EACCES; goto error; } #endif /* * Open a new connection. */ error = tf_open(dev, file, &connection); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "tf_open failed (error %d)!\n", file, error); goto error; } file->private_data = connection; /* * Send the CreateDeviceContext command to the secure */ error = tf_create_device_context(connection); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "tf_create_device_context failed (error %d)!\n", file, error); goto error1; } /* * Successful completion. */ dprintk(KERN_INFO "tf_device_open(%p): Success (connection=%p)\n", file, connection); return 0; /* * Error handling. */ error1: tf_close(connection); error: dprintk(KERN_INFO "tf_device_open(%p): Failure (error %d)\n", file, error); return error; }
static int tf_device_open(struct inode *inode, struct file *file) { int error; struct tf_device *dev = &g_tf_dev; struct tf_connection *connection = NULL; dprintk(KERN_INFO "tf_device_open(%u:%u, %p)\n", imajor(inode), iminor(inode), file); /* Dummy lseek for non-seekable driver */ error = nonseekable_open(inode, file); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "nonseekable_open failed (error %d)!\n", file, error); goto error; } /* * Open a new connection. */ error = tf_open(dev, file, &connection); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "tf_open failed (error %d)!\n", file, error); goto error; } file->private_data = connection; /* * Send the CreateDeviceContext command to the secure */ error = tf_create_device_context(connection); if (error != 0) { dprintk(KERN_ERR "tf_device_open(%p): " "tf_create_device_context failed (error %d)!\n", file, error); goto error1; } /* * Successful completion. */ dprintk(KERN_INFO "tf_device_open(%p): Success (connection=%p)\n", file, connection); return 0; /* * Error handling. */ error1: tf_close(connection); error: dprintk(KERN_INFO "tf_device_open(%p): Failure (error %d)\n", file, error); return error; }