Commit 4ab0f5ce authored by Nicolas Saenz Julienne's avatar Nicolas Saenz Julienne Committed by Greg Kroah-Hartman
Browse files

staging: vchiq_arm: fix open/release cdev functions



Both functions checked the minor number of the cdev prior running the
code. This was useless since the number of devices is already limited by
alloc_chrdev_region.

This removes the check and reindents the code where relevant.

Signed-off-by: default avatarNicolas Saenz Julienne <nsaenzjulienne@suse.de>
Acked-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 187ac53e
Loading
Loading
Loading
Loading
+100 −147
Original line number Diff line number Diff line
@@ -63,8 +63,6 @@
#undef MODULE_PARAM_PREFIX
#define MODULE_PARAM_PREFIX DEVICE_NAME "."

#define VCHIQ_MINOR 0

/* Some per-instance constants */
#define MAX_COMPLETIONS 128
#define MAX_SERVICES 64
@@ -1950,23 +1948,13 @@ vchiq_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

#endif

/****************************************************************************
*
*   vchiq_open
*
***************************************************************************/

static int
vchiq_open(struct inode *inode, struct file *file)
static int vchiq_open(struct inode *inode, struct file *file)
{
	int dev = iminor(inode) & 0x0f;

	vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
	switch (dev) {
	case VCHIQ_MINOR: {
	VCHIQ_STATE_T *state = vchiq_get_state();
	VCHIQ_INSTANCE_T instance;

	vchiq_log_info(vchiq_arm_log_level, "vchiq_open");

	if (!state) {
		vchiq_log_error(vchiq_arm_log_level,
				"vchiq has no connection to VideoCore");
@@ -1989,39 +1977,20 @@ vchiq_open(struct inode *inode, struct file *file)
	INIT_LIST_HEAD(&instance->bulk_waiter_list);

	file->private_data = instance;
	} break;

	default:
		vchiq_log_error(vchiq_arm_log_level,
			"Unknown minor device: %d", dev);
		return -ENXIO;
	}

	return 0;
}

/****************************************************************************
*
*   vchiq_release
*
***************************************************************************/

static int
vchiq_release(struct inode *inode, struct file *file)
static int vchiq_release(struct inode *inode, struct file *file)
{
	int dev = iminor(inode) & 0x0f;
	int ret = 0;

	switch (dev) {
	case VCHIQ_MINOR: {
	VCHIQ_INSTANCE_T instance = file->private_data;
	VCHIQ_STATE_T *state = vchiq_get_state();
	VCHIQ_SERVICE_T *service;
	int ret = 0;
	int i;

		vchiq_log_info(vchiq_arm_log_level,
			"%s: instance=%lx",
			__func__, (unsigned long)instance);
	vchiq_log_info(vchiq_arm_log_level, "%s: instance=%lx", __func__,
		       (unsigned long)instance);

	if (!state) {
		ret = -EPERM;
@@ -2029,8 +1998,7 @@ vchiq_release(struct inode *inode, struct file *file)
	}

	/* Ensure videocore is awake to allow termination. */
		vchiq_use_internal(instance->state, NULL,
				USE_TYPE_VCHIQ);
	vchiq_use_internal(instance->state, NULL, USE_TYPE_VCHIQ);

	mutex_lock(&instance->completion_mutex);

@@ -2045,8 +2013,7 @@ vchiq_release(struct inode *inode, struct file *file)

	/* Mark all services for termination... */
	i = 0;
		while ((service = next_service_by_instance(state, instance,
			&i)) !=	NULL) {
	while ((service = next_service_by_instance(state, instance, &i))) {
		USER_SERVICE_T *user_service = service->base.userdata;

		/* Wake the slot handler if the msg queue is full. */
@@ -2058,8 +2025,7 @@ vchiq_release(struct inode *inode, struct file *file)

	/* ...and wait for them to die */
	i = 0;
		while ((service = next_service_by_instance(state, instance, &i))
			!= NULL) {
	while ((service = next_service_by_instance(state, instance, &i))) {
		USER_SERVICE_T *user_service = service->base.userdata;

		wait_for_completion(&service->remove_event);
@@ -2068,20 +2034,16 @@ vchiq_release(struct inode *inode, struct file *file)

		spin_lock(&msg_queue_spinlock);

			while (user_service->msg_remove !=
				user_service->msg_insert) {
		while (user_service->msg_remove != user_service->msg_insert) {
			VCHIQ_HEADER_T *header;
				int m = user_service->msg_remove &
					(MSG_QUEUE_SIZE - 1);
			int m = user_service->msg_remove & (MSG_QUEUE_SIZE - 1);

			header = user_service->msg_queue[m];
			user_service->msg_remove++;
			spin_unlock(&msg_queue_spinlock);

			if (header)
					vchiq_release_message(
						service->handle,
						header);
				vchiq_release_message(service->handle, header);
			spin_lock(&msg_queue_spinlock);
		}

@@ -2097,12 +2059,10 @@ vchiq_release(struct inode *inode, struct file *file)
		VCHIQ_SERVICE_T *service;

		completion = &instance->completions[
				instance->completion_remove &
				(MAX_COMPLETIONS - 1)];
			instance->completion_remove & (MAX_COMPLETIONS - 1)];
		service = completion->service_userdata;
		if (completion->reason == VCHIQ_SERVICE_CLOSED) {
				USER_SERVICE_T *user_service =
					service->base.userdata;
			USER_SERVICE_T *user_service = service->base.userdata;

			/* Wake any blocked user-thread */
			if (instance->use_close_delivered)
@@ -2132,13 +2092,6 @@ vchiq_release(struct inode *inode, struct file *file)

	kfree(instance);
	file->private_data = NULL;
	} break;

	default:
		vchiq_log_error(vchiq_arm_log_level,
			"Unknown minor device: %d", dev);
		ret = -ENXIO;
	}

out:
	return ret;
@@ -3613,7 +3566,7 @@ static int __init vchiq_driver_init(void)
		return PTR_ERR(vchiq_class);
	}

	ret = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
	ret = alloc_chrdev_region(&vchiq_devid, 0, 1, DEVICE_NAME);
	if (ret) {
		pr_err("Failed to allocate vchiq's chrdev region\n");
		goto class_destroy;