From patchwork Fri Aug 23 15:38:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775443 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 1B3FB1898EA for ; Fri, 23 Aug 2024 15:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427536; cv=none; b=eH6O8/DnSM+fbr0mkEzmkOdX8F9THYaw9O0Pw+6wUrSJXshTREvSZaQQQj8H0exoFqr4odtMhxevEqQ62oQwKmdsOffvoDongXlyBs5BGjsF7nMDC31MsDDeJOnUFyQLfiSWe53rhnk7jFdJZT8gpPmcXGMKPOndN7pCt+16CsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427536; c=relaxed/simple; bh=JR9cw74DQSM2eU2zWwaNZZ0xGyZqYuXXOD6ozbehUUQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XeJ3UqP6x1iugKc+musevsY8W6LHumykVKC6V1voUt6WNMdfllrT+7fjWPVhMVWv262ofzuYQIjUcl+m1mOJR8aF6yc3uSv45aDMMsdXnQ91divxXkJJQxsK6bPnkmSfmrucCdHk42sdkAwTts0/4nLTqGDX9vHL9xO6WNBb1w0= 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=H653+rAO; arc=none smtp.client-ip=209.85.218.54 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="H653+rAO" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a868b4d67c6so15270166b.1 for ; Fri, 23 Aug 2024 08:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724427533; x=1725032333; 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=UJs8d7RVfQGekQmLWkZ3l/lci/ql4y2sx5IVAqszbbQ=; b=H653+rAONM9NH05H08lSI7RPuqapvCjRvNLdz3hqHWK64TTTqjYNj7ym2BzCIeEJgz 53ol87XiD4PXelWmqmeDJPvrarqPe80U8qxul+j52nXQdeLlwv6paIi27yp3tqw1FyC7 7lSd0Zr7inDAFZAk15MAsvPNdXhBIe6oQaafYs+ztTaOwQ3DvGGBO9kochf+NGSmGcv6 VKnpBVKvduUPsr93zGzLjOQRtzkqXHE4E4hsWnhHTeyvdT9oYgYLB18MARrfQmUuey6h K9EeALecGbVcPzcPIL908ZcHDRXN9IZeW8G903bPUtZOLYBJY9hCZ+a0PMV2ZU4Nn04E ohsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724427533; x=1725032333; 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=UJs8d7RVfQGekQmLWkZ3l/lci/ql4y2sx5IVAqszbbQ=; b=Plh+GMCaozysrbj7X5q+IkO5HkxYXuTK3Pbxmrr/SGgKWnnA34+zXcZornlpXpPByQ q0pSrkAEBX0FBWj2qmshI5np/pLfsxj/E1lBZYVh5v3DEfN++fccHG1nFvFAjsxR37Ey e5aS8M2JN2XDjD2bPSLXNfHTu+t5byWo/dGKJyS5lkRJyPyIDRfm+VfIII059ynRVFvE CA5Qqzd1tlS1PzsAFF+n/41znnJIcna+mvSWbmeLsrR1wUkNloDBI0ShLVu0uNhRSghS rpEzDyGXNWdlyqt2efme+xgnJTpOb8zuHsLXwd9h4YQ3jg0Mq13FK1xv3pVoNCkcVGKj sjXA== X-Forwarded-Encrypted: i=1; AJvYcCWKcUxLcAImHsqOj1so1EQhEI2c4C2dulItz6MCB5IVvodibuIXYlnvOGbSEVoHrcaHBbkehRKbRtE=@vger.kernel.org X-Gm-Message-State: AOJu0YxYndeTTUA8YuK2uEy26rtLczu/igueexXJTdtZC+w9k73h6hH+ ed8WD6NHPcIRrZZNV5Gj/1/YcZytpIthhpXZxvU7WLLfQsdsOtEMAdKUasSwgsI= X-Google-Smtp-Source: AGHT+IHjrGLfTu2FQGAUVxvGqawL/r9shFFDgxA1PeiSj8myBbgeuoJr5guuoDNtki43GxYl4WmVig== X-Received: by 2002:a17:907:868e:b0:a7a:8378:6253 with SMTP id a640c23a62f3a-a86a5489a52mr122703866b.6.1724427533388; Fri, 23 Aug 2024 08:38:53 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2e6722sm273279866b.91.2024.08.23.08.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 08:38:52 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 17:38:43 +0200 Subject: [PATCH 1/3] clk: qcom: rpm: simplify locking with guard() Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-clk-qcom-v1-1-68bb9601c9dd@linaro.org> References: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@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=2437; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=JR9cw74DQSM2eU2zWwaNZZ0xGyZqYuXXOD6ozbehUUQ=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyK0IQtEkv5hsTH16vg7GMkM80IXzMNmQHSClE WDLx9TYIlyJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsitCAAKCRDBN2bmhouD 17SRD/9O9R3z7jT0K4xXGRf4Jsz0hfvMvbt5+GVp3EGiPy5d6axfBuNX1/OWAgdCHeEvhJKR6MJ ZDoSdUNxevZLbafQmwlTGFTwe0kuT2B+dUM6xB22VUNHTRnWM0iCF6fucU5dDAQjC1yAB/K3oRE lNc/C2u6tFZuMvBv1Fu06h7EtvPDjEfIVbZkkjzPk2HuLlTlXm6z5Cvl/YqYVwR3Ve6GsepflLA LXR5DWR1HOdlhLrXNFB8ErJHxoXhutLCzKoBIu2U+ANBpHyrQ3gvw5D4x9OsxbcFPyydOpKxAuh QnR545gj9b2smdNQM8opOyTZAoQEm57Y82dzLjz0ryYFp2R2xWBlnC7OhzxKaRojS/X0NPvHkNe FeNYdG8I1e+Ejd0ZCP+KSwKSQrlrTYVJ5WB/aWdVz1xP5rt9z65U7MZGc3qMQ5mCRLdcfpFyQoY 23HVbRa+vKX6Hv2oV4d2Gpc5ghplUAKXk1ljmld6u0bplTxVHDbRdDy8NkOXhEtWOqUFQpaFd2G N91KuywF7T3KUJ+VIbKydsoBePBxZmU4RowAN/hyGvBxcVTriseJhul1tJW8X+Z81vhZD+ZaPde 9a/r8CyviB3d+yGZWmhpD7ffzepSuXk0n5Yl+pKTJeeYvPGgVyi6ULTpD9gFZUVApj2FZcGL+pm nryYWEy/6Wqtz1A== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski --- drivers/clk/qcom/clk-rpm.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/clk/qcom/clk-rpm.c b/drivers/clk/qcom/clk-rpm.c index 9da034f8f2ff..ccc112c21667 100644 --- a/drivers/clk/qcom/clk-rpm.c +++ b/drivers/clk/qcom/clk-rpm.c @@ -4,6 +4,7 @@ * Copyright (c) 2014, The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -224,10 +225,10 @@ static void clk_rpm_unprepare(struct clk_hw *hw) unsigned long active_rate, sleep_rate; int ret; - mutex_lock(&rpm_clk_lock); + guard(mutex)(&rpm_clk_lock); if (!r->rate) - goto out; + return; /* Take peer clock's rate into account only if it's enabled. */ if (peer->enabled) @@ -237,17 +238,14 @@ static void clk_rpm_unprepare(struct clk_hw *hw) active_rate = r->branch ? !!peer_rate : peer_rate; ret = clk_rpm_set_rate_active(r, active_rate); if (ret) - goto out; + return; sleep_rate = r->branch ? !!peer_sleep_rate : peer_sleep_rate; ret = clk_rpm_set_rate_sleep(r, sleep_rate); if (ret) - goto out; + return; r->enabled = false; - -out: - mutex_unlock(&rpm_clk_lock); } static int clk_rpm_xo_prepare(struct clk_hw *hw) @@ -324,12 +322,12 @@ static int clk_rpm_set_rate(struct clk_hw *hw, unsigned long active_rate, sleep_rate; unsigned long this_rate = 0, this_sleep_rate = 0; unsigned long peer_rate = 0, peer_sleep_rate = 0; - int ret = 0; + int ret; - mutex_lock(&rpm_clk_lock); + guard(mutex)(&rpm_clk_lock); if (!r->enabled) - goto out; + return 0; to_active_sleep(r, rate, &this_rate, &this_sleep_rate); @@ -341,19 +339,16 @@ static int clk_rpm_set_rate(struct clk_hw *hw, active_rate = max(this_rate, peer_rate); ret = clk_rpm_set_rate_active(r, active_rate); if (ret) - goto out; + return ret; sleep_rate = max(this_sleep_rate, peer_sleep_rate); ret = clk_rpm_set_rate_sleep(r, sleep_rate); if (ret) - goto out; + return ret; r->rate = rate; -out: - mutex_unlock(&rpm_clk_lock); - - return ret; + return 0; } static long clk_rpm_round_rate(struct clk_hw *hw, unsigned long rate, From patchwork Fri Aug 23 15:38:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775444 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 95F58189BBF for ; Fri, 23 Aug 2024 15:38:56 +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=1724427538; cv=none; b=YjsCie45oyAmI/uhNQkIfGCxqyEk91dAvp2VhjCyPRpUFWO/Yum/m0rXzpU46pRjIgGN2rhPxtIsqfzrK7RE2I1IgtS6OeEeyJstby3AV315DjlDh7MFr67mKrMDJYAlNQdOYdQs0zG9FOpQsrrEXDzNVqsRLwEphw3oy1WEZhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427538; c=relaxed/simple; bh=evdq8Yt94WWw4pg1Boz8p0xNjQ+kk++pcNlC3Frqugo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q4CW1IzxM1sAguJ12AxBeHz8h/tIMGxFfjPyRCyVQ4WRaByRKVSjvLhl9HrwU2DIjLGEqWpS8OPdD/G4i/gM8hr0kLZRUihYrldgFs20It3PzDtCu2omuyQTgVOPcl0PNmicDy05cxb3dsMEVRI+lNGm/9kgRrJHxow+ojuCfHQ= 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=ObZHnFX2; 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="ObZHnFX2" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a86939e9d7cso17003366b.2 for ; Fri, 23 Aug 2024 08:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724427535; x=1725032335; 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=aTYXi4axMl8Q+ASzCGhkA8CZYY+O5erF5dL8M2uXh4I=; b=ObZHnFX2cXQwb1Jzat8NcyevEZ8kT3SLFR0/p9pRb9C+LA3foupCaRFqMWaakrKSZq T43421K1fR2Ti4bgQfwzRiLRtfz57fNtyAvNcmb/u2tsYrey0K61ZqmUiNpmGJpRi0kc tsqGXOSAu2E5do9KvW1FIduKeZZpCzf0BHwt6Bub0LESvg8XQdVttea1h/JL+upKZEO+ +BzYOTzVNuxML5FW04a+xxHV6XHIFNrJSq1sKoOG9Yo0dRzLbrWHK+HGqq5VN+la7/5N QIXePr6FN4mwKd2Hq8UfF6OWTWCBcFOAdrTaGjG8Bt7vFLoNVgPd6qoiujwFQZNoa/0c Jc9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724427535; x=1725032335; 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=aTYXi4axMl8Q+ASzCGhkA8CZYY+O5erF5dL8M2uXh4I=; b=MX/XqY55jGA9+fi3qT0KXzC+pF/DPfUCgnlbjed9rjsBs8i1+sK2n84TWCV16J9jM7 mfiMorExziua8+PiCDe1pPcu5kxrBJZFKyg9WMgT1zFpBUBEGH844fRr0BmweoFNYHN0 AkwWkk5JliH3A4bP4KTh/FWceKxI7K3RbKlHDh7jwp9a++K00nDytZXaexcd2BtLTvuK c+PTEd4NhFeZKBrnwUseBuyqwN+3xNm3I3vHfgnfQQrYCTcboLnEPI4GMTsXF2AkP73k 2j4tvpMbulypyLd+2d8V9/4DUdVrG1WavYonu1TnUyO8nM2BoCTY/bGsDWRauJugh09v Ob/w== X-Forwarded-Encrypted: i=1; AJvYcCVEG30MWcmT+ymYfie0LEZN9yXyhUYUFWcfNmAJF2/WI73DGEsFVC5SlK6E8z0j60D2MTDuis88oOc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/p4k2xeafObEiWGgH/jGQf83HcFVsmtRKJDwNe/KB04umq6L9 TeSMVbPapIchJYCIFUGL8jyFzob5T+QCA/JeU9zX6INA2h3vDGJIxPRQ4A1LO6qNQW2DAX7Yhvc g X-Google-Smtp-Source: AGHT+IE3hEHSz2qFa4m7gjtHBOUfNOEt1yU0j6abrhEBU9YNRc92xmhZn0idm+jCJ4fUR8136/gHhA== X-Received: by 2002:a17:907:868e:b0:a7a:9d1e:3b28 with SMTP id a640c23a62f3a-a86a54d3d34mr128491466b.5.1724427534954; Fri, 23 Aug 2024 08:38:54 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2e6722sm273279866b.91.2024.08.23.08.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 08:38:54 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 17:38:44 +0200 Subject: [PATCH 2/3] clk: qcom: smd-rpm: simplify locking with guard() Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-clk-qcom-v1-2-68bb9601c9dd@linaro.org> References: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@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=2470; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=evdq8Yt94WWw4pg1Boz8p0xNjQ+kk++pcNlC3Frqugo=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyK0J87EiZDIfKLdvqTZgG0+FpbtH0S1vt1+oK Q6V3cbvtn2JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsitCQAKCRDBN2bmhouD 13PJD/4t3HRMv3eRBZKlsqv6qvMVSdJM36Smg2aWIT+lQi6G+TgLoAvWJYAS3O3I7IhM5jRb1vn 4FXwIGY49hUowR6vxVCBka3ZoIMl86cm8NU38sxdS7hjZ1v7KFUX60qAqH/np/m/yGwjXL4iZqy 8ic8pCqJUDIK30u+MqG3GJwnm2ESLC2ax3LG9TP26qTZjOIdiRGWlk3YqNSHJBula2bVZ8ajh7/ 53Y54Y8RHiklMhvJIExLv+rmTtu6UYqN8kVajlyGC2QEs9xc/65x9hZIciqSZexssPTvU2Lhglq ObAkyez9zzRvqc6mmuoULEBzkswkMecQ/i179eB6Z0fgpNSvpDeBNm4OTaU6CaOV9n1/J+oZmt5 i9RL49B3ak19zASQ0RcJ+GpNZK02/xsrB5KfrBcCv/p99XAQgVat6SwaQag95J2KXDbSXf35TTO kjSKTJ+F7SLfOm4cXbUf+pCDaffuSEia2+/lcbkWHitW4bbG/jmHRXYZmD+qalq5STu3OlBkFrn fC0C37NmamYhrPpBwb2BXQ7z7UniSV7NMcx8tXVx6tb/YG92xi/HsDCaQMZML8UiEgNoZyBNyAS hquijbXGr8xeZU/dnieQW1SJjtVF4bn3swMVtW04qkaVIWOHhEDNJdAVcHwOYl0JYX5B3yjKtrv NZY0cQ9hKgw0B1A== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski --- drivers/clk/qcom/clk-smd-rpm.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/clk/qcom/clk-smd-rpm.c b/drivers/clk/qcom/clk-smd-rpm.c index 45c5255bcd11..b8cd9f730119 100644 --- a/drivers/clk/qcom/clk-smd-rpm.c +++ b/drivers/clk/qcom/clk-smd-rpm.c @@ -4,6 +4,7 @@ * Copyright (c) 2014, The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -309,10 +310,10 @@ static void clk_smd_rpm_unprepare(struct clk_hw *hw) unsigned long active_rate, sleep_rate; int ret; - mutex_lock(&rpm_smd_clk_lock); + guard(mutex)(&rpm_smd_clk_lock); if (!r->rate) - goto out; + return; /* Take peer clock's rate into account only if it's enabled. */ if (peer->enabled) @@ -322,17 +323,14 @@ static void clk_smd_rpm_unprepare(struct clk_hw *hw) active_rate = r->branch ? !!peer_rate : peer_rate; ret = clk_smd_rpm_set_rate_active(r, active_rate); if (ret) - goto out; + return; sleep_rate = r->branch ? !!peer_sleep_rate : peer_sleep_rate; ret = clk_smd_rpm_set_rate_sleep(r, sleep_rate); if (ret) - goto out; + return; r->enabled = false; - -out: - mutex_unlock(&rpm_smd_clk_lock); } static int clk_smd_rpm_set_rate(struct clk_hw *hw, unsigned long rate, @@ -345,10 +343,10 @@ static int clk_smd_rpm_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long peer_rate = 0, peer_sleep_rate = 0; int ret = 0; - mutex_lock(&rpm_smd_clk_lock); + guard(mutex)(&rpm_smd_clk_lock); if (!r->enabled) - goto out; + return 0; to_active_sleep(r, rate, &this_rate, &this_sleep_rate); @@ -360,19 +358,16 @@ static int clk_smd_rpm_set_rate(struct clk_hw *hw, unsigned long rate, active_rate = max(this_rate, peer_rate); ret = clk_smd_rpm_set_rate_active(r, active_rate); if (ret) - goto out; + return ret; sleep_rate = max(this_sleep_rate, peer_sleep_rate); ret = clk_smd_rpm_set_rate_sleep(r, sleep_rate); if (ret) - goto out; + return ret; r->rate = rate; -out: - mutex_unlock(&rpm_smd_clk_lock); - - return ret; + return 0; } static long clk_smd_rpm_round_rate(struct clk_hw *hw, unsigned long rate, From patchwork Fri Aug 23 15:38:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13775445 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 66A7C18E346 for ; Fri, 23 Aug 2024 15:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427540; cv=none; b=fUFer4Vd0ZNGIruLhCuNIUIpctBgwwlLhGciN3e8y3o5mlHm0x/hbX0BJz5UzSCi8F79q6PlImKlbgBpEDmvvLYKZBSwTs3m2pzkrn+uXVsp/zOMJKYeVLK0aEOof+tGgDIpYTesjBpiw3s6H2Ce+WTi9wZykZ6LoqHlRRJ02uU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427540; c=relaxed/simple; bh=l7a7u0My53bkxxah+iS3TThVKBAYiSLyEhlPU4rJbTg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EkCmPdbn9VXXVpegAMCvIHLTZtF4gHD4FTrejl/t+sugr8KxwxO7r8RuqHufxxTJ2U02xmjsA1IuyfvY+UUqyhwZjEQcclDLFMkTei+te0l4a5J0PkNCqpsx/ZpflcjGxpEc5/fRIN7Y3kNytcSMLYLUWZ9X5Y1ebmBCYhmxt28= 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=tjnAJi5+; arc=none smtp.client-ip=209.85.208.174 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="tjnAJi5+" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f4020d2c65so4242231fa.1 for ; Fri, 23 Aug 2024 08:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724427536; x=1725032336; 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=fy0emVGM/pZ3IFD6JVSFNjd9kWRX/zwsWuupwTClnF4=; b=tjnAJi5+zyTXNKSD/NDeZf99d7kVL60aPzEiX3GhNY7OuQz3rFi7JBLZUODCbgGG2x j1zLgqJ0cbgurO30k+a327ybvvQN6TI9YwUShrEUTKP3BNxfSRseImyxZeJUyKhziMSp SCY20U5vKZPzsvR4t9+WuO3Z1ELFEC9fWcY823aPate08OfT3zOWLHZjllcDN8fI7o7Z ixxyE9HAXzSOzureTsBiL6yls9WAnIoar0SJjua6IG+P/aI/434LzSYx7AM/UXsG1E16 PBpde/NfxygoVEaqYqcM6JHpQTlSLkx9LrKvpEDqImKI52aj/a7Pvl1iZ3ci85AMaj5h i7Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724427536; x=1725032336; 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=fy0emVGM/pZ3IFD6JVSFNjd9kWRX/zwsWuupwTClnF4=; b=I9ej3zw2sYdO7V9fOjoWWdCXmc30mOFoepzbuNwvQHeHxFVqN8iuqK78qRYDTH0Ddn lizOE2jRd3EnN9NbEVeaerecAbXtYXxNM3nFqlC3pTHqCL5LuiKRngfr7h4c3c8rPFoD yylbgDb6LsbiVqqzp3oQufWB2RZVkkBws0wXas05c2qkunYjJTqo86ItongJrVHD3P5U 2ndXbZKeZQ/b+OHfd2T3PMxMDjS+geid9YPfVNlXhwZfzle9/Bpue6KdCi3t050LK/bW s3vJDHUFjkjCabMCKxr/SRh4UdwALNn/ajZJ4PP7urXYFBC5GVicJdP52SbkDDjUCQIi Jk7Q== X-Forwarded-Encrypted: i=1; AJvYcCW9gX1RRwDHN5eryM5ddgN7SJXE7mrkNI6/RS/ydbIlpfcVQ1csRJq53g/ezEJ68Eu9eW85ZpNJ3HE=@vger.kernel.org X-Gm-Message-State: AOJu0YyzLFFVtqYc/iPK8WhZPfzHiJGbIE/yKK95AcvJJrYGI+07pER7 HYF27qTBPtOsFsaLmioO9fK8k73eP32AqBRTRmApXmFMxvc5YeM1ZLVAANAy86s= X-Google-Smtp-Source: AGHT+IH95pyx++0+x6r3b0ylOn5qoAmOpJPJk+X3WWJ82zLdKPCwrw5O0zep2cGh4t1vgStIsiNa/Q== X-Received: by 2002:a2e:a592:0:b0:2f0:23f7:8e6d with SMTP id 38308e7fff4ca-2f4f49493a5mr10725521fa.8.1724427536341; Fri, 23 Aug 2024 08:38:56 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2e6722sm273279866b.91.2024.08.23.08.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 08:38:55 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 17:38:45 +0200 Subject: [PATCH 3/3] clk: qcom: spmi-pmic-div: simplify locking with guard() Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-cleanup-h-guard-clk-qcom-v1-3-68bb9601c9dd@linaro.org> References: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> In-Reply-To: <20240823-cleanup-h-guard-clk-qcom-v1-0-68bb9601c9dd@linaro.org> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@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=1550; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=l7a7u0My53bkxxah+iS3TThVKBAYiSLyEhlPU4rJbTg=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyK0JqhID/6P4SXswjPo5SrAFWoJ/fFS0z1WoT bdQrdHJG+CJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZsitCQAKCRDBN2bmhouD 1+EuD/sFCwblV55kzx2hxQvstFtApCUTcYo7f42fCjD5l/BlJb/gmQs1rc5c8lhykaYCYv0dJMu pcoYJGTCSWVGNYyQdMA6sdCopvePTiV9LcQlUFHgWhel6fVE1hjMw7b/1qOvRy8jZHLyStfHAuD 6yOZUj5sxiWoIdd5OBhfLR5L3f/bIQAhmXipjFyRP5+XBTs2i0FE0H3QjCMEQWlbiGWXrMyoir7 yxy3TVMm8qCxa1Gn46X+DBJFaWv8NPZqeoYw6H7uiUsygC0DmEg87QhfM9LfrwRSPN7A9GTmlYX 4ZTsHKChnvRjR8s7q41QRbvTTg2oocdQAKEkmpzhn/Glwi5BhIUaYcWFTCeamFjoYKPgva5hwX/ ypR5jLmfq3z5TwuVQrU/9lMKJjDCc2rHFamBXKPdUHEtcbl1DSOajkOkD4HRfg2UxE4hgz5jMtu aybAFGTCMe8LELrE+D8yzuE1FkPygBuaI7MAGMsyMkXjabd1+0U+3AcLw0xPZVelJVSpiIp58AY bz8dzxazK5/sw9O18fzU1ngtlz8jU+WLBQJCKieKvpBXFbr5p8D/eScnosU5y4nVP0J2inB74CU LMM4KAvCYMN5z27m2dgYll808UyIgRvfkS5uI8T1kA8sWsoQ6Wv8fUOGkrsi30cWppFtw94S3im iyUosGRr95XLSAg== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski --- drivers/clk/qcom/clk-spmi-pmic-div.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/clk/qcom/clk-spmi-pmic-div.c b/drivers/clk/qcom/clk-spmi-pmic-div.c index f394031eb0e5..41a0a4f3b4fb 100644 --- a/drivers/clk/qcom/clk-spmi-pmic-div.c +++ b/drivers/clk/qcom/clk-spmi-pmic-div.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -140,30 +141,26 @@ static int clk_spmi_pmic_div_set_rate(struct clk_hw *hw, unsigned long rate, { struct clkdiv *clkdiv = to_clkdiv(hw); unsigned int div_factor = div_to_div_factor(parent_rate / rate); - unsigned long flags; bool enabled; int ret; - spin_lock_irqsave(&clkdiv->lock, flags); + guard(spinlock_irqsave)(&clkdiv->lock); + enabled = is_spmi_pmic_clkdiv_enabled(clkdiv); if (enabled) { ret = spmi_pmic_clkdiv_set_enable_state(clkdiv, false); if (ret) - goto unlock; + return ret; } ret = regmap_update_bits(clkdiv->regmap, clkdiv->base + REG_DIV_CTL1, DIV_CTL1_DIV_FACTOR_MASK, div_factor); if (ret) - goto unlock; + return ret; if (enabled) ret = __spmi_pmic_clkdiv_set_enable_state(clkdiv, true, div_factor); - -unlock: - spin_unlock_irqrestore(&clkdiv->lock, flags); - return ret; }