From patchwork Fri Aug 23 16:21:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775529 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E801898F3 for ; Fri, 23 Aug 2024 16:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430100; cv=none; b=flYNxb2kzBwWgZgmhH3vDMU6z22Z5IcvEeiAd6ZLKfv7xaEtFH6S4D0se5sKutMRKVvh4/sPWXpTi93CbNYKQ+0uCZmbq3K5EcgZO4AmE8f0MrspG7VWGIuxGLG1KBA8d35SqgJcH3uc/ElofbwP3h5ds+ghvhbDs1JENhpalzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430100; c=relaxed/simple; bh=ub/VuVWp0Knj12UIC5h+BDoK62pFjZRxW7gqCbPSQXw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dtrmDSyXl+xYbix0bjfTm5MpJHpqk3dnvmAJXi0TFRtDia6sC2aEzK6MqlYA1S+Hf4OPMeicJB888aGJdqNyr7ezzLRr2do3BzgU3JdRUYMvp70c2tZGhB9cLkjYmOzwQ5mW+C5DVw5vc2Isy9Xh3PAQ/rhZA/Z4yq3S6DClAn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=To0nohPH; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="To0nohPH" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4290075c7e1so2718445e9.0 for ; Fri, 23 Aug 2024 09:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724430097; x=1725034897; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oHlJrjBVePe1SeLSbv4Eko9PRunifYIKIfHjAwXzAIk=; b=To0nohPH+Qk8rub6k8PHhwiRXWkqPpBRe2cd7rr2DeqPZZVMWY74ZPc9HTasRnNRw0 cJzCQqOpGyViPZDQIbt8UxbKymT1ZBJpFjmmVLcNsrdPP32DmyXg31y9xWLFVZmgvrG8 7n3voi5mchQgKBNd3pQ2lmV2JLImrl5voFcWrkW+wZC+lzGneyq/+B/BzBtOkqZW+waA hFWVYeFzB+shEo90WOsagPPkTDP1QhJ+laFFqThxiy+40l4NmzbqdJOfWJlYOf4S5Myh ZkFGzVqI3xDbFwQrw63vxoII3kd/PMXOvwwdpVKECXi5giuZFsZvcVWZx6HbdmCS4fft 7UvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724430097; x=1725034897; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oHlJrjBVePe1SeLSbv4Eko9PRunifYIKIfHjAwXzAIk=; b=eYcL5I98xcYbT8adRHPC54JSgi/8IfSrOIVXICWgMHU+Ulof3pQsdQZh+hsx1ZCZwz DpMv3JWtzRGNB1hl8RRZE8C7xei44pK3SgL37Pe7s/f2HZ4twdZQD3mIIUww/RI96A1m Wa1moUSOxCq3OHU+theVq9ib4YmcfsTfJzqFeFtC9ZOFZcpBN49Gp0Sx6eI5XNUh/hgq AD8MxH0LpO9i+aFP05BWDI6GGM4x5WcozzDwXIlirtTUNkoOXoUi/r8AMFF83UhjpIdp AHak4bDdQjXF3Wigatev7yMhEJX8ct0YHjtCBFc1pTJH75eN4YwNdVT2IGEu1YrRcJbN Le9w== X-Gm-Message-State: AOJu0YyPDSTQ3zhG7tHpnzuShYfhw//qmDFaKmQL7ald1uK8SZ8sXC83 3nRju6cmJMYmAAIwkk2OQE4RJQSWwSnb5DUogjAic2/gRcCwsZKOtakrsDRKa1/7l26bIxw+JXn y X-Google-Smtp-Source: AGHT+IGaAT5CoBTn0zsG4cPP6D+5MC+AXuVqHDCJvSm5Lnq3Y/7n8RDjZ2yyq7jMTQ7u/rOKSqKtzg== X-Received: by 2002:a05:600c:1c9f:b0:426:6ea6:383d with SMTP id 5b1f17b1804b1-42acc8de6bamr12721845e9.2.1724430096759; Fri, 23 Aug 2024 09:21:36 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37308160586sm4499312f8f.58.2024.08.23.09.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:21:36 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 18:21:29 +0200 Subject: [PATCH 1/3] ASoC: codecs: wcd937x: Simplify locking with guard() Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-of-node-asoc-v1-1-2349bd7fb7f4@linaro.org> References: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2368; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=ub/VuVWp0Knj12UIC5h+BDoK62pFjZRxW7gqCbPSQXw=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyLcLG8HQHGINNmHWD3ZNgw/T5pgusG7Ng7fhx L60p4yQ1kyJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsi3CwAKCRDBN2bmhouD 14SwD/wLVdZJmNWBwyt8sE2Me3LkhDATw+Ka38o40SDKTczfAcCnWTxwNEwgcuqCStlwJIIIrtt Y0n0kWFxKDz8Biu+qnlk8lpVzw+mzZfl/2s/5pJIizWM5FapNKd0DD0dx2jg8vXiJQdYuPwkV0C ZZH3VVX5mdhpsQTEL49L6Ubmg9XW47ZIA32/453zaluWgwmAhnDE9/IOpGwy0+MXyBKIWDdEGPJ olB65xGv9DUwDDnY36K50bewU+XFgG8UyAcdSSQ228ZHWNAro1PynjoMStTfu+opTwr2ubIy7un pv50YHu9sFQUV9al49GkR8KveVDqOiF3UEE5pnNM+3QqID+arPUZmAPrA1ANnhw7pwzTO5yy+GH RWj/WVUn9Xl64pEfBMsn7dnCuEKQkW+8vy3cY/x6iEAJ5sEGFmWqqkPbCllpVi+BfN5AyQ3a8EO SSieQSyCvVo7z4vE+KOhQXZcwHy4bvVEiqeiORaDB/lEtS7HceVfIY9OLPmZEcGOB7zWHf8DKzW wYZSbuUrTj8w0gs41PeDYlPW2OyEnR6pG7aIlCn5A/pKW+6JRPhvFOE+/Q4djgkl9NnBTtxCc2/ xJFzHW9bTfxKz9C6sDVtHE1fTrRz60B5Nka0OULrTkiOM7Npi1OKiWz+7fDo/ELa0DODyzyT992 Dq+idLSDsqVX2jw== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling with guard(mutex), which allows to drop local 'ret' variable and to directly return instead of jumping. Signed-off-by: Krzysztof Kozlowski --- sound/soc/codecs/wcd937x.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c index af296b77a723..59d2a5da9854 100644 --- a/sound/soc/codecs/wcd937x.c +++ b/sound/soc/codecs/wcd937x.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. +#include #include #include #include @@ -1440,7 +1441,7 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, int req_volt, int micb_num) { struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); - int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0; + int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en; switch (micb_num) { case MIC_BIAS_1: @@ -1455,7 +1456,9 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, default: return -EINVAL; } - mutex_lock(&wcd937x->micb_lock); + + guard(mutex)(&wcd937x->micb_lock); + /* * If requested micbias voltage is same as current micbias * voltage, then just return. Otherwise, adjust voltage as @@ -1470,15 +1473,11 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, WCD937X_MICB_VOUT_MASK); req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt); - if (req_vout_ctl < 0) { - ret = -EINVAL; - goto exit; - } + if (req_vout_ctl < 0) + return -EINVAL; - if (cur_vout_ctl == req_vout_ctl) { - ret = 0; - goto exit; - } + if (cur_vout_ctl == req_vout_ctl) + return 0; if (micb_en == WCD937X_MICB_ENABLE) snd_soc_component_write_field(component, micb_reg, @@ -1499,9 +1498,8 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, */ usleep_range(2000, 2100); } -exit: - mutex_unlock(&wcd937x->micb_lock); - return ret; + + return 0; } static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component, From patchwork Fri Aug 23 16:21:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775530 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA2C12B6C for ; Fri, 23 Aug 2024 16:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430101; cv=none; b=g4j8FnfaSkWX373hLDnfj8CFCZTapBowwy2kaTwBmyJbsNEZX7Mg1Xh+YOkqlgWbDR+qJeLnnEZBqN0ZevF5qBBoGNi1krPwNO3Ycb7kg6ODCaGJk0d6JJB4Tfe3lrV0QQaoMQlyltzdYYv1hfzeIBGZFqVAiWR9A4rzGnAXnt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430101; c=relaxed/simple; bh=D+zkVBV6t4Pm0wNjj/vCouujptgcyT0JrPLkU/hlsTY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qVXtrkkUib5KItesDKkUOWhqDZJeeJe2hHvb27HSeVjJSSxiqnwppl4ok4DJvceyHn2/3EesYZZICYWKQJ+zuHPIcnJRb8OqbkEoTJkIiu6dB5zi8twRQ41bHqHhvWVbTc952gmUCikVXoKqjLUqJR+8WDe22qKlFLyhEJa7rfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=G/xhRjwQ; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G/xhRjwQ" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-371a939dab9so317567f8f.2 for ; Fri, 23 Aug 2024 09:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724430098; x=1725034898; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=757Xyd4GDjdQ78EeSCWOM/UbvfLrpKBRwkR+ySC2BSM=; b=G/xhRjwQSsdP64MsLFw22P0jbXqrBj0S9RfNXGPMOJPzG3sYH+gAcgqcpXSPH+m8ts Q4gHX5KBzLhfvFxK/JtRskq2UN4vkEle6FHZlxt8fffOfbIpNDQk6XrIq8FU+wGg01JT wrl7fPfreqnF9NSLm2Mx1W33jrZW1QLooNCZErCEzhYsv5eW9PXCbjv73bGwLI0441t0 921otlL/toEbVxMO9roCVKvUZwK/vm01Eref0CTkLdCwq8ODqBg/DL5Mmu8+dfYWO+6Q N8I3Rvi8hGqU225BRI512a7hZcyO3lbW+ZeVRoxHyeos3+lJ6DRaDMBjh+gClFm3P6bz kl3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724430098; x=1725034898; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=757Xyd4GDjdQ78EeSCWOM/UbvfLrpKBRwkR+ySC2BSM=; b=LjroNlBSt2gMDn6BUIp8e2Yok/F5h2yYzPGOpLe+M+ls2Yh798rPEPUhHnTvAY/hs3 HTIXIdr4nsjjtZ4nw63BnNx8xSEOsLhhC3yOHF5iP7aXP3DkZu9+my82GxovfNECGbbe 33fKHNQTUTSxuBwJLg6ikELkNGngGVhmA4KDMLwx2qe/GyH5P8QdhZzFYm7980W76Awo sPs23eG++uFKs9CgbmTGEFEUrJkjZiI5qgmKlVKD+a0JbQoA6oIuZerKrEu1sFvk7pV0 /0gwNJBOSFj35Lndskb439o9HXDUgu2fLBw41UKFp8M6WWzGIVA0l8ihVGU+7DEZ2WHt Ktow== X-Gm-Message-State: AOJu0YwrJsUVAPp/8m0Szev4AtqfQNJLHAlUQpHKBp2P7ZBu7TyuiN3g u4h9hKR+ctEt2zJTC8Ylo49EHvk5VMWD+SON+5QNMWiXCBritqJCG2arSzH8LxM= X-Google-Smtp-Source: AGHT+IE0NOFf0ynPJHje0E7k3ADLffLdWE83krf1vj3Mu8Li7Z+DhEbvkzeo8PhD6s7NgKBsjJ98zw== X-Received: by 2002:a5d:6c6f:0:b0:368:4e31:7735 with SMTP id ffacd0b85a97d-3731191ea94mr1072233f8f.9.1724430098059; Fri, 23 Aug 2024 09:21:38 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37308160586sm4499312f8f.58.2024.08.23.09.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:21:37 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 18:21:30 +0200 Subject: [PATCH 2/3] ASoC: codecs: wcd938x: Simplify locking with guard() Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-of-node-asoc-v1-2-2349bd7fb7f4@linaro.org> References: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2364; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=D+zkVBV6t4Pm0wNjj/vCouujptgcyT0JrPLkU/hlsTY=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyLcMy2WxPO+SbR0y4B04islNvwLxCIeu5PxJV yNMiRTNE7eJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsi3DAAKCRDBN2bmhouD 1xdhD/0X7hEUTG0wwG1W6xxir1GrQopHRjUwgyVXWqIl6xwvtS9kaKBTbZ8nV4ezo+oAazh1UTS kmMG6sfXfxsesXC2lsL1QzagrjMxuTRNCnPKEVSL3PFq9r/dWP0C2aZcNLVeJUQ67TzbzuzFhJy rDqqQwzifcdbFblBI/vUA+WgnpJf/KyDe2aS6ZzBOFpf2hgexebNAW3oH5V3mtkkeOHKT/lE6qu XFu/mLbRmckcDeXWTlDdb4hkhAmoPZtorNUUbEVoOspJWyxDpcKshxnvlKDTaesRrrSkZj/FPe5 sC9jupbWRVD7miOiOloD5cCtesR6PwbKAYupeTKiEgHU6pap7XPeTfFi5gR2Cw7AClwdNQFq1Y/ SfPEfldHG6dWlUZ3xWJDSj/D9Jn3aX2RNTwkH4cVKq8oXtS0WHNN9e3CekBdHrG8X+7GdXwZWDy uYkOA/9dChSqSQFADeDvxI82VYAyN2jrofkv1ZhrmzEQAZn5fDJbXUJ3pSNiGgqq5/VBS6pccIE bYU49OsJ+zwkFWcdfKmFj8/YUDp6lHioXI11VQV3P6i9MCpD5c8Ayy1pBtNMJUDT5296A1hXOlB BYLikkVR8+2Wj6Co4dhzvBlHgKvZ5PUF2U4P4fruW9NUIRv7hJnTraKiszdQScQsri/Ne+nl9bF y92WV/gWLec6dOw== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling with guard(mutex), which allows to drop local 'ret' variable and to directly return instead of jumping. Signed-off-by: Krzysztof Kozlowski --- sound/soc/codecs/wcd938x.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index aa92f1bfc921..15056fc493b7 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. +#include #include #include #include @@ -1992,7 +1993,7 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, int req_volt, int micb_num) { struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); - int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0; + int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en; switch (micb_num) { case MIC_BIAS_1: @@ -2010,7 +2011,9 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, default: return -EINVAL; } - mutex_lock(&wcd938x->micb_lock); + + guard(mutex)(&wcd938x->micb_lock); + /* * If requested micbias voltage is same as current micbias * voltage, then just return. Otherwise, adjust voltage as @@ -2025,15 +2028,11 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, WCD938X_MICB_VOUT_MASK); req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt); - if (req_vout_ctl < 0) { - ret = -EINVAL; - goto exit; - } + if (req_vout_ctl < 0) + return -EINVAL; - if (cur_vout_ctl == req_vout_ctl) { - ret = 0; - goto exit; - } + if (cur_vout_ctl == req_vout_ctl) + return 0; if (micb_en == WCD938X_MICB_ENABLE) snd_soc_component_write_field(component, micb_reg, @@ -2054,9 +2053,8 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, */ usleep_range(2000, 2100); } -exit: - mutex_unlock(&wcd938x->micb_lock); - return ret; + + return 0; } static int wcd938x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component, From patchwork Fri Aug 23 16:21:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775531 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D7B018BB9B for ; Fri, 23 Aug 2024 16:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430102; cv=none; b=Gsaavdtx7dxOv6HUnYsyb0vmmicwob62WUOQ5dzbwF31BAJOMmWAsSg1tBYWifs+ZsACY2eplfDGLpGHu/3NFHU2BsxHSIB0A7B9C4wtWu1c4Wn/h/eeyd77BuolLuiEERSvgBdFbpUMIdzhG5AhhnhSV6+fAWRbRqeauwajg3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724430102; c=relaxed/simple; bh=YMK3zEWCRlOermMUoSe3gCcOKQ0OSZIF1hdfiLQ3/3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=goGgObuHF7HrlBhW3Nnhuzi9+db5HBNiKC3yVMYrBCdiKIcgX/LTQky0HGphMbf1EAVQRk0rN+Ix8am9j5xScjDxcCpWrMtgx+SsDMlvbPyggVQ9zUPrjcrha5OWyrBA+NY4BD16W3jxTurBv4kc9BmtHE4sVQXfNWDxKf7wd44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gLjtB4L1; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gLjtB4L1" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42808a69a93so3683895e9.3 for ; Fri, 23 Aug 2024 09:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724430099; x=1725034899; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xE4AEtOVapV6PoQb9xXwqRdy3tgXiMSO7wO5xbXDvBk=; b=gLjtB4L1f3OUa+jer1S1Ad0TO4S1Y3Adr930FN7zmmyoF/ggE0VHZX+lGO8OMzYNPP fiwxFJoTh/NJeD8UtDwoX5x4wZzaxEyWOoWRszNMCeu5vqmXixpAy4aCW/qVwYa9NvLQ N7XyR9n9HaMZg77DG89OMW+v6IFhJtA26VX2egVEWKJxGhwvS5VDjGd3TtZohMtK9OhX UYO0F+8xDn/Ty9WGVEYRWO3YS8xQXVO0GR+ZO7PnXtmfnZh3yYLIur57Lgb3RoyXPJjs 2lYGH0EQt7w0JGaR5vFOzMY/5B82pQbN3DZ92VlrBOXUfeKlLZY1Y+blxnH/fFfxZCG5 Y5fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724430099; x=1725034899; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xE4AEtOVapV6PoQb9xXwqRdy3tgXiMSO7wO5xbXDvBk=; b=O3P4rNhvkK/KYlwsAQtMP5c2jP8tYMP9uin9jkGzlxL9tBKUJ4eDQAFRys9Wc6/d3J 8YxaDM2RsP07plY21hAcXIPU4sYrKDAnAQBQRQlg6tNPX7sdEtqnF4bLX8UEUrXXKFQP O6pY3aaPItaQNPMojzrd8UlRdZbzYpLAyY39mcJSR/DlKNPuV+u8v5Cf9oPcnWQiCrjW lI9Dtvdh0oaGHJscf8XimXYB+o05wDRVR1wLzwH+CCEokI67zejz263sF3JLf8jUC6Me eBGXImeYZAl6Wa441fWavn8YMFGycQvx0auf38bpcS7//mnYVpklYJ+j2quaYf9hu5Pn YmrA== X-Gm-Message-State: AOJu0YwONvzR2XRRj1C9tZaJuCynNu3jg19Ds5XqctKLCvFEcZJURZsV xfc/V37m4oG2aBxvLOztDwPI3wOd8+wHB+GfEvlBUvneJk4G5+oV56g/lihanWlt9rujHX12TRq G X-Google-Smtp-Source: AGHT+IGFWpXyotIsRADtAGF2Vnlr5VPVsHgGrfTXQwvdzGD3AL/M2ou5aTc2LpMdPeruY+7Thjpqdw== X-Received: by 2002:a05:600c:4445:b0:425:7ac6:96f9 with SMTP id 5b1f17b1804b1-42acc8a55f3mr15708725e9.0.1724430099295; Fri, 23 Aug 2024 09:21:39 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37308160586sm4499312f8f.58.2024.08.23.09.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:21:38 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 18:21:31 +0200 Subject: [PATCH 3/3] ASoC: codecs: wcd939x: Simplify locking with guard() Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-of-node-asoc-v1-3-2349bd7fb7f4@linaro.org> References: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-of-node-asoc-v1-0-2349bd7fb7f4@linaro.org> To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2206; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=YMK3zEWCRlOermMUoSe3gCcOKQ0OSZIF1hdfiLQ3/3s=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyLcMC3oV2jdwkepRh+MjsS/sJo02teK7A0I9+ FPmS5kvoLqJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsi3DAAKCRDBN2bmhouD 1xDgD/9h+NlLbLIyay5J6kOJi5zvny6MWxMj8Cly/6STHvdMPumrujp69rx0qNuuGIGJ8Tq0E3k +SsIsMKiY8MVTc0LZznq1PN6rRVdZL/cEYNGUXFqnhnsOiphoY7Qa6XFAO8jMVZHcWd0755F0WX G7B5gI4kCYd4AMBvfHKNybWwgQZdVkxw+YXo0F+mf1ThRk8aMIwFkVgTj5sKkpFphSBScn0euRL Yr4PhHfJP0iF2bAwKHwP0767rqe5xGXR/508PmGOtsKxp/VH/DZAOs31etB+nRns/mIRjdwQ/Jp y6W+x5hbeGXa1yZRGHGJnLVCGJvVyYs+i8o0k//9dLqUBaItS37JaVePZHW5ybcAiHr8YBIpBvl kzW6ACe2HKqN3QBPrrIgaLZDOf06YzunRQC7XmaaQUg569GGBtQeiUliqsrLmsLlP6iUanAXN51 NAwCFbLLAAw2n8IgqnPXRQCBuy66e6jJwRFaW+A5UFtT46pNOOxtNAvyJaUG+js/X+dJMExOUXT EW9KesBY0CKrk3M5dsRje5drrMbGzKGeord0krGu/kebQ0LP6fss4uGRkLtgWNkBiATpQqsAT/l jVAwMvA9nHfzmrtZVl2iFJwwxwvEEDxld0u18nLUKgSoEOlgXeMySYFPrYZ0Z/sOD8tTeRKx63x dMmIU0+hq5pCulA== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling with guard(mutex), which allows to drop local 'ret' variable and to directly return instead of jumping. Signed-off-by: Krzysztof Kozlowski --- sound/soc/codecs/wcd939x.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c index 68fc591670dc..a77e4b8b3931 100644 --- a/sound/soc/codecs/wcd939x.c +++ b/sound/soc/codecs/wcd939x.c @@ -5,6 +5,7 @@ * Copyright (c) 2023, Linaro Limited */ +#include #include #include #include @@ -1933,7 +1934,6 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component); unsigned int micb_reg, cur_vout_ctl, micb_en; int req_vout_ctl; - int ret = 0; switch (micb_num) { case MIC_BIAS_1: @@ -1951,7 +1951,8 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, default: return -EINVAL; } - mutex_lock(&wcd939x->micb_lock); + + guard(mutex)(&wcd939x->micb_lock); /* * If requested micbias voltage is same as current micbias @@ -1967,15 +1968,11 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, WCD939X_MICB_VOUT_CTL); req_vout_ctl = wcd939x_get_micb_vout_ctl_val(req_volt); - if (req_vout_ctl < 0) { - ret = req_vout_ctl; - goto exit; - } + if (req_vout_ctl < 0) + return req_vout_ctl; - if (cur_vout_ctl == req_vout_ctl) { - ret = 0; - goto exit; - } + if (cur_vout_ctl == req_vout_ctl) + return 0; dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n", __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl), @@ -2000,9 +1997,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, usleep_range(2000, 2100); } -exit: - mutex_unlock(&wcd939x->micb_lock); - return ret; + return 0; } static int wcd939x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,