static long nsm_dev_ioctl()

in nsm-driver/nsm.c [304:338]


static long nsm_dev_ioctl(struct file *file, unsigned int cmd,
	unsigned long arg)
{
	struct nsm_kernel_message message;
	int status = 0;

	if (cmd != NSM_IO_REQUEST)
		return -EINVAL;

	/* The kernel message structure must be cleared */
	memset(&message, 0, sizeof(message));

	/* Copy the message from user-space to kernel-space */
	status = message_copy_from_user(&message, (struct nsm_message *)arg);
	if (status != 0)
		return status;

	/* Communicate with the NSM device */
	mutex_lock(&nsm_lock);
	status = nsm_communicate_with_device(&message);
	mutex_unlock(&nsm_lock);

	if (status != 0) {
		message_delete(&message);
		return status;
	}

	/* Copy the response back to user-space */
	status = message_copy_to_user((struct nsm_message *)arg, &message);

	/* At this point, everything succeeded, so clean up and finish. */
	message_delete(&message);

	return status;
}