From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757573AbdKOOCJ (ORCPT ); Wed, 15 Nov 2017 09:02:09 -0500 Received: from mout.web.de ([212.227.17.12]:52429 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757984AbdKOOBx (ORCPT ); Wed, 15 Nov 2017 09:01:53 -0500 To: alsa-devel@alsa-project.org, Ander Conselvan De Oliveira , Bhumika Goyal , Daniel Dadap , Jaroslav Kysela , Libin Yang , Pierre-Louis Bossart , "Subhransu S. Prusty" , Takashi Iwai , Vinod Koul From: SF Markus Elfring Subject: [PATCH] ALSA: HDA: Improve unlocking of a mutex in hdmi_pcm_open() Cc: LKML , kernel-janitors@vger.kernel.org Message-ID: Date: Wed, 15 Nov 2017 15:00:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:m10r04fBTevNBTFdSUq3QDoz0FwiyA0xKiZicm6nyZXyQ14iQt1 gpow69bVKY/X6A+BTZho28OBwJ9gLaBYXmbd6FFwRF8+qVNNzdsH+ELqb4P7JLxIoCWU2HK uKrY9tGZfY1s8xvhNrmUHuMAxRycakUG6s8/IkhIpaVpGdK/o0pEB4jFH4JCcFZFOMDtepo I8y8G5HGcmGF+R7FHLVtA== X-UI-Out-Filterresults: notjunk:1;V01:K0:h4kSXWjnFaM=:ZIKDieHyRdtBHZzKAvjvlo Vj3IcrdLsvW1VSZ7tndLnfv3Da5QxwstcFvyy0gvH3bAyNxxriMgCXVGT4PEVo7cn6cW1uNSh bL92315eDZZPoIhVKpzvdoyKk8UByzEkSjPo1w4FsVgCe0q7eX6+jlX3zlbaSGrf3l5jWuCDz BPy+/D/Mdorcl19bHPwLI7i2L2VHFFliESzF9HoENvdaM8F6uUajoKw6E1H+4XR6+yPsckWp/ Fs8OCJDydBz7uH0k6JDaKd3owmB9wj54jdvgjGnZIJ6hvuvObIbYKRcp8bY90wVCQTKgwcn2P 49mxuS6j9l7HWVRsP3Wza8In7M5eted59EAA/MZPPBNVu16zATqqB/nlqC3vnGNJQF1/lAF5R Rusi++/qrEfVgjAADEOv4IyM7HmNwjCIN6XgoDhEqoK+ZY1cV8h/bnAtNzoO/35gwhpoksABE JXQweELPJy1MWBc/VCNWzzh5maZp0oK7BD7v87kdZgqwr0TXtOjclsTQNdBmu9VcetzNK8ziZ P5pNICJJo8RVZYvjNrjP8R4fHP0fRPmVwuvRRczrxL+LbGNCGSLgql3O16/v2xBtNi047tzC+ TSKsrjzC3zLa54+g/aEeCUy9NzPesLpzH2rIfWqaUDU4aAcmXzbNIbEYOymq0vyW2A4nAlrW2 xPyy9NTBH73sC/hgK8qwI8/zZ0fOv+/iK9iu0AOVO7NFTd9Tr5wv0QXQTCO8Dnv3p2nk3VKzJ VR2vLpJnP0cpKdOqF2AfNZBYCHcDYHphFtgYPGsf0KKEqMcILi26HdugekY9og+xl4PiKGY54 /6u/sgsn5eMS1iJfA6vCbveJP3jJ/eyEbPvsvLJE5F/eReP7ek= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Wed, 15 Nov 2017 14:46:19 +0100 * Add a jump target so that a call of the function "mutex_unlock" is stored only twice in this function implementation. * Replace four calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- sound/pci/hda/patch_hdmi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index c19c81d230bd..f1c0b6cab90a 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -1205,8 +1205,8 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, pin_idx = hinfo_to_pin_index(codec, hinfo); if (!spec->dyn_pcm_assign) { if (snd_BUG_ON(pin_idx < 0)) { - mutex_unlock(&spec->pcm_lock); - return -EINVAL; + err = -EINVAL; + goto unlock; } } else { /* no pin is assigned to the PCM @@ -1214,16 +1214,13 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, */ if (pin_idx < 0) { err = hdmi_pcm_open_no_pin(hinfo, codec, substream); - mutex_unlock(&spec->pcm_lock); - return err; + goto unlock; } } err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); - if (err < 0) { - mutex_unlock(&spec->pcm_lock); - return err; - } + if (err < 0) + goto unlock; per_cvt = get_cvt(spec, cvt_idx); /* Claim converter */ @@ -1260,8 +1257,8 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, per_cvt->assigned = 0; hinfo->nid = 0; snd_hda_spdif_ctls_unassign(codec, pcm_idx); - mutex_unlock(&spec->pcm_lock); - return -ENODEV; + err = -ENODEV; + goto unlock; } } @@ -1275,6 +1272,10 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); return 0; + +unlock: + mutex_unlock(&spec->pcm_lock); + return err; } /* -- 2.15.0