Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4472375ybx; Mon, 4 Nov 2019 14:01:05 -0800 (PST) X-Google-Smtp-Source: APXvYqySMujrEc/okMlqNAaWwq6l88ShjW8/JmvxxvTrJzkBAamnSlsDYe88hek7lVizZt93k9us X-Received: by 2002:a17:906:80c:: with SMTP id e12mr9299193ejd.59.1572904865289; Mon, 04 Nov 2019 14:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572904865; cv=none; d=google.com; s=arc-20160816; b=DSXNkzi0/yEh0YwE5L0v6QOk4dAU9DB9z6rjP96jfTexV45dYN/vgs9+fJx83zS3GL 9PSd3DPtCL0luqlQfKmWnedaZhKjtju5xdeVfxqT4X2iHK/jQL4WH/WTFyTWay9gR/h+ mU4QIJlHQPECb9Rx9LXZsLwKvEoh4PiXoKPfUtEW05YDQ13rEJUP1+gZk5Frm2W5A4pQ 5QRavT4wJ3YagAqNzSe2DPBDNTzPLeZxfmDi7N9+q7gkNGJDrXPctjLsdVnAbYERa7g5 4E9kI5ns810Ipo9D9vUVExoOk1M3MSI9iJ39aDTcUGYgPvramVPwU0pfuT0WbnAW8q1M +taQ== 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=3NEa0dmLdBEX+75nD/WSFnq+5QCfufV/le2aXUIKA8U=; b=mrOJ7wBaW+luv3WGSFmWGE4jWnft/GZdimWGPexhv1w8MKpZCV8uc8zOc5rt5CDhuD XkNhF3PImcI1Wgp8sJiSejr8IoOrMZIVzfECXNgEtqyNpL0h8BpU6vVqSl0bStaaecTE kkygwwnnoSgC15eSoWnuhFXeM3f+PtZdDqClz0f17Xn+f8TuM2fTq92NYuYhKnh4igB/ lWVdzAzshho6cf3NuP35vZX+iHN8YJVn0bAPBZbGKrHiFgNO31YpLIYPCUSImWvIXwfv Rak4lHFNT1EoLsIuDQ4TNkCIf9PQIFhNMUXqZOi5SmPBqfub1aqQL8JVCgMO3PZj+jOh WtDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dwoKBTpW; 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 k24si8135135edk.367.2019.11.04.14.00.41; Mon, 04 Nov 2019 14:01:05 -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=dwoKBTpW; 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 S2388480AbfKDV4w (ORCPT + 99 others); Mon, 4 Nov 2019 16:56:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:52582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388407AbfKDV4t (ORCPT ); Mon, 4 Nov 2019 16:56:49 -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 0226320650; Mon, 4 Nov 2019 21:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904608; bh=nHrJQy6IRtduNdoMR+OvKKGPN+3FdGijZZWTnM9090E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dwoKBTpW1mJflVVXYO8tjq2aML/qbg7io9X6zc+plkLWQL/RMavz/PdCFv1UwtMHF +4HJ3b8UXaZ5bqiuR3E4BoUYws0N5q5+Hfmf0dZZ/MXKl4nO6EFb4dGCCv5biqQOTm s4IApHk98/UJVMmKalNGDSHKLnwaRVu4/HeFP1Qg= 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.14 94/95] ALSA: timer: Simplify error path in snd_timer_open() Date: Mon, 4 Nov 2019 22:45:32 +0100 Message-Id: <20191104212125.226357372@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212038.056365853@linuxfoundation.org> References: <20191104212038.056365853@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 2c0f292226d79..b50f7601cc2b0 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -254,19 +254,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; @@ -277,13 +278,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) { @@ -294,25 +292,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) @@ -321,16 +320,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; } } @@ -341,6 +340,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