forked from mirrors/linux
		
	ALSA: timer: Simplify error path in snd_timer_open()
Just a minor refactoring to use the standard goto for error paths in snd_timer_open() instead of open code. The first mutex_lock() is moved to the beginning of the function to make the code clearer. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
		
							parent
							
								
									2eabc5ec8a
								
							
						
					
					
						commit
						41672c0c24
					
				
					 1 changed files with 20 additions and 19 deletions
				
			
		| 
						 | 
					@ -255,19 +255,20 @@ int snd_timer_open(struct snd_timer_instance **ti,
 | 
				
			||||||
	struct snd_timer_instance *timeri = NULL;
 | 
						struct snd_timer_instance *timeri = NULL;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mutex_lock(®ister_mutex);
 | 
				
			||||||
	if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
 | 
						if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
 | 
				
			||||||
		/* open a slave instance */
 | 
							/* open a slave instance */
 | 
				
			||||||
		if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
 | 
							if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
 | 
				
			||||||
		    tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
 | 
							    tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
 | 
				
			||||||
			pr_debug("ALSA: timer: invalid slave class %i\n",
 | 
								pr_debug("ALSA: timer: invalid slave class %i\n",
 | 
				
			||||||
				 tid->dev_sclass);
 | 
									 tid->dev_sclass);
 | 
				
			||||||
			return -EINVAL;
 | 
								err = -EINVAL;
 | 
				
			||||||
 | 
								goto unlock;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		mutex_lock(®ister_mutex);
 | 
					 | 
				
			||||||
		timeri = snd_timer_instance_new(owner, NULL);
 | 
							timeri = snd_timer_instance_new(owner, NULL);
 | 
				
			||||||
		if (!timeri) {
 | 
							if (!timeri) {
 | 
				
			||||||
			mutex_unlock(®ister_mutex);
 | 
								err = -ENOMEM;
 | 
				
			||||||
			return -ENOMEM;
 | 
								goto unlock;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		timeri->slave_class = tid->dev_sclass;
 | 
							timeri->slave_class = tid->dev_sclass;
 | 
				
			||||||
		timeri->slave_id = tid->device;
 | 
							timeri->slave_id = tid->device;
 | 
				
			||||||
| 
						 | 
					@ -278,13 +279,10 @@ int snd_timer_open(struct snd_timer_instance **ti,
 | 
				
			||||||
			snd_timer_close_locked(timeri);
 | 
								snd_timer_close_locked(timeri);
 | 
				
			||||||
			timeri = NULL;
 | 
								timeri = NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		mutex_unlock(®ister_mutex);
 | 
							goto unlock;
 | 
				
			||||||
		*ti = timeri;
 | 
					 | 
				
			||||||
		return err;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* open a master instance */
 | 
						/* open a master instance */
 | 
				
			||||||
	mutex_lock(®ister_mutex);
 | 
					 | 
				
			||||||
	timer = snd_timer_find(tid);
 | 
						timer = snd_timer_find(tid);
 | 
				
			||||||
#ifdef CONFIG_MODULES
 | 
					#ifdef CONFIG_MODULES
 | 
				
			||||||
	if (!timer) {
 | 
						if (!timer) {
 | 
				
			||||||
| 
						 | 
					@ -295,25 +293,26 @@ int snd_timer_open(struct snd_timer_instance **ti,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	if (!timer) {
 | 
						if (!timer) {
 | 
				
			||||||
		mutex_unlock(®ister_mutex);
 | 
							err = -ENODEV;
 | 
				
			||||||
		return -ENODEV;
 | 
							goto unlock;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!list_empty(&timer->open_list_head)) {
 | 
						if (!list_empty(&timer->open_list_head)) {
 | 
				
			||||||
		timeri = list_entry(timer->open_list_head.next,
 | 
							timeri = list_entry(timer->open_list_head.next,
 | 
				
			||||||
				    struct snd_timer_instance, open_list);
 | 
									    struct snd_timer_instance, open_list);
 | 
				
			||||||
		if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
 | 
							if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
 | 
				
			||||||
			mutex_unlock(®ister_mutex);
 | 
								err = -EBUSY;
 | 
				
			||||||
			return -EBUSY;
 | 
								timeri = NULL;
 | 
				
			||||||
 | 
								goto unlock;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (timer->num_instances >= timer->max_instances) {
 | 
						if (timer->num_instances >= timer->max_instances) {
 | 
				
			||||||
		mutex_unlock(®ister_mutex);
 | 
							err = -EBUSY;
 | 
				
			||||||
		return -EBUSY;
 | 
							goto unlock;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	timeri = snd_timer_instance_new(owner, timer);
 | 
						timeri = snd_timer_instance_new(owner, timer);
 | 
				
			||||||
	if (!timeri) {
 | 
						if (!timeri) {
 | 
				
			||||||
		mutex_unlock(®ister_mutex);
 | 
							err = -ENOMEM;
 | 
				
			||||||
		return -ENOMEM;
 | 
							goto unlock;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	/* take a card refcount for safe disconnection */
 | 
						/* take a card refcount for safe disconnection */
 | 
				
			||||||
	if (timer->card)
 | 
						if (timer->card)
 | 
				
			||||||
| 
						 | 
					@ -322,16 +321,16 @@ int snd_timer_open(struct snd_timer_instance **ti,
 | 
				
			||||||
	timeri->slave_id = slave_id;
 | 
						timeri->slave_id = slave_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (list_empty(&timer->open_list_head) && timer->hw.open) {
 | 
						if (list_empty(&timer->open_list_head) && timer->hw.open) {
 | 
				
			||||||
		int err = timer->hw.open(timer);
 | 
							err = timer->hw.open(timer);
 | 
				
			||||||
		if (err) {
 | 
							if (err) {
 | 
				
			||||||
			kfree(timeri->owner);
 | 
								kfree(timeri->owner);
 | 
				
			||||||
			kfree(timeri);
 | 
								kfree(timeri);
 | 
				
			||||||
 | 
								timeri = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (timer->card)
 | 
								if (timer->card)
 | 
				
			||||||
				put_device(&timer->card->card_dev);
 | 
									put_device(&timer->card->card_dev);
 | 
				
			||||||
			module_put(timer->module);
 | 
								module_put(timer->module);
 | 
				
			||||||
			mutex_unlock(®ister_mutex);
 | 
								goto unlock;
 | 
				
			||||||
			return err;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -342,6 +341,8 @@ int snd_timer_open(struct snd_timer_instance **ti,
 | 
				
			||||||
		snd_timer_close_locked(timeri);
 | 
							snd_timer_close_locked(timeri);
 | 
				
			||||||
		timeri = NULL;
 | 
							timeri = NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 unlock:
 | 
				
			||||||
	mutex_unlock(®ister_mutex);
 | 
						mutex_unlock(®ister_mutex);
 | 
				
			||||||
	*ti = timeri;
 | 
						*ti = timeri;
 | 
				
			||||||
	return err;
 | 
						return err;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue