From patchwork Mon Dec 9 12:00:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899416 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 265761EB2E for ; Mon, 9 Dec 2024 12:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745645; cv=none; b=fkaJYbTzXoLyzRwrFVDUnxtVkuHXvsxABf5PwpGGavsJGyGVzrf/72uIVFj+S0+j+xdmtRwCkmjkNMs3Ask5OoNGbrRUJl49rw1p+I7YFlpMSGBCw8dI2BcZLaCfJ6IhSrHL1NAOEs5qkpoyk2sGbP01jSg/9QofFmdtZEeJ5rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745645; c=relaxed/simple; bh=AfvDk3kCBindu1M/SPA1g+/8ocBf4bQNvfgLlw3/usE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qeMcB7/11kRr6QoUvCzrk1IqzeGGCGZslrzyyROUH/yqLn38h9OHW5Dl3vxa7gJiL5WLMRXpyCI5VMl+ELyM26KJiLGOmMXJ8vQbVAvKGg7csC4SsimTl6QvK08st2+tHcj9JLber6QOh4/59uGy0jxzd20HINURdo7GpwztQfg= 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=Ee0eaGBH; arc=none smtp.client-ip=209.85.218.42 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="Ee0eaGBH" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-aa659775dd5so21673666b.0 for ; Mon, 09 Dec 2024 04:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745641; x=1734350441; 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=EglX5AVeuOK1iJau5AtpYy/rgxr+Cdktyzw1epur3aY=; b=Ee0eaGBHKL2LSQknTU0PLicajGKmvbA+96cV1pZ1oZUJ96ok9gik74+kUB444bCpBp JsuSjSHu10T/xFO64cttn4v8MdGbjzxZkRS2dvTgUSTGR4phH88cg6jl968wlO+R5EVR 0YPJ8CvvgkSLEK68JJfNGt65QC9Xo2Dj5ZG+06VF2GDK1FCNENo/GxehBjuZLq0NaJv/ /9CAtrIvVEgu5aLgp65OA3WJjSFCiiVljoCUYrpKhFJFqNAfZtsCuED5P27n4gjTHEPC LVtUjnR3mBsdjj9+RjjhxHvilCYPsELlDDSTCVoTcDhKYk231g7K+mJkpSxceWsAjlBH +Zdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745641; x=1734350441; 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=EglX5AVeuOK1iJau5AtpYy/rgxr+Cdktyzw1epur3aY=; b=ROljI8du9ejFV/0miJDiAPc++fJU/K96P9VLb8Zb7KO17vJ45QacNs0xENU+6kmbrM NSusWXiWEf/4wCIiRwlZsJQ7yjScORX1l7pTkdoG0W0YxXhM2tlYrdPu1/NLY8BtpUVC 9869Uh09jhbE1rNyxZwiQP7+pmOxTj4z0X/CXiujgP2lI1qqyOxiLawW/dY0fWIIdKqA 1jVFKwNGUHFbxxJRU0SqhyxFaVJW86+8K/BHhAoCVPIOOjpxKFoBhDmmTPSAnN/xcZeG NWyB81AzeoXLVEG4grym0ShuNV/VyGMDtN9PHtC5VANM6xKGNtaKDNvUO9QJehIfKIK/ xdzw== X-Gm-Message-State: AOJu0YxeSZeDXj1EIOW+Qr+ON/XhJhXWF/zFu3s0vSka6Xctiivl+pr7 3KJoCUepih/ekZw7/Qpszvp9c9YXLWBH/eOc4pDM4FfLPSyYNLH9Dt0cWxeF7tA= X-Gm-Gg: ASbGncuVLwdIZYeJ2AbCvZ49T/jv8QSHVu3INCRUTSBB/GxM6/9CaV8WP4SOz6TmYAI Sa34lWScqXuDDZz+klfxRC9UC+aoLwYkGF0RkhSGs5cCYX3VeaN2ZRjPlFUt1Y2R7kf/RbY3DOS VNxNZBKQtjlA2NuJbApIYAA0ZLUB3cRaMltuwWm4gEv7BoIrLDGvKEtKw+E/lci0gmUhl+s4Zsz MjVkxixkO4WRYU2QFOF+woOkgeqNtPd1yNkCGK99fQWS7QZaCzc1IeUhevmowy11Q== X-Google-Smtp-Source: AGHT+IFQz+sHrhTNPQ93WvH87tO0/6WQElPlihSk/tcyEOGbqPjda/XE16U0+c3VXKI1+eO+KbJDyg== X-Received: by 2002:a17:907:3d94:b0:aa6:227b:d821 with SMTP id a640c23a62f3a-aa63a2d24aamr502007866b.11.1733745641516; Mon, 09 Dec 2024 04:00:41 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6260e33f7sm678589466b.183.2024.12.09.04.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 04:00:40 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 13:00:28 +0100 Subject: [PATCH RESEND 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: <20241209-cleanup-h-guard-of-node-asoc-v1-1-397f6385e4a5@linaro.org> References: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@linaro.org> In-Reply-To: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2424; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=AfvDk3kCBindu1M/SPA1g+/8ocBf4bQNvfgLlw3/usE=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVtvkzZBmR2PooyNA+BCY/u9Ie6qgnsWOoxo8u nYzUrYVz2KJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1bb5AAKCRDBN2bmhouD 1/jKD/9auacR6d7c3PeOsT6ExgOSLR4E+xafo5iH+maYepzSK5CNhhvW3w7W9V++wZGcsc21l1z wS7cYpCttuCmJQ8WDsax4eAqMbWdeAiOCFDZzYT+Rgp/Us0MF6NvNKSU2hY8tUY65lQstuQ3/gc NxU0Q45edcfd0I4uLUA53ZRWJli3Ri38KL3ObIrGZJqDShx5HAjM/MuCaEsrygz8Hfo9lyVhkmZ igte+tL41Bl7obatzr+jT0ThA5rAvW83m416HxWb+piBcHdt3MSN6pJKX7sMdSWhv9IkqIoK9ms w4mQ20MTawpUtAoN5ShFqzwXHfb/Qvfo/RYMowybn7Yd3fFZCxSTz2xAYOEfEomOl0sH1QDPxDl 8xIc+AJc/+10C50ddXjOIv7jcUsI/Rl/UoLPYIha+9LJ0zl99VD0MEZFionnUqLLZ+zKFnMTDKV CunkAkdAa+5xgFXSr12fmWqHVp+3huwnLOOEljxC9z3CuCxKBXS4C00XxLFs5VI6JWSCooVtJyM yFw/FvUsokT2B84vtmNZto2gGY5afBAdkTNfKAm1LEGy6FORBKiTr3Ovbl/HPoZx/GECNdoAeXh v6GTQjBvR/6viVRSroKgL50NfCeJKLX5bxXAubJc7A65VQN+C/+HBYffLY+GL+578hX8MxACRyw 4hCy4RLMEUaaz7A== 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 c9d5e67bf66e4e8e21a76cfd563c75bac6555513..7d8f995d2daff50708e361fa446b52898c0faa81 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 @@ -1445,7 +1446,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: @@ -1460,7 +1461,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 @@ -1475,15 +1478,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, @@ -1504,9 +1503,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 Mon Dec 9 12:00: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: 13899417 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.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 B7D4721B91F for ; Mon, 9 Dec 2024 12:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745646; cv=none; b=sRieG7QX5yVL84QgMdPPHvAKEaUqsj4Y6qH6l1WFrnp+rq1zwMZTcoITKy/b0LuccoQ7rkYjI+FnKcA2sXnNLNTZNw5fBKltI+fngDX0Y+iBO+26lepguvomev2brhnDaVJaNINlL7jRhmW2WJUw74zHEffhkyf8kT1NPM9WMU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745646; c=relaxed/simple; bh=9sRQt+fEILRzDTNPp4NsJSUXPScp1R8Q7XAPeUZ+iqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t9zRYVOi1J85SEgeD5Omb+Kh3Z1AMHmE4wxlEXFDA9GLpItcmVMOq8iuV41xrshJAGKn+KejJ3SdrAjSCAo6lj0DTMP1daNrR/SL1qQ+wSUFNN7pKsOOnGMx/4ntlHhuxQYF6ELG2g7BKiQXPTBingDEq+fQ6kDY/tsA+AOz2ZI= 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=K4KQCnq/; arc=none smtp.client-ip=209.85.218.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="K4KQCnq/" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-aa69599b4b0so8204666b.3 for ; Mon, 09 Dec 2024 04:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745643; x=1734350443; 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=dvMgTCziUbKV8Sn4Rfvx0RhbjGii00C0EWsPPIrd18s=; b=K4KQCnq/hfqhtgHsnUP45TFxjl2Bri2zKrTzaXOtWDFYlpRSEmL4C8iM4FUUQPeuRj is+3ndJO1cM96gBPSQkghKYGv4exQwWzk7ZcfPr818shHKEGAOCwm7nxsr3/63DKy1Ao P7RT4tKVa/gyp7FUiwR+fEEX2djEMJOsGnhG4JHnpy9iV22dl/pCuCSANHfceOLW0+Ga dpEq72O8GmixvniS8lXFWcOWhauj3YCD/tybXPSt6/wZdq5NcgyizNx9/GCkK+Y1qnX2 +00Ol30jq8lBDW7wo6V9CnyarG0jHjUNKrAmvsRe7gi9T8C6O9IGuULIvOfl0ZBiQkVy LrGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745643; x=1734350443; 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=dvMgTCziUbKV8Sn4Rfvx0RhbjGii00C0EWsPPIrd18s=; b=l2PklGkogicN625k4NDLwSQ7H6j+u9kfkXcClcYXldeXETBFeNcT9Pf1SzjKie/v49 WNp4itISATnxtm0Mh1gX8y1n2LwpfkhuRmloUprY4S+JILbHhAFUvXiqgT1bj37cGClf gPkA8erCQryy8zrWdtzzt2y0wqbW8W5mlD7KqEj8wFLYBdK+l2UzqwOjpiPW4Q7cK62u Jbu8jIFt6QYfeEcxiRqPYtsbn6/0dnLPSwljSQ1Xyn6S+D8PJD8PAbOZUzgFhXeL0qio KGJySZZDp6trjX552YxstuP5FbxdADJoDJN0FyB0fsXEgo9fZtqm/byuohtIRXZ2jt9A 4aBA== X-Gm-Message-State: AOJu0YwtvA9M/BeCuI34Z6dJ0+B8xi4CTOdI8cTVR/J0kC+o19xwuN1J 8Fa0huwPCqDbDe8cr3DwXWH1ZZXRR8IEi8xIi+QCENWriU458mbh22ZawLwS6oE= X-Gm-Gg: ASbGncukGaTczCjqdHVEEkqRHZzCKFwt3NJSsKjAM5EsXo3F50jaYLdvfWDoIfN82wz Wafrx2Ay6CTVxziebMIuqDt91KH0dh9uzAYHnmKC5+3dzmcDtv2PR7BwlNcYhOgr21o9JqXhwuB Hgn7NFWI2BdkBFEY1rDVlB4zaTJPHUiiIePFjX1xGxj6TEOHRBpMM2IMPrSgWZNseQ+IdGrf8ig CDi9b+0PMQRw4gYHGvYdB+XhTmt5QJns1np9B4Dc13aF+8Hnrz2q394bu9wx369zQ== X-Google-Smtp-Source: AGHT+IEqH1oaArwnV6wNm6opfU9J8wUrT7nB0JecmzXsIpT8ziyNbaP+FOzBH6K4aWnkqgODWjFUnA== X-Received: by 2002:a17:907:3e1d:b0:aa5:3e81:5abc with SMTP id a640c23a62f3a-aa63a025e12mr529837266b.1.1733745642780; Mon, 09 Dec 2024 04:00:42 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6260e33f7sm678589466b.183.2024.12.09.04.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 04:00:42 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 13:00:29 +0100 Subject: [PATCH RESEND 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: <20241209-cleanup-h-guard-of-node-asoc-v1-2-397f6385e4a5@linaro.org> References: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@linaro.org> In-Reply-To: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2420; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=9sRQt+fEILRzDTNPp4NsJSUXPScp1R8Q7XAPeUZ+iqY=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVtvlv9laKURklc50GyvU7ApINZFdb6iPHFHM3 IGn+qUM5uuJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1bb5QAKCRDBN2bmhouD 10g5D/0WnXxailydX0vc5hIzAjuDVC2J93gYT7B3iaw0AD+lI0E1RdPIuu/k+tW7vMfUimqH4LY ZEAaes7CDLoN/zcjv6/1Jogl5pDfoYarlXyV3GqPxNa+/e9TNohSr5FVXl6g5jwLppL7mfjGY4p DRuwO/LMFQ/7gVGHRfveij54gk0HHmnnOjTVjdnJsxfoMqf75Awh0HvG70Br3c9v60eTzMaxaoq 3M/vgtmG580MYG56wpD61wpkNTrmXkpkedLv6W9Cv2LgJ2R13sVJlXXW4Lc5meMyTq/nqmK9BLt Bw9tPTv11txl8pRAa//pWM5z51A13bsnxvKGG80OrKeHJg7xvYzzmLzDKPND2UJILjUGnwN72TC s3GGfjvrdov8rxt7sHD6i59rYxEKadqyq/3pbUYscKQAzQX1nIybw3z1P6tqn2W+5zcmeq6EwQD QllkjqAGpT7jEBvjlhuAGflmBNglf3bSN9vkh6NoKZP5oCESFlUc4izbuZAqTacSbHSXcpFP78F OcLiB7dgp6KNAlxJaLhatv7fqDDUMr9Igc/G/4Nuum1400zcTX7acUTEmMfJbCdOToiO9V94z3R Ni41kLDvmSZ5BoKyM/VjpM0Gpymve8uVNPQa/GRDRu4WpaU39vPRlXQMJkSooZ20onVswGC+vcy 8oIzSBX2cCtVVgQ== 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 f2a4f3262bdbc5f828628464bba9ae07ef99af56..0c1377eee5697f79b5075a29190c39d5195da65a 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 Mon Dec 9 12:00: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: 13899418 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 BF29E221DB6 for ; Mon, 9 Dec 2024 12:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745647; cv=none; b=b2Ig6vcZ8B87HmPOFrgeTx1mXyvnEnBfvDnu9v9iXOzp4CYInK5VlgSTaXUryB7PhL63OqyGJmevwOts1OxJuGKNwldERWGEt9tWTbLdn2irj7IdJG/5up+epv4kTNImH61G13X8CUOPiLc7k8hDJWXf4+qmbFOkCCHi0efNOnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745647; c=relaxed/simple; bh=WhShiMoI5qZyDrMImdB/9FQDtPm2fCJn5q8eADeJPtU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bR+urQQWQ93HZDzWmwHAWd0isRNB3w+7BD7SmDRswQhy3+U0+l4HyJ2p+1gViw6QvuREk+MJy4HLF8OpHq6ZjiY/SCRuPSzt42vsPHob8e2JmKEVJsSqIdkuK2DABimLgCs99G6VpfpiqrBf3Rcpe8XmwaH/Y2j5TcfkcFjixJU= 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=byMKvySA; arc=none smtp.client-ip=209.85.218.50 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="byMKvySA" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aa6647a7556so35244666b.2 for ; Mon, 09 Dec 2024 04:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745644; x=1734350444; 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=KEzv543yTtonY0OGrBiwa/9yBGOxRrOVZoppfjxzgLQ=; b=byMKvySA5jwnEWoNEH3m1d1Hz4cd80wtwZ8mUVFtpZojMaRuqp6tPHWYb8Eg9BmgxS ItzeVqWAVTaoe2ZtlU2j/8Yl8raz7XrdxnYJKJLhAEFN6wWZIE8nShx89bW3OI2KynkF OTSeYcPBdkAs+z6Tgk87a231Ur1HGWewqHBV5JYJ8fClAaOfgVZVEDJ2k2xq8mO93k3X c0EmdFWV5QNaZMvWoSVNEwxYY1dzIjn8KUe5W9PffSC8JZfu4+qZMlU3e18smwzyeX+b vx3jD1euXGvwqfBhP5pa9mV5PIUe1PNwuhHrn0Trk+A2723igCcWhhH17QjMwfX38Bpl HA7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745644; x=1734350444; 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=KEzv543yTtonY0OGrBiwa/9yBGOxRrOVZoppfjxzgLQ=; b=fYHW7V1vjaIK4D2BCeH4UJGeBs8Abd6+ktfbhz3VysMiAMFB3VdK2XkBajpXwu6ms0 9Uf4OMwZRQNJyrF252PPy0X9c/iAfdQM531m5M9IafxzU8Xv5sXS5P9OSlfQfFo8AbHY lLmHr3FZPAmUJ8w3z8zRBDZfoWWRD9tslOYAN2suNTkuzcp5pLU4mxc+tRQiV8r0s7jy wE28R4Q75i+vs+iOXaP3yDxgyCUOVqVvomw+O090z/ByAWamMvW6Kp/bqYOSH1JggxIw ELl71kL6WmQRXUVdbNAQgMRg/kCJb6l+dkmGIXL1cpKC0HT2ih6vHXbqHh3F5jG5ey7A jFcw== X-Gm-Message-State: AOJu0YyJmTrDSO5YkxJzcsu4ckV5qLHy26riKH2xptQvLazy2TE/o286 PLwEp9nfYRcsG1WTEHqaQW6ya3yLjeo45lzy/lKDMxQTqQVIQ61l4n3t85FBfxssBl4iAk5GDoU Y X-Gm-Gg: ASbGncsDgoYEeX/25NN7swAi9G5fyVifRZpySethTmKPvgNOjBL7LWyr43WYP+Cw+AA iO9RQ+qXkadZKcDFzda3k++9MRe2UvBEL8RXMxYRN+iZdPunPzRTeJ9DFLlohCyhi4nT8Hq0hCE GuVG1Pthj2GAaV2fD9njhXNiBrAVgRPBDGsOd8tfzvQ90n8N+a6dgEn6Us2oI9iCgzJrAkSZaC+ ux5o2+D3glwbUD0seTCsYU8e08+GWoJsdyAk0zxRwlivt9CfPuuc+qQM5cXDKOvAA== X-Google-Smtp-Source: AGHT+IG1yj+lZs+M+jU/dqkLzO2Uzei8FmEuNpnnKZbBTY6w/ukv2TlkWZgSCe1/NeYLa4E5/wbXmg== X-Received: by 2002:a17:907:3e1d:b0:aa5:3e81:5abc with SMTP id a640c23a62f3a-aa63a025e12mr529842066b.1.1733745644042; Mon, 09 Dec 2024 04:00:44 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6260e33f7sm678589466b.183.2024.12.09.04.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 04:00:43 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 13:00:30 +0100 Subject: [PATCH RESEND 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: <20241209-cleanup-h-guard-of-node-asoc-v1-3-397f6385e4a5@linaro.org> References: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@linaro.org> In-Reply-To: <20241209-cleanup-h-guard-of-node-asoc-v1-0-397f6385e4a5@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2262; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=WhShiMoI5qZyDrMImdB/9FQDtPm2fCJn5q8eADeJPtU=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVtvmQJL00sYkjfVvuVgIrhwYEy98tB9QE1roy vhg8xdWNWqJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1bb5gAKCRDBN2bmhouD 10yKD/wO+Ga1nldyhsPmyyCVePuA3JuZQsFtvR5Dy7Y6KiBuc1BdG3OaFaRpScUAgxc2mVyiYri t1vQkt8F2FYF1yQ3HwD+wbi5JWjMDGQ1wxXpTpA9BXjOel9BwyOmy+9uAwkHuUcWKXE72KrVSnC +RCEgy5cQZyzNtGnVGoKbE/eT/JHzQwMmNuBMTn8dO8ZSGl6vwLNYReXVNVt+/9Seww3Vgi78ca WoQlMhR3t3TU/Q5zx9QipW/TyJIF9RXhfmryOTcpRTjaKCFumEg2ft7j+dM6oNlivm2tNs1HCtk BnYPcQMVcaogJULzVxWXMyeQeW9rdFKG57Oa9MTwd25iD2JCpmtzQaAVgjxcIq3RAY9PPl7RNSI aO4jxNPIpuhIylccvDpOQHeFQMq8CqVqDwBzUA47Sn9ezChNH+BcwS9lvQvAz1lxVJ2nRBFY52V BMQqtFRjS69uFdTVx0eCpZWae/7oCIZohv6LOPEjLuLIl+RWIGenXxtg2C0F0l1bKnjGCkxeOMN /wuncNwPA7V7HbRyd1pMiMjiyZy3mS3Cxy8Hu5FKBhj356xlVlrOPDLDCektI/37uREuhQw+9Vy qAXLeqMe5S69U9HiWnAz/HwXJ+lcEx6eaS6lYjDHPD6COrEKs2moL/sNf0nQEHEt1C8sc/aaSkU ZG/LVk62Z5FjWNQ== 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 4a417a92514d7979aab8a7b67c518e9889e12012..e033e153c2e8e663a04957779625b04ac11c7625 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,