From: Anand Moon <linux.amoon@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Philipp Zabel <p.zabel@pengutronix.de>,
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 <linux.amoon@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH v3 6/6] phy: rockchip-pcie: Use guard notation when acquiring mutex
Date: Sat, 12 Oct 2024 12:49:08 +0530 [thread overview]
Message-ID: <20241012071919.3726-7-linux.amoon@gmail.com> (raw)
In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com>
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 <linux.amoon@gmail.com>
---
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/rockchip/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 = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
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));
if (--rk_phy->pwr_cnt) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -161,10 +158,9 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
int err = 0;
u32 status;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->pwr_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
@@ -230,13 +225,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
goto err_pll_lock;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
err_pll_lock:
reset_control_assert(rk_phy->phy_rst);
rk_phy->pwr_cnt--;
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -246,10 +239,9 @@ static int rockchip_pcie_phy_init(struct phy *phy)
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->init_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -270,13 +260,12 @@ static int rockchip_pcie_phy_exit(struct phy *phy)
struct phy_pcie_instance *inst = phy_get_drvdata(phy);
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (--rk_phy->init_cnt)
goto err_init_cnt;
err_init_cnt:
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
--
2.44.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
WARNING: multiple messages have this Message-ID (diff)
From: Anand Moon <linux.amoon@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Philipp Zabel <p.zabel@pengutronix.de>,
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 <linux.amoon@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH v3 6/6] phy: rockchip-pcie: Use guard notation when acquiring mutex
Date: Sat, 12 Oct 2024 12:49:08 +0530 [thread overview]
Message-ID: <20241012071919.3726-7-linux.amoon@gmail.com> (raw)
In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com>
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 <linux.amoon@gmail.com>
---
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/rockchip/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 = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
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));
if (--rk_phy->pwr_cnt) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -161,10 +158,9 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
int err = 0;
u32 status;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->pwr_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
@@ -230,13 +225,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
goto err_pll_lock;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
err_pll_lock:
reset_control_assert(rk_phy->phy_rst);
rk_phy->pwr_cnt--;
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -246,10 +239,9 @@ static int rockchip_pcie_phy_init(struct phy *phy)
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->init_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -270,13 +260,12 @@ static int rockchip_pcie_phy_exit(struct phy *phy)
struct phy_pcie_instance *inst = phy_get_drvdata(phy);
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (--rk_phy->init_cnt)
goto err_init_cnt;
err_init_cnt:
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
--
2.44.0
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
WARNING: multiple messages have this Message-ID (diff)
From: Anand Moon <linux.amoon@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Philipp Zabel <p.zabel@pengutronix.de>,
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 <linux.amoon@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH v3 6/6] phy: rockchip-pcie: Use guard notation when acquiring mutex
Date: Sat, 12 Oct 2024 12:49:08 +0530 [thread overview]
Message-ID: <20241012071919.3726-7-linux.amoon@gmail.com> (raw)
In-Reply-To: <20241012071919.3726-1-linux.amoon@gmail.com>
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 <linux.amoon@gmail.com>
---
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/rockchip/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 = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
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));
if (--rk_phy->pwr_cnt) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -161,10 +158,9 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
int err = 0;
u32 status;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->pwr_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
@@ -230,13 +225,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
goto err_pll_lock;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
err_pll_lock:
reset_control_assert(rk_phy->phy_rst);
rk_phy->pwr_cnt--;
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -246,10 +239,9 @@ static int rockchip_pcie_phy_init(struct phy *phy)
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
int err = 0;
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (rk_phy->init_cnt++) {
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
@@ -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;
}
- mutex_unlock(&rk_phy->pcie_mutex);
return err;
}
@@ -270,13 +260,12 @@ static int rockchip_pcie_phy_exit(struct phy *phy)
struct phy_pcie_instance *inst = phy_get_drvdata(phy);
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
- mutex_lock(&rk_phy->pcie_mutex);
+ guard(mutex)(&rk_phy->pcie_mutex);
if (--rk_phy->init_cnt)
goto err_init_cnt;
err_init_cnt:
- mutex_unlock(&rk_phy->pcie_mutex);
return 0;
}
--
2.44.0
next prev parent reply other threads:[~2024-10-12 7:27 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-12 7:19 [PATCH v3 0/6] RK3399: PCie Phy using new helper function Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` [PATCH v3 1/6] phy: rockchip-pcie: Simplify error handling with dev_err_probe() Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` [PATCH v3 2/6] phy: rockchip-pcie: Use devm_clk_get_enabled() helper Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` [PATCH v3 3/6] phy: rockchip-pcie: Use regmap_read_poll_timeout() for PCIe reference clk PLL status Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` [PATCH v3 4/6] phy: rockchip-pcie: Refactor mutex handling in rockchip_pcie_phy_power_off() Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` [PATCH v3 5/6] phy: rockchip-pcie: Refactor mutex handling in rockchip_pcie_phy_power_on() Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-10-12 7:19 ` Anand Moon [this message]
2024-10-12 7:19 ` [PATCH v3 6/6] phy: rockchip-pcie: Use guard notation when acquiring mutex Anand Moon
2024-10-12 7:19 ` Anand Moon
2024-12-02 16:01 ` [PATCH v3 0/6] RK3399: PCie Phy using new helper function Anand Moon
2024-12-02 16:01 ` Anand Moon
2024-12-02 16:01 ` Anand Moon
2024-12-08 17:02 ` Vinod Koul
2024-12-08 17:02 ` Vinod Koul
2024-12-08 17:02 ` Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241012071919.3726-7-linux.amoon@gmail.com \
--to=linux.amoon@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=heiko@sntech.de \
--cc=kishon@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=p.zabel@pengutronix.de \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.