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

phy: ti: da8xx-usb: Handle devm_pm_runtime_enable() errors

devm_pm_runtime_enable() can fail due to memory allocation. The current
code ignores its return value after calling pm_runtime_set_active(),
leaving the device in an inconsistent state if runtime PM initialization
fails.

Check the return value of devm_pm_runtime_enable() and return on
failure. Also move the declaration of 'ret' to the function scope
to support this check.

Fixes: ee8e41b5044f ("phy: ti: phy-da8xx-usb: Add runtime PM support")
Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patch.msgid.link/20251124105734.1027-1-vulab@iscas.ac.cn
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Haotian Zhang and committed by
Vinod Koul
08aa19de cabd25b5

+4 -3
+4 -3
drivers/phy/ti/phy-da8xx-usb.c
··· 180 180 struct da8xx_usb_phy_platform_data *pdata = dev->platform_data; 181 181 struct device_node *node = dev->of_node; 182 182 struct da8xx_usb_phy *d_phy; 183 + int ret; 183 184 184 185 d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL); 185 186 if (!d_phy) ··· 234 233 return PTR_ERR(d_phy->phy_provider); 235 234 } 236 235 } else { 237 - int ret; 238 - 239 236 ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy", 240 237 "ohci-da8xx"); 241 238 if (ret) ··· 248 249 PHY_INIT_BITS, PHY_INIT_BITS); 249 250 250 251 pm_runtime_set_active(dev); 251 - devm_pm_runtime_enable(dev); 252 + ret = devm_pm_runtime_enable(dev); 253 + if (ret) 254 + return ret; 252 255 /* 253 256 * Prevent runtime pm from being ON by default. Users can enable 254 257 * it using power/control in sysfs.