Skip to content

Commit c90a7a6

Browse files
moonlinuxvinodkoul
authored andcommitted
phy: rockchip-pcie: Use guard notation when acquiring mutex
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 96522ee commit c90a7a6

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

drivers/phy/rockchip/phy-rockchip-pcie.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int rockchip_pcie_phy_power_off(struct phy *phy)
124124
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
125125
int err = 0;
126126

127-
mutex_lock(&rk_phy->pcie_mutex);
127+
guard(mutex)(&rk_phy->pcie_mutex);
128128

129129
regmap_write(rk_phy->reg_base,
130130
rk_phy->phy_data->pcie_laneoff,
@@ -133,7 +133,6 @@ static int rockchip_pcie_phy_power_off(struct phy *phy)
133133
PHY_LANE_IDLE_A_SHIFT + inst->index));
134134

135135
if (--rk_phy->pwr_cnt) {
136-
mutex_unlock(&rk_phy->pcie_mutex);
137136
return 0;
138137
}
139138

@@ -146,11 +145,9 @@ static int rockchip_pcie_phy_power_off(struct phy *phy)
146145
HIWORD_UPDATE(!PHY_LANE_IDLE_OFF,
147146
PHY_LANE_IDLE_MASK,
148147
PHY_LANE_IDLE_A_SHIFT + inst->index));
149-
mutex_unlock(&rk_phy->pcie_mutex);
150148
return err;
151149
}
152150

153-
mutex_unlock(&rk_phy->pcie_mutex);
154151
return err;
155152
}
156153

@@ -161,18 +158,16 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
161158
int err = 0;
162159
u32 status;
163160

164-
mutex_lock(&rk_phy->pcie_mutex);
161+
guard(mutex)(&rk_phy->pcie_mutex);
165162

166163
if (rk_phy->pwr_cnt++) {
167-
mutex_unlock(&rk_phy->pcie_mutex);
168164
return 0;
169165
}
170166

171167
err = reset_control_deassert(rk_phy->phy_rst);
172168
if (err) {
173169
dev_err(&phy->dev, "deassert phy_rst err %d\n", err);
174170
rk_phy->pwr_cnt--;
175-
mutex_unlock(&rk_phy->pcie_mutex);
176171
return err;
177172
}
178173

@@ -230,13 +225,11 @@ static int rockchip_pcie_phy_power_on(struct phy *phy)
230225
goto err_pll_lock;
231226
}
232227

233-
mutex_unlock(&rk_phy->pcie_mutex);
234228
return err;
235229

236230
err_pll_lock:
237231
reset_control_assert(rk_phy->phy_rst);
238232
rk_phy->pwr_cnt--;
239-
mutex_unlock(&rk_phy->pcie_mutex);
240233
return err;
241234
}
242235

@@ -246,22 +239,19 @@ static int rockchip_pcie_phy_init(struct phy *phy)
246239
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
247240
int err = 0;
248241

249-
mutex_lock(&rk_phy->pcie_mutex);
242+
guard(mutex)(&rk_phy->pcie_mutex);
250243

251244
if (rk_phy->init_cnt++) {
252-
mutex_unlock(&rk_phy->pcie_mutex);
253245
return 0;
254246
}
255247

256248
err = reset_control_assert(rk_phy->phy_rst);
257249
if (err) {
258250
dev_err(&phy->dev, "assert phy_rst err %d\n", err);
259251
rk_phy->init_cnt--;
260-
mutex_unlock(&rk_phy->pcie_mutex);
261252
return err;
262253
}
263254

264-
mutex_unlock(&rk_phy->pcie_mutex);
265255
return err;
266256
}
267257

@@ -270,13 +260,12 @@ static int rockchip_pcie_phy_exit(struct phy *phy)
270260
struct phy_pcie_instance *inst = phy_get_drvdata(phy);
271261
struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst);
272262

273-
mutex_lock(&rk_phy->pcie_mutex);
263+
guard(mutex)(&rk_phy->pcie_mutex);
274264

275265
if (--rk_phy->init_cnt)
276266
goto err_init_cnt;
277267

278268
err_init_cnt:
279-
mutex_unlock(&rk_phy->pcie_mutex);
280269
return 0;
281270
}
282271

0 commit comments

Comments
 (0)