From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 1FAE4126BE1 for ; Sat, 12 Oct 2024 07:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717581; cv=none; b=XVktjJwjPdt3+ulh9K/jrrgUwA+9YP/UoiLMWbjl0xcxRkgnhkQ51xCGSs2qdy5435UwN37eW0w06MruQL41DEWORrCjgLj+Zp4PkFqLenMbuj3X8PXFRKx9YJmP45A5tKS6a+rtgazIL7J4mzWyJr/c1MTLZwcteFC3NrPmeWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717581; c=relaxed/simple; bh=QUpie//8a2pVA2kTIf37Wc0ZfgiY+n1sBlkCEjqbu/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ShmsEOXwytYJqHA5QlBiT29ZPlW/hPhcMuPo7elm0mNcDx3GqQBfgcCo0+tiqtU0F4ZyvhuZWW1HmyfalIHyUtxqPoNWOL7iECApAIPbu4MSZYb1ms1r7rlOZK/0QX2ACIz9vYpNCV+rlPHaHZmRQ+Pw7lwUXyTLSHB/aA1bK2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aFZ5XuPu; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aFZ5XuPu" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71df468496fso2504709b3a.1 for ; Sat, 12 Oct 2024 00:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717579; x=1729322379; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YRnaRhdgkUaUMlLRJLvxIED2m3y6s8utZfCC8ysa670=; b=aFZ5XuPuVTaMo7v9akv1Zw/0kOKawFARi6FiUeUncDluTTh4h8t879fG0UvKWV1l3B YSrjtxK393jqdhmL3kyV6HmvdpA4CL1/cHR83B2xN/PZ1ns9KOKIQvqecIqTQX3WHwON 7A/1EU6XtzIKPJeh99GiMAMtQEOq/9NMf7wb4qgItAdy4zSsG+ExcZfpHtglqeCHz3MY PPvkddBcGtgjnYZlyAyKYc1PdSmeB7mL/JIbhokKaZtIpF6LNCLV5NRXAaFDbkP9aMIw lcUVNfsF9PBGYKMzsFif53kTLpKfK/nnIeV2YwMpIWSvcr7Pv4TWKdyxwe2yYpZaZ09q KJJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717579; x=1729322379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YRnaRhdgkUaUMlLRJLvxIED2m3y6s8utZfCC8ysa670=; b=OelGaSFelfWPUILGNd4FEGMmyTiYvkWYjc0ny8p/g3Qa8hvyYNx7HvAUlahnuB0vht Ms8mpX/cSN3RXkGu31kqnAaPiSJvKBm62Sm5lMO0Dqs1LwDGqOSb8C59aTu9yd6YZRz+ zjSKYS2NiKzW9erUqEFiGuzOZu9y5U+UVS9ngPUSBJiwPc+vO9fBi1AQ7j5x+vxP5XNd ZapxgJVcYJm8nLWtVpLlwqOe6/V4zKUGDQl21Pef32UxeJZ0T3VmNMVl/SYtm/jTbZ7K rXBqH3h6ypSYEkbHS3v3KhA+PMu2S96uZybBXPVbkZOr/dQjqAI5F9/RehBmI7TycBLC h2uQ== X-Forwarded-Encrypted: i=1; AJvYcCUUjyZUwxCZP95uVUcBqAjBPxyDjKCO+5IwQOpNy3cDjxzU0CNIGQ7vC6UwMeaTuclQ596e9nrEOJ/E2VE=@vger.kernel.org X-Gm-Message-State: AOJu0YxsfptHXNO0P/zzU04oxZR3eAsl4k91Ulsh78ygM1zVX1qexN/B 0gUecos7PQqr16jT6vYnCYNLD0k2MbBYlUdVZVKLxDcRHoIJY1gA X-Google-Smtp-Source: AGHT+IFBdUwCJYRaP9uIilAhxIH8b2VIJABfgd2ZHHwiTppROC77o42YtpLJtRJ3UBXTnvVl99LC5w== X-Received: by 2002:a05:6a00:228f:b0:714:2198:26bd with SMTP id d2e1a72fcca58-71e37e4a7b6mr8409189b3a.11.1728717579344; Sat, 12 Oct 2024 00:19:39 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:19:39 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 1/6] phy: rockchip-pcie: Simplify error handling with dev_err_probe() Date: Sat, 12 Oct 2024 12:49:03 +0530 Message-ID: <20241012071919.3726-2-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the dev_err_probe() helper to simplify error handling during probe. This also handle scenario, when -EDEFER is returned and useless error is printed. Signed-off-by: Anand Moon --- v3: None v3: None --- drivers/phy/rockchip/phy-rockchip-pcie.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index 51cc5ece0e63..51e636a1ce33 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -371,12 +371,9 @@ static int rockchip_pcie_phy_probe(struct platform_dev= ice *pdev) mutex_init(&rk_phy->pcie_mutex); =20 rk_phy->phy_rst =3D devm_reset_control_get(dev, "phy"); - if (IS_ERR(rk_phy->phy_rst)) { - if (PTR_ERR(rk_phy->phy_rst) !=3D -EPROBE_DEFER) - dev_err(dev, - "missing phy property for reset controller\n"); - return PTR_ERR(rk_phy->phy_rst); - } + if (IS_ERR(rk_phy->phy_rst)) + return dev_err_probe(&pdev->dev, PTR_ERR(rk_phy->phy_rst), + "missing phy property for reset controller\n"); =20 rk_phy->clk_pciephy_ref =3D devm_clk_get(dev, "refclk"); if (IS_ERR(rk_phy->clk_pciephy_ref)) { --=20 2.44.0 From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 22CD01448DC for ; Sat, 12 Oct 2024 07:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717586; cv=none; b=u5Rf2/dgMv+uPMj+YXE4Z8YcOOoUFKpPOgq50WbLsxhhKV2OLyCZVc7EKhnz76Ell12a96PZSZlv4J/2ydhdnAUxus9SBwnrweB8JmXnwIN8g/0PzospLvEc6sNM1kVi1397Z2g6hHdVk6MB6hSjQinwYjWt9HaBAMjsRFGCOV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717586; c=relaxed/simple; bh=EIw3mJfTAmTe4zvwkPUO5JEBYkHljj9jBLbLU/NmMOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D4a8csSQRr90uV6EUih5puHS9wwfte/65609uy4PkAGNLUjBebGTrHsaYARix2yUDOoulsoUnYFVf5wz2+bAdqdF7psEKRLlTWPcuODoFFzjQ66dK/WiWTJJDWAEh8mblQyak2BwkYPbnlxNYjFHUhiLwDz7x5ozG/TmeoMopvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f5CAu7jZ; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f5CAu7jZ" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71de9e1f431so2177744b3a.3 for ; Sat, 12 Oct 2024 00:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717584; x=1729322384; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UDPgjk5EMnq9O3TXdBLuoizjZD+u/zLo9dMYOLZW6Gs=; b=f5CAu7jZUbGwyBEqbldqirxmsuvAs4stw+T4GIRUdrzIz23pg3RmqDzlQCkc/0pEWL wxecMdc7UbW+OCfgbSdr1HXWOZ0utf79o4mYmCkhOTlbAx6DK1Xh7OY/basrs7Sj69Hr 4tA9xrXm0yQI+paOAaRpgeyPh5BV3d+5XGkSSa0BH5fc4Y+VQyr7kWeEijblcVfp4JVn 2uKl/El32knpap867SJlUC9YSw1GnIDePQLI7x+CUWESA5aekyGdMqmrD26LV++GTihu uML8eLmqb3kWfQJg48XJnubGmDiILaQUViKZ+xLfH/1X4q+8TSdFc0UexQLaCW2zWy6k Kfvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717584; x=1729322384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UDPgjk5EMnq9O3TXdBLuoizjZD+u/zLo9dMYOLZW6Gs=; b=RocEPVEmwSJn22ruotPQMyPhmympaVR+QDJgb1hqpbgAHcxjhP5mk8OSy0yrw301RC aNiGFRNQiRTYjPpHq8y9zGAO8/TZFhMkamOoqUqIVODYdCG2hW8PkyxQEAxrGKej60ni zojvlEUi0yR62EMkb79ubg2eizX+wMlNISK4M07R+tRLr/xL1f/MWiZ9gk1Vyv8R7Ca8 VhfgyF/GBNvCfoaNofEGGnKatkX2qh2EiXk0c1ffluzjdkehCrrmfc2yVeinUJUMQgPk LYl8v3/4SOjOErd6oAUa7umBjrWWKPUZRQ8ZcWRMhbfJwYPt/suyK9T8Nmc9NSUBi0rr BnkQ== X-Forwarded-Encrypted: i=1; AJvYcCUut2fOGOJGu5QSX9A5ZWs01IPxS2WrsuSWl9ciqGuGKJfw8ufH1KLI1x1O1mk6gDnSSUFUhzITgYN20Bw=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ7hVVCqF34T7A4qsQPQdMuTQG/NvbT1lTPanzkzzmhoSJDKLz x8Sohr4Yl/FdppsT+fX1RxNug+llrgH+j29wYk8jTtZp8b1APK96 X-Google-Smtp-Source: AGHT+IHOKv/G3fft8lrCLPkbfUGY4VYY1XzqY3QsgC+ZnNRSYHKjHGuKluxzX8c+5kAFExIe9iS23w== X-Received: by 2002:a05:6a00:2288:b0:71e:ed6:1cab with SMTP id d2e1a72fcca58-71e4c1cfc19mr2588966b3a.26.1728717584316; Sat, 12 Oct 2024 00:19:44 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:19:44 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 2/6] phy: rockchip-pcie: Use devm_clk_get_enabled() helper Date: Sat, 12 Oct 2024 12:49:04 +0530 Message-ID: <20241012071919.3726-3-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use devm_clk_get_enabled() instead of devm_clk_get() to make the code cleaner and avoid calling clk_disable_unprepare(), as this is exactly what this function does. Use the dev_err_probe() helper to simplify error handling during probe. Refactor the mutex handling in the rockchip_pcie_phy_init() function to improve code readability and maintainability. The goto statement has been removed, and the mutex_unlock call is now directly within the conditional block. Return the result of reset_control_assert() function, with 0 indicating success and an error code indicating failure Signed-off-by: Anand Moon --- v3: Dan Carpenter: Reported below warning. smatch warnings: drivers/phy/rockchip/phy-rockchip-pcie.c:278 rockchip_pcie_phy_init() warn:= missing error code 'err' So refactor the mutex_lock/mutex_unlock and return the err code. v2: Change the subject drop: Change to use/Use v1: New patch in this series --- drivers/phy/rockchip/phy-rockchip-pcie.c | 34 +++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index 51e636a1ce33..b5b1b1a667b2 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -274,30 +274,19 @@ static int rockchip_pcie_phy_init(struct phy *phy) =20 mutex_lock(&rk_phy->pcie_mutex); =20 - if (rk_phy->init_cnt++) - goto err_out; - - err =3D clk_prepare_enable(rk_phy->clk_pciephy_ref); - if (err) { - dev_err(&phy->dev, "Fail to enable pcie ref clock.\n"); - goto err_refclk; + if (rk_phy->init_cnt++) { + mutex_unlock(&rk_phy->pcie_mutex); + return 0; } =20 err =3D reset_control_assert(rk_phy->phy_rst); if (err) { dev_err(&phy->dev, "assert phy_rst err %d\n", err); - goto err_reset; + rk_phy->init_cnt--; + mutex_unlock(&rk_phy->pcie_mutex); + return err; } =20 -err_out: - mutex_unlock(&rk_phy->pcie_mutex); - return 0; - -err_reset: - - clk_disable_unprepare(rk_phy->clk_pciephy_ref); -err_refclk: - rk_phy->init_cnt--; mutex_unlock(&rk_phy->pcie_mutex); return err; } @@ -312,8 +301,6 @@ static int rockchip_pcie_phy_exit(struct phy *phy) if (--rk_phy->init_cnt) goto err_init_cnt; =20 - clk_disable_unprepare(rk_phy->clk_pciephy_ref); - err_init_cnt: mutex_unlock(&rk_phy->pcie_mutex); return 0; @@ -375,11 +362,10 @@ static int rockchip_pcie_phy_probe(struct platform_de= vice *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(rk_phy->phy_rst), "missing phy property for reset controller\n"); =20 - rk_phy->clk_pciephy_ref =3D devm_clk_get(dev, "refclk"); - if (IS_ERR(rk_phy->clk_pciephy_ref)) { - dev_err(dev, "refclk not found.\n"); - return PTR_ERR(rk_phy->clk_pciephy_ref); - } + rk_phy->clk_pciephy_ref =3D devm_clk_get_enabled(dev, "refclk"); + if (IS_ERR(rk_phy->clk_pciephy_ref)) + return dev_err_probe(&pdev->dev, PTR_ERR(rk_phy->clk_pciephy_ref), + "failed to get phyclk\n"); =20 /* parse #phy-cells to see if it's legacy PHY model */ if (of_property_read_u32(dev->of_node, "#phy-cells", &phy_num)) --=20 2.44.0 From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 0B41F13D50A for ; Sat, 12 Oct 2024 07:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717591; cv=none; b=dw01U+TZNs8+29A6QbdEhOYbv6l+gbVE5/W7rkJh1xX8Ei+M7XRxsDNq13YZNYuqbeDPoQk6neknSKAh7HP7biGGUX7jtNLppTCJljKzyZnbLKMS2r7CI/SGVLi0Hvud66eBBylUwcOx5SiNOP0eDhLw414RzFpbNZlz3JQd6Ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717591; c=relaxed/simple; bh=y0fnOKUQDiED3PC2Orv9TeNTOXW0bTcc4bQfCqyChT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MNB2L7OVC+cALWj37N/5k7gq5DCZ3nykxJKDgF0TMaDUMoo0r7WynBXj+JbxPkPYcviOIWEkT5VN+GVQ593/hxTS7WfuKcpeT/vgO+NFoqx7bH8HYfKt3V6VmMumTSYIixQiq07va5gN1YNsz4lMq2Hc6yJ8gg+mVVol4zxIUFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zo5pnkUe; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zo5pnkUe" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71df2de4ed4so1851966b3a.0 for ; Sat, 12 Oct 2024 00:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717589; x=1729322389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ei1bnltRJdZvKwzxVRf43H9d7hPRtvBawiK2S1vBv6g=; b=Zo5pnkUe4h3zTjZjaxuom6LD6LYnVc8H5kMRABp/yaBK4R/s5UaaJz2Xf00OKCwNEu rws2xXo0ZuMq0oLMRXRoeHfRS/QSpXGpbXE1r8+dJYE8YsTt/JXfto6wODxBJDz0UkAb 6VJDheysQXdBR+JTeUZMCmqB6johrV2tR+/BGcZavBOGV9Li6UflCmd897/DGStwbe9B d5CyKVmXwsee7B6nsjBztyQ015TxAO4lT0yRC7DwFZRH/JQEFt51jPsmi4kzsAJuzoTO MDSLgSrFcivcl+NsaFHUR4M7uwyvXK8loWvfwxjX2Yn+P/OiqUGDKwwcQUIbtFSAmZBb uWtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717589; x=1729322389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ei1bnltRJdZvKwzxVRf43H9d7hPRtvBawiK2S1vBv6g=; b=usdSu6ES3dh51PDIadyzrBsaZ4MVyFIWe1dqap+qVFszcRE/k23DgdwLgyOXuP0K2v VTVI5TBDgp8xmFf3IHqBYaUHsFyDZIUfI7GKTZvgbUcXESbbbrWNqGADIGDSOq+AoV63 i2jaoGEc5lSgWOEbUItfVmz/q7jvfk84hw1AlYqguW/om3QwGE16mD+kV4kuIldVmyhH CU7u6Cq49/vVcTc+DrxdE9zjKyvl1ByFmJylx07JEyCWHcFMptfk7SPH/44SAV4Drlez R/S6nbvpRbgD5sNlLxrSwyEGAqGT2XYouVFW1S1ZMfG7CUUyVkSvrBF9hU6GewGSKQqv qfPw== X-Forwarded-Encrypted: i=1; AJvYcCV6nPQWzWYGlhSx/0XqzUBeEAWVGDg0w71/0kEfiGe1NODvfN1gNj/ak9vuUaxlMzLK1bs4E3kmS02haCU=@vger.kernel.org X-Gm-Message-State: AOJu0YxBNVRb041cgEM5NuohY7Ygbc9obujcSbzhVBbtt4ohiZtXaJL1 aeXaUPoYT/9d5/6hc8wKzxsvretYSwmRlBMIW0L+GLHwgeZ5f+bv X-Google-Smtp-Source: AGHT+IGHNnL0hR5nCBDTCirZJfQbJMU9jdSi821rPi96/CgZugLrK7sJ+5WJuuelZIParpqlLGUGPw== X-Received: by 2002:aa7:8e5a:0:b0:71d:f240:ec5 with SMTP id d2e1a72fcca58-71e26effbf5mr14046534b3a.14.1728717589354; Sat, 12 Oct 2024 00:19:49 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:19:49 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 3/6] phy: rockchip-pcie: Use regmap_read_poll_timeout() for PCIe reference clk PLL status Date: Sat, 12 Oct 2024 12:49:05 +0530 Message-ID: <20241012071919.3726-4-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace open-coded phy PCIe reference clk PLL status polling with regmap_read_poll_timeout API. This change simplifies the code without altering functionality. Signed-off-by: Anand Moon --- v3: None. v2: Fix the subject, add the missing () in the function name, Fix the typo reference v1: None. --- drivers/phy/rockchip/phy-rockchip-pcie.c | 56 +++++++----------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index b5b1b1a667b2..e60f24b0b363 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -162,7 +162,6 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) struct rockchip_pcie_phy *rk_phy =3D to_pcie_phy(inst); int err =3D 0; u32 status; - unsigned long timeout; =20 mutex_lock(&rk_phy->pcie_mutex); =20 @@ -191,21 +190,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) * so we make it large enough here. And we use loop-break * method which should not be harmful. */ - timeout =3D jiffies + msecs_to_jiffies(1000); - - err =3D -EINVAL; - while (time_before(jiffies, timeout)) { - regmap_read(rk_phy->reg_base, - rk_phy->phy_data->pcie_status, - &status); - if (status & PHY_PLL_LOCKED) { - dev_dbg(&phy->dev, "pll locked!\n"); - err =3D 0; - break; - } - msleep(20); - } - + err =3D regmap_read_poll_timeout(rk_phy->reg_base, + rk_phy->phy_data->pcie_status, + status, + status & PHY_PLL_LOCKED, + 200, 100000); if (err) { dev_err(&phy->dev, "pll lock timeout!\n"); goto err_pll_lock; @@ -214,19 +203,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) phy_wr_cfg(rk_phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE); phy_wr_cfg(rk_phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M); =20 - err =3D -ETIMEDOUT; - while (time_before(jiffies, timeout)) { - regmap_read(rk_phy->reg_base, - rk_phy->phy_data->pcie_status, - &status); - if (!(status & PHY_PLL_OUTPUT)) { - dev_dbg(&phy->dev, "pll output enable done!\n"); - err =3D 0; - break; - } - msleep(20); - } - + err =3D regmap_read_poll_timeout(rk_phy->reg_base, + rk_phy->phy_data->pcie_status, + status, + !(status & PHY_PLL_OUTPUT), + 200, 100000); if (err) { dev_err(&phy->dev, "pll output enable timeout!\n"); goto err_pll_lock; @@ -236,19 +217,12 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) HIWORD_UPDATE(PHY_CFG_PLL_LOCK, PHY_CFG_ADDR_MASK, PHY_CFG_ADDR_SHIFT)); - err =3D -EINVAL; - while (time_before(jiffies, timeout)) { - regmap_read(rk_phy->reg_base, - rk_phy->phy_data->pcie_status, - &status); - if (status & PHY_PLL_LOCKED) { - dev_dbg(&phy->dev, "pll relocked!\n"); - err =3D 0; - break; - } - msleep(20); - } =20 + err =3D regmap_read_poll_timeout(rk_phy->reg_base, + rk_phy->phy_data->pcie_status, + status, + status & PHY_PLL_LOCKED, + 200, 100000); if (err) { dev_err(&phy->dev, "pll relock timeout!\n"); goto err_pll_lock; --=20 2.44.0 From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 122F513D50A for ; Sat, 12 Oct 2024 07:19:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717596; cv=none; b=u5meJpumTEDkC9i485pcOMxQmnfo5VMN//Ds/M4ILF2rBQgsmsQX+QjeVam/VHvltY8ZNPPqxYXgQ4i0hbuItB9n4pUYe+bHKNgukZwDuzKokGFDBZQ5RmCVXdDd4GIEs07zqW4z/YcyMXi2jwqoMb2KYZV1XNQM5Igzmu17wYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717596; c=relaxed/simple; bh=9sOCsYd8FuD1db4bG2wZTrCV0DHzZtqtGuhIk3xlfMs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y0iCIVeGD1PNQnb0DMHvolgny+YZ30wT8vFkD9yH3kklg/1XxhdYGqJ0pjUz8OVm9o0uCx1jg6TYsTFyfcAvxj5lttGeAuutrjpA+5883NIv6wkxg+Sh43zfuouSKQBpkiHomQX2yeo/K3h+wsSDYu1po4ddd/QI0PtFQnhOA3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=abQkmSzM; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="abQkmSzM" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71df04d3cd1so2359895b3a.2 for ; Sat, 12 Oct 2024 00:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717594; x=1729322394; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=97G2TijBo7TJKDwdLKVOfvTHrYI49lDUOlitVvXkVUE=; b=abQkmSzMJoHPUEnud/mJlqv7JHD2LHlXXcvWZzu8Eg96lOVPzS3YOahbMwrkdD5QxE ClHeqRgdwbMf/OZhy+yAx/eKYs0clV7eca+wk3JxQMjdaHHfI/HqF4n/EdR9YVQIa+O/ ZKVOq8JHQ8e21yAhBR9HfO8DWdJmSkGaePJhOBTMeoRwityd5Rw/jYJuvRaFU0JmzMy1 BuxKFNkXZX4PQ4KqDMEtSHjrD025ozFvfL5Cakh6NlrOZZyI95RUw+kix8ODIlWn/thX l0MeothT4h0TcAcy+VyT5NfBtAlCQhU2y0/QAPvhLu+zxR6ghZi+XYiqkG14fCvVf78A g2CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717594; x=1729322394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=97G2TijBo7TJKDwdLKVOfvTHrYI49lDUOlitVvXkVUE=; b=cAH0sffsol1OEyF2EqCrInE6y16sin9NbzanTbGKxaAa1kCM2iSkIRc+PrnMOOyINI mXK9HlYYfNs2a4UdINQCvcQi6rABV1D5+52sjuAV6Z6di8/ay3WIgR5+MT/8PjTnFT/h vXecSAUheXa8P5GWXYEQsMRm+hIseSZZrf96BGpxQJJt3tNlA/0EczUuKR9zubXCJ4Yv IO1soInhc/J5Ymc1VNvKXuBj7KE1tvcPjeji5Kgaa5+Ezgmmwiu7GQLJMWMTNPJkQWMB DL7VCd8QPbwzqDHVtnb4GPdcYkkDRYtDc3acTNw2FloVZIWsjeCn2yr5Fw5uMdcmKWgN 4IQg== X-Forwarded-Encrypted: i=1; AJvYcCU3War2W/cQdIO6IrrpAc3MWGuiE+CwJqvfYtsPjbtk3+6DoSMmA9IIoIfonisOZBWmJ7lgj70jDnwEqW4=@vger.kernel.org X-Gm-Message-State: AOJu0YzoP1oucf9Pg8lYzMWFtSenDQNl6UgDgh8tfoBcl5uBVvMz5Das uxTcIo+y5fGrYrCyvYcWEa1Sghi/mXdL1bW2Eoj9yEptfU/FhdMZ X-Google-Smtp-Source: AGHT+IGQCNKpLK6KUs8VSkaJ0d7emmgc4XI8SJDHYeYoaej9YcBG4bftnc4g9GOFwvVQAzJ0Rkljkw== X-Received: by 2002:a05:6a00:189a:b0:71e:4655:59ce with SMTP id d2e1a72fcca58-71e4c03044cmr3762274b3a.0.1728717594320; Sat, 12 Oct 2024 00:19:54 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:19:54 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 4/6] phy: rockchip-pcie: Refactor mutex handling in rockchip_pcie_phy_power_off() Date: Sat, 12 Oct 2024 12:49:06 +0530 Message-ID: <20241012071919.3726-5-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the mutex handling in the rockchip_pcie_phy_power_off() function to improve code readability and maintainability. The goto statement has been removed, and the mutex_unlock call is now directly within the conditional block. Return the result of reset_control_assert() function, with 0 indicating success and an error code indicating failure Signed-off-by: Anand Moon --- v3: New patch. --- drivers/phy/rockchip/phy-rockchip-pcie.c | 26 +++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index e60f24b0b363..c84a3c209315 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -132,26 +132,24 @@ static int rockchip_pcie_phy_power_off(struct phy *ph= y) PHY_LANE_IDLE_MASK, PHY_LANE_IDLE_A_SHIFT + inst->index)); =20 - if (--rk_phy->pwr_cnt) - goto err_out; + if (--rk_phy->pwr_cnt) { + mutex_unlock(&rk_phy->pcie_mutex); + return 0; + } =20 err =3D reset_control_assert(rk_phy->phy_rst); if (err) { dev_err(&phy->dev, "assert phy_rst err %d\n", err); - goto err_restore; + rk_phy->pwr_cnt++; + regmap_write(rk_phy->reg_base, + rk_phy->phy_data->pcie_laneoff, + HIWORD_UPDATE(!PHY_LANE_IDLE_OFF, + PHY_LANE_IDLE_MASK, + PHY_LANE_IDLE_A_SHIFT + inst->index)); + mutex_unlock(&rk_phy->pcie_mutex); + return err; } =20 -err_out: - mutex_unlock(&rk_phy->pcie_mutex); - return 0; - -err_restore: - rk_phy->pwr_cnt++; - regmap_write(rk_phy->reg_base, - rk_phy->phy_data->pcie_laneoff, - HIWORD_UPDATE(!PHY_LANE_IDLE_OFF, - PHY_LANE_IDLE_MASK, - PHY_LANE_IDLE_A_SHIFT + inst->index)); mutex_unlock(&rk_phy->pcie_mutex); return err; } --=20 2.44.0 From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 0A6EE13D50A for ; Sat, 12 Oct 2024 07:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717601; cv=none; b=h6Ig5pJ15HnnwPfoPE1sM3K5C5u/x8tn88Ji/kXuSxp5rp0SF955v26Gy7M0Z0hHlzX5npNehhAg6MXL+kynMdOPj9gUSrSRBRTVIORTHwpsoESO64T96KL8/T4LJCmvxHemnNicu9wXyYma5+qJKv9Y2RQFhivXjVfOKZwqLM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717601; c=relaxed/simple; bh=NQM+xKqLTytj/SwpdEdRSRqK2+IrXB9RWOud85bANfc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ARZrcBipDDJYtDRWrsDFszoQwSfmOSzcjmCYJxmfuRdh30z3HXugj3SIxyhlzj7SyvCUGIDwdtf4lzk39wQ/d6qfJ4Jtzm5WaZOc6Fz3B4UYSZrUsnWbwgKhyQN1WdBYCOGMMY9HEUADCNeqjZzR9XIgPBGpxETmSRgdjSVhLZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XMi7Hk2A; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XMi7Hk2A" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7cd8803fe0aso1991169a12.0 for ; Sat, 12 Oct 2024 00:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717599; x=1729322399; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tveNarpSwjlEhM4Qolz0xMrvg/75/UUwTA0pqhWJ0Mw=; b=XMi7Hk2Ab88kTmfW9kDZ+xLFIyf9NTvYBEBSERifoy78O/zajzsD/B2Y8CRjMyzlBW NCf5YSOFw175CuGW081lLWhhyvqWhZdL4wIuqCcE3XQgerrRLHNMi8hH378HRIAglxFv x8d8DJWz4DFQk5cg2zX3CetRJ3X9nKb75HYunEE3ZhJYd68tYOfQKOt+hbBeQve8IpPO LEFnOVz1LnE9V/Dq7pg71slxkbgSUX2cc88qB3zUHtAt2j8aFn9Rrd5PY8mNI2EfPKu5 FkFZKi13CtxVI+gh/k90ql94LNO3A/LNeXiebnnumbUeOXSTZHiK+CaMfegd2IbEEnIa hwbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717599; x=1729322399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tveNarpSwjlEhM4Qolz0xMrvg/75/UUwTA0pqhWJ0Mw=; b=Udy40cx/H77537PcRjiOAdrPJBvUaqwucoNFQ1l3h36RFx4hUe2aYhaZOBYEKHjzoV ooI4Zrw2q+B6wjrQDewz7GDalvthoFYBeTNTjCC+EVhTrJcL7+SE3NHCNc2iYBKaDxxw U8Y8CtAMvJ7CGRlOFQ1bAeq2P5HQmBW9OrhDJrFoEc8ksmyb5a2AHzsDXQ5KP1aBwuHr 4DtG4KRnCEk+6lrpArBpQZ7fhmYwz+G7MKF/znDfBLxtfBDXw5ZPzlUIR0J5daMYYOIY F/toK5wt2ivxECG/XMcMHnDQvV15rChR2vdobi7UrddkPq8DGFpgmdhLWxjgWbHy7S54 UTtw== X-Forwarded-Encrypted: i=1; AJvYcCUmicd472pTZA/4EuaYfp/2t3bPnYxTnIaKFXhoHV9eepmxoHAbUQx6reCjXNiNgVkGp9x6enjEoxgphGI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4bK/GCZKMjQGN5BAFhdB7ZJtRgseTUOr59znX3JSSx0/O5mD9 ivTkw9/Z8NSviVw6nw3Nld5FjcpSbmi+0vmb3/wQ4iHf6wIqXNEP X-Google-Smtp-Source: AGHT+IHa+OOul8kkfcVe5xb551ye568I+GFpxdHlOz9EhP0OrqwzuVKv5lNmoyUlXuqKze6HkNM1TQ== X-Received: by 2002:a05:6a21:6e4b:b0:1cf:e5e4:d225 with SMTP id adf61e73a8af0-1d8bcfaa171mr6538150637.37.1728717599290; Sat, 12 Oct 2024 00:19:59 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:19:59 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 5/6] phy: rockchip-pcie: Refactor mutex handling in rockchip_pcie_phy_power_on() Date: Sat, 12 Oct 2024 12:49:07 +0530 Message-ID: <20241012071919.3726-6-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the mutex handling in the rockchip_pcie_phy_power_on() function to improve code readability and maintainability. The goto statement has been removed, and the mutex_unlock call is now directly within the conditional block. Return the result of reset_control_deassert() or regmap_read_poll_timeout() function, with 0 indicating success and an error code indicating failure. Signed-off-by: Anand Moon --- v3: New patch. --- drivers/phy/rockchip/phy-rockchip-pcie.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index c84a3c209315..6dd014625226 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -163,13 +163,17 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) =20 mutex_lock(&rk_phy->pcie_mutex); =20 - if (rk_phy->pwr_cnt++) - goto err_out; + if (rk_phy->pwr_cnt++) { + mutex_unlock(&rk_phy->pcie_mutex); + return 0; + } =20 err =3D reset_control_deassert(rk_phy->phy_rst); if (err) { dev_err(&phy->dev, "deassert phy_rst err %d\n", err); - goto err_pwr_cnt; + rk_phy->pwr_cnt--; + mutex_unlock(&rk_phy->pcie_mutex); + return err; } =20 regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_conf, @@ -226,13 +230,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) goto err_pll_lock; } =20 -err_out: mutex_unlock(&rk_phy->pcie_mutex); - return 0; + return err; =20 err_pll_lock: reset_control_assert(rk_phy->phy_rst); -err_pwr_cnt: rk_phy->pwr_cnt--; mutex_unlock(&rk_phy->pcie_mutex); return err; --=20 2.44.0 From nobody Wed Nov 27 06:51:57 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 0681C142E76 for ; Sat, 12 Oct 2024 07:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717606; cv=none; b=TE8lTofH8KT0g3DD6WpkQxD8/7M5auUIh5hYU7UGFeu4i2wUQ+RXurgOv4VlT68/8RmqtLdITpXvETd+lPTujiBgQQs/Qpg9daY0b+ipjjsH8dYfhSd737/gk5fwmjy1H5oRO4dNljfNVbjVx9AVuZxRCNePRLRlgbUQXhbKGM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728717606; c=relaxed/simple; bh=YmNKaUk7IoY1KZlZKWCDkN2t9kQL+UzmbogTz9W9Qec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g2OZjPqHfGS7RfSgoDoc88/0RbkJwEbcuFZep521tPdCrFL+OaRePJUPYlRVd2qgzeRT2adP/UQ4LocAcgnmCHlMRy+tnSV2T3ME8ijSK67gj6jyfxvoFFhk3LwYqRAP0d0U1XJvWy1EAOJvH8qeoNOto613fkqiE0f8kPfTrys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K1duH1Iv; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K1duH1Iv" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e1a715c72so2056821b3a.1 for ; Sat, 12 Oct 2024 00:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728717604; x=1729322404; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9ApDa1aMFJqfOVoyoGKBNzlcDrQSgxcYXTomesTpCDA=; b=K1duH1Ivn5XtEQiTHpPirsCJRDAW6G0aKWF8s82647lc08ZJkBuOkRxBbO9ZdU4m5p V8bBEdoK0hlpRSSwvhl48vDmlquQBuo9ssVtyhSRxyufs0Y87FI13U/Z5cIuctWAu0JR ohWohH3oeqsv0lYiuut1Gxb5LhrtFVmDIvaockUS4eeuwm4mqG4OylJc4lFkhKUxmTLm RvL9/C+goA3I9TkWpPfZ+c5JrqUtkDQ6Xv4Dpi8ZGVL9OEHYz1IUiAy8GLYQTHoNv6Bw NiL3IKg1gUzocayOPI9cpoI1sttKgmmErkjWmP33fTqb+ZKOYMD7eqFmoVu427EcIEyd Wx/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728717604; x=1729322404; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9ApDa1aMFJqfOVoyoGKBNzlcDrQSgxcYXTomesTpCDA=; b=aaVM0o4xnv+3rV4HavjHTOe5yX7+j0C0nSNWugShiTsNrOS1pk4TxTgDuUpHn5gj4t 1/UVApXv+iErnB3WF8mxBYysKO4NLOpGpL5/AC17rMgDm6MZuA2IFZ5J1Z/ofJCwPRZN cBoWj9fvk4DwGcrBT2KYZ98swXb76DcD+T5A7k4AZSHilzVflrypHrp6EkT0U6zhtDJL GXouXWjBQRCGPxuFVvPzIXnqQSKu5iJ5B0whhfT3RyeoIp3RzejN/cKxbdx4a5AHWU0X ecbI1LrNFQcZPEm3hNsoeh++fjTQB+JDINnAiZPZHb2iPNNA9P2R/dZb2eP/HNfaxmlJ AxJw== X-Forwarded-Encrypted: i=1; AJvYcCVEamFlFShhlKY9W88Oy+u9V9gHn7Fp9rvqMungC6EpIAARLmaLTTAhro0Aq/pZJTI/bWjVGQXyFdYyV04=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ9yntXLGV9FcZ4NEii2jMayGW1joDeDb8VpbPaq0cKxxg2R5/ 7Q3zGNi2vpWlZRd/gLfgo+z9E41QpSgM/5bHSt3E9TQ8ioALVNwU X-Google-Smtp-Source: AGHT+IFsw1Y6x7x4B49Cs5Sitm7AtWn/o4JBeTJPuqe7CDeq3DvEnDZYXFgGluNUXLU0iuQXhCPlsA== X-Received: by 2002:a05:6a00:1390:b0:71e:ba5:821b with SMTP id d2e1a72fcca58-71e3806bfefmr7441120b3a.27.1728717604256; Sat, 12 Oct 2024 00:20:04 -0700 (PDT) Received: from localhost.localdomain ([113.30.217.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aaba171sm3664620b3a.161.2024.10.12.00.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 00:20:03 -0700 (PDT) From: Anand Moon To: Vinod Koul , Kishon Vijay Abraham I , Heiko Stuebner , Philipp Zabel , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support), linux-kernel@vger.kernel.org (open list) Cc: Anand Moon , Dan Carpenter Subject: [PATCH v3 6/6] phy: rockchip-pcie: Use guard notation when acquiring mutex Date: Sat, 12 Oct 2024 12:49:08 +0530 Message-ID: <20241012071919.3726-7-linux.amoon@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com> References: <20241012071919.3726-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using guard notation makes the code more compact and error handling more robust by ensuring that mutexes are released in all code paths when control leaves critical section. Signed-off-by: Anand Moon --- v3: New patch --- drivers/phy/rockchip/phy-rockchip-pcie.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchi= p/phy-rockchip-pcie.c index 6dd014625226..bd44af36c67a 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -124,7 +124,7 @@ static int rockchip_pcie_phy_power_off(struct phy *phy) struct rockchip_pcie_phy *rk_phy =3D to_pcie_phy(inst); int err =3D 0; =20 - mutex_lock(&rk_phy->pcie_mutex); + guard(mutex)(&rk_phy->pcie_mutex); =20 regmap_write(rk_phy->reg_base, rk_phy->phy_data->pcie_laneoff, @@ -133,7 +133,6 @@ static int rockchip_pcie_phy_power_off(struct phy *phy) PHY_LANE_IDLE_A_SHIFT + inst->index)); =20 if (--rk_phy->pwr_cnt) { - mutex_unlock(&rk_phy->pcie_mutex); return 0; } =20 @@ -146,11 +145,9 @@ static int rockchip_pcie_phy_power_off(struct phy *phy) HIWORD_UPDATE(!PHY_LANE_IDLE_OFF, PHY_LANE_IDLE_MASK, PHY_LANE_IDLE_A_SHIFT + inst->index)); - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 @@ -161,10 +158,9 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) int err =3D 0; u32 status; =20 - mutex_lock(&rk_phy->pcie_mutex); + guard(mutex)(&rk_phy->pcie_mutex); =20 if (rk_phy->pwr_cnt++) { - mutex_unlock(&rk_phy->pcie_mutex); return 0; } =20 @@ -172,7 +168,6 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) if (err) { dev_err(&phy->dev, "deassert phy_rst err %d\n", err); rk_phy->pwr_cnt--; - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 @@ -230,13 +225,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy) goto err_pll_lock; } =20 - mutex_unlock(&rk_phy->pcie_mutex); return err; =20 err_pll_lock: reset_control_assert(rk_phy->phy_rst); rk_phy->pwr_cnt--; - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 @@ -246,10 +239,9 @@ static int rockchip_pcie_phy_init(struct phy *phy) struct rockchip_pcie_phy *rk_phy =3D to_pcie_phy(inst); int err =3D 0; =20 - mutex_lock(&rk_phy->pcie_mutex); + guard(mutex)(&rk_phy->pcie_mutex); =20 if (rk_phy->init_cnt++) { - mutex_unlock(&rk_phy->pcie_mutex); return 0; } =20 @@ -257,11 +249,9 @@ static int rockchip_pcie_phy_init(struct phy *phy) if (err) { dev_err(&phy->dev, "assert phy_rst err %d\n", err); rk_phy->init_cnt--; - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 - mutex_unlock(&rk_phy->pcie_mutex); return err; } =20 @@ -270,13 +260,12 @@ static int rockchip_pcie_phy_exit(struct phy *phy) struct phy_pcie_instance *inst =3D phy_get_drvdata(phy); struct rockchip_pcie_phy *rk_phy =3D to_pcie_phy(inst); =20 - mutex_lock(&rk_phy->pcie_mutex); + guard(mutex)(&rk_phy->pcie_mutex); =20 if (--rk_phy->init_cnt) goto err_init_cnt; =20 err_init_cnt: - mutex_unlock(&rk_phy->pcie_mutex); return 0; } =20 --=20 2.44.0