Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <linux.amoon@gmail.com>
Link: https://lore.kernel.org/r/20241012071919.3726-7-linux.amoon@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Anand Moon and committed by
Vinod Koul
c90a7a68 96522eeb

+4 -15
+4 -15
drivers/phy/rockchip/phy-rockchip-pcie.c
··· 124 124 struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst); 125 125 int err = 0; 126 126 127 - mutex_lock(&rk_phy->pcie_mutex); 127 + guard(mutex)(&rk_phy->pcie_mutex); 128 128 129 129 regmap_write(rk_phy->reg_base, 130 130 rk_phy->phy_data->pcie_laneoff, ··· 133 133 PHY_LANE_IDLE_A_SHIFT + inst->index)); 134 134 135 135 if (--rk_phy->pwr_cnt) { 136 - mutex_unlock(&rk_phy->pcie_mutex); 137 136 return 0; 138 137 } 139 138 ··· 145 146 HIWORD_UPDATE(!PHY_LANE_IDLE_OFF, 146 147 PHY_LANE_IDLE_MASK, 147 148 PHY_LANE_IDLE_A_SHIFT + inst->index)); 148 - mutex_unlock(&rk_phy->pcie_mutex); 149 149 return err; 150 150 } 151 151 152 - mutex_unlock(&rk_phy->pcie_mutex); 153 152 return err; 154 153 } 155 154 ··· 158 161 int err = 0; 159 162 u32 status; 160 163 161 - mutex_lock(&rk_phy->pcie_mutex); 164 + guard(mutex)(&rk_phy->pcie_mutex); 162 165 163 166 if (rk_phy->pwr_cnt++) { 164 - mutex_unlock(&rk_phy->pcie_mutex); 165 167 return 0; 166 168 } 167 169 ··· 168 172 if (err) { 169 173 dev_err(&phy->dev, "deassert phy_rst err %d\n", err); 170 174 rk_phy->pwr_cnt--; 171 - mutex_unlock(&rk_phy->pcie_mutex); 172 175 return err; 173 176 } 174 177 ··· 225 230 goto err_pll_lock; 226 231 } 227 232 228 - mutex_unlock(&rk_phy->pcie_mutex); 229 233 return err; 230 234 231 235 err_pll_lock: 232 236 reset_control_assert(rk_phy->phy_rst); 233 237 rk_phy->pwr_cnt--; 234 - mutex_unlock(&rk_phy->pcie_mutex); 235 238 return err; 236 239 } 237 240 ··· 239 246 struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst); 240 247 int err = 0; 241 248 242 - mutex_lock(&rk_phy->pcie_mutex); 249 + guard(mutex)(&rk_phy->pcie_mutex); 243 250 244 251 if (rk_phy->init_cnt++) { 245 - mutex_unlock(&rk_phy->pcie_mutex); 246 252 return 0; 247 253 } 248 254 ··· 249 257 if (err) { 250 258 dev_err(&phy->dev, "assert phy_rst err %d\n", err); 251 259 rk_phy->init_cnt--; 252 - mutex_unlock(&rk_phy->pcie_mutex); 253 260 return err; 254 261 } 255 262 256 - mutex_unlock(&rk_phy->pcie_mutex); 257 263 return err; 258 264 } 259 265 ··· 260 270 struct phy_pcie_instance *inst = phy_get_drvdata(phy); 261 271 struct rockchip_pcie_phy *rk_phy = to_pcie_phy(inst); 262 272 263 - mutex_lock(&rk_phy->pcie_mutex); 273 + guard(mutex)(&rk_phy->pcie_mutex); 264 274 265 275 if (--rk_phy->init_cnt) 266 276 goto err_init_cnt; 267 277 268 278 err_init_cnt: 269 - mutex_unlock(&rk_phy->pcie_mutex); 270 279 return 0; 271 280 } 272 281