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.

usb: phy: generic: Convert to devm_clk_get_optional()

The generic USB PHY driver uses the existence of the "clocks" property
to see if a clock is optional or not. Use devm_clk_get_optional()
instead, which exists for this purpose. As usb_phy_generic.clk is now
either a valid clock pointer or NULL, and all clock operations handle
NULL pointers gracefully, several IS_ERR() checks can be removed,
simplifying the code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

...

Link: https://patch.msgid.link/5cc21d821edf5d40f56a74cd251bb1b982876b72.1769004444.git.geert+renesas@glider.be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Geert Uytterhoeven and committed by
Greg Kroah-Hartman
300034f9 62b718d2

+9 -19
+9 -19
drivers/usb/phy/phy-generic.c
··· 49 49 int ret = 0; 50 50 51 51 if (suspend) { 52 - if (!IS_ERR(nop->clk)) 53 - clk_disable_unprepare(nop->clk); 52 + clk_disable_unprepare(nop->clk); 54 53 if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev)) 55 54 ret = regulator_disable(nop->vcc); 56 55 } else { 57 56 if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev)) 58 57 ret = regulator_enable(nop->vcc); 59 - if (!IS_ERR(nop->clk)) 60 - clk_prepare_enable(nop->clk); 58 + clk_prepare_enable(nop->clk); 61 59 } 62 60 63 61 return ret; ··· 135 137 dev_err(phy->dev, "Failed to enable power\n"); 136 138 } 137 139 138 - if (!IS_ERR(nop->clk)) { 139 - ret = clk_prepare_enable(nop->clk); 140 - if (ret) 141 - return ret; 142 - } 140 + ret = clk_prepare_enable(nop->clk); 141 + if (ret) 142 + return ret; 143 143 144 144 nop_reset(nop); 145 145 ··· 151 155 152 156 gpiod_set_value_cansleep(nop->gpiod_reset, 1); 153 157 154 - if (!IS_ERR(nop->clk)) 155 - clk_disable_unprepare(nop->clk); 158 + clk_disable_unprepare(nop->clk); 156 159 157 160 if (!IS_ERR(nop->vcc)) { 158 161 if (regulator_disable(nop->vcc)) ··· 197 202 { 198 203 enum usb_phy_type type = USB_PHY_TYPE_USB2; 199 204 int err = 0; 200 - 201 205 u32 clk_rate = 0; 202 - bool needs_clk = false; 203 206 204 207 if (dev->of_node) { 205 208 struct device_node *node = dev->of_node; 206 209 207 210 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 208 211 clk_rate = 0; 209 - 210 - needs_clk = of_property_present(node, "clocks"); 211 212 } 212 213 nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset", 213 214 GPIOD_ASIS); ··· 226 235 if (!nop->phy.otg) 227 236 return -ENOMEM; 228 237 229 - nop->clk = devm_clk_get(dev, "main_clk"); 238 + nop->clk = devm_clk_get_optional(dev, "main_clk"); 230 239 if (IS_ERR(nop->clk)) { 231 240 dev_dbg(dev, "Can't get phy clock: %ld\n", 232 241 PTR_ERR(nop->clk)); 233 - if (needs_clk) 234 - return PTR_ERR(nop->clk); 242 + return PTR_ERR(nop->clk); 235 243 } 236 244 237 - if (!IS_ERR(nop->clk) && clk_rate) { 245 + if (clk_rate) { 238 246 err = clk_set_rate(nop->clk, clk_rate); 239 247 if (err) { 240 248 dev_err(dev, "Error setting clock rate\n");