Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4466812ybx; Mon, 4 Nov 2019 13:55:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyKR1rqGiNMdjcApO33k5oBX7AoVAgzjIwxzCjtBwZ1ab5VTXo2MDQAEW1Qypc0bAxL0kgC X-Received: by 2002:aa7:c80d:: with SMTP id a13mr32051054edt.59.1572904506322; Mon, 04 Nov 2019 13:55:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572904506; cv=none; d=google.com; s=arc-20160816; b=hjv4RcMD5rlKCJfr4r5XMWhl6e//ViYD8lkhy6jQKBtDi/nYO3Pp7jLGBK8wZZ+and bx7wYOu0sBQx5+R9m9b+YtHugYU1pfB6icldLa+4oHnkJ/v0DVDhlsUxOIBjBKJ+xyBB ynoYAIzF5E2wEfQQ0E6gXDVXpw6l2AvbyJ46F6RSQi8wkIS0py2Pv8nF8jPydttYeuzR ahDPwCcoUuO+a6/Ds7BKDaR6aSTNUkXwEAy41OjC8GP7NBIopN0GLYunlaRAWbofEGnO qr9PGAMRohIbmKy1i4hfIi6bo9zHr0w2asdJYau/PzH0UIgTdMDOwbSDnbS51+XhvT0S xOMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k92YymmHkZSFQQ0BJ0dY6d4kUHoDWXJ4DiICq/+ip7s=; b=072ojsy0SzDFQeJHAoGOgsxa+ylhK2QSJvNbj7zOyl++9Hu0UZG53IIyyspMf0c0lX KET5DNCDtZc2s2YVwanWlfeNTosM6vrA555NybvXwqj8kTRruP2xA0YMKAa9F6n9KAsF YbaF9v9C7//k5JczDHlJPma4Nz5JlQXXgj6t3INuCNEXV2TP+l9M2mgpTLsII1N4/k0E AUlOe4AHDqV/np3g1sAG6//sGlzsgxQgPwIfRtGIZbIxARdx8OqMvGI1MkXua5qyf2SR /SiyTdiQ/rOse3LGZERuJTxwVVn0Qu71uwLGhw74aKcOGOqGeTq7pG7gKuJ3t75PJuP2 JxTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LtKmPmHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24si10494017ejz.252.2019.11.04.13.54.43; Mon, 04 Nov 2019 13:55:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LtKmPmHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730643AbfKDVv6 (ORCPT + 99 others); Mon, 4 Nov 2019 16:51:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:45008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730629AbfKDVvy (ORCPT ); Mon, 4 Nov 2019 16:51:54 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAC77217F5; Mon, 4 Nov 2019 21:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904313; bh=QDtYiaW8pMVAcjR4z3UvlNtLXCVqNgx0gLg082M8GG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtKmPmHRHIuQnyeykdwFcESVD7OnoMCJNFoafIz/aRVVxd4D4MHn4QKPBOasozn10 kJVctfFwdA2IBZS//waQLNbOkj0XbWZAP7zfU1X1y5v9qgnRTR5zAMnXCX8qBfJz8Z Dkk3lNVvv2nOXRKbBSuO6Tq9XGrHagBTjMb7yNSY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Sasha Levin Subject: [PATCH 4.9 61/62] ALSA: timer: Simplify error path in snd_timer_open() Date: Mon, 4 Nov 2019 22:45:23 +0100 Message-Id: <20191104212000.884979037@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211901.387893698@linuxfoundation.org> References: <20191104211901.387893698@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 41672c0c24a62699d20aab53b98d843b16483053 ] 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 Signed-off-by: Sasha Levin --- sound/core/timer.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/sound/core/timer.c b/sound/core/timer.c index 95c5838747754..6eb4e97662d9c 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -253,19 +253,20 @@ int snd_timer_open(struct snd_timer_instance **ti, struct snd_timer_instance *timeri = NULL; int err; + mutex_lock(®ister_mutex); if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) { /* open a slave instance */ if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) { pr_debug("ALSA: timer: invalid slave class %i\n", tid->dev_sclass); - return -EINVAL; + err = -EINVAL; + goto unlock; } - mutex_lock(®ister_mutex); timeri = snd_timer_instance_new(owner, NULL); if (!timeri) { - mutex_unlock(®ister_mutex); - return -ENOMEM; + err = -ENOMEM; + goto unlock; } timeri->slave_class = tid->dev_sclass; timeri->slave_id = tid->device; @@ -276,13 +277,10 @@ int snd_timer_open(struct snd_timer_instance **ti, snd_timer_close_locked(timeri); timeri = NULL; } - mutex_unlock(®ister_mutex); - *ti = timeri; - return err; + goto unlock; } /* open a master instance */ - mutex_lock(®ister_mutex); timer = snd_timer_find(tid); #ifdef CONFIG_MODULES if (!timer) { @@ -293,25 +291,26 @@ int snd_timer_open(struct snd_timer_instance **ti, } #endif if (!timer) { - mutex_unlock(®ister_mutex); - return -ENODEV; + err = -ENODEV; + goto unlock; } if (!list_empty(&timer->open_list_head)) { timeri = list_entry(timer->open_list_head.next, struct snd_timer_instance, open_list); if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { - mutex_unlock(®ister_mutex); - return -EBUSY; + err = -EBUSY; + timeri = NULL; + goto unlock; } } if (timer->num_instances >= timer->max_instances) { - mutex_unlock(®ister_mutex); - return -EBUSY; + err = -EBUSY; + goto unlock; } timeri = snd_timer_instance_new(owner, timer); if (!timeri) { - mutex_unlock(®ister_mutex); - return -ENOMEM; + err = -ENOMEM; + goto unlock; } /* take a card refcount for safe disconnection */ if (timer->card) @@ -320,16 +319,16 @@ int snd_timer_open(struct snd_timer_instance **ti, timeri->slave_id = slave_id; if (list_empty(&timer->open_list_head) && timer->hw.open) { - int err = timer->hw.open(timer); + err = timer->hw.open(timer); if (err) { kfree(timeri->owner); kfree(timeri); + timeri = NULL; if (timer->card) put_device(&timer->card->card_dev); module_put(timer->module); - mutex_unlock(®ister_mutex); - return err; + goto unlock; } } @@ -340,6 +339,8 @@ int snd_timer_open(struct snd_timer_instance **ti, snd_timer_close_locked(timeri); timeri = NULL; } + + unlock: mutex_unlock(®ister_mutex); *ti = timeri; return err; -- 2.20.1