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: renesas: rcar-gen3-usb2: Use devm_pm_runtime_enable()

Replace pm_runtime_enable() with devm_pm_runtime_enable() to ensure proper
cleanup if the probe fails. This change enhances driver reliability by
avoiding resource leaks, as the devm-managed version automatically handles
disabling at probe failure or device removal.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/ca028d41f84227efeccb0cbdff22fbf16e5cf6ab.1766405010.git.tommaso.merciai.xr@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Tommaso Merciai and committed by
Vinod Koul
230c817a d6db3b3a

+21 -32
+21 -32
drivers/phy/renesas/phy-rcar-gen3-usb2.c
··· 862 862 * devm_phy_create() will call pm_runtime_enable(&phy->dev); 863 863 * And then, phy-core will manage runtime pm for this device. 864 864 */ 865 - pm_runtime_enable(dev); 865 + ret = devm_pm_runtime_enable(dev); 866 + if (ret) 867 + return dev_err_probe(dev, ret, "Failed to enable pm_runtime\n"); 866 868 867 869 channel->phy_data = of_device_get_match_data(dev); 868 - if (!channel->phy_data) { 869 - ret = -EINVAL; 870 - goto error; 871 - } 870 + if (!channel->phy_data) 871 + return -EINVAL; 872 872 873 873 platform_set_drvdata(pdev, channel); 874 874 channel->dev = dev; 875 875 876 876 ret = rcar_gen3_phy_usb2_init_bus(channel); 877 877 if (ret) 878 - goto error; 878 + return ret; 879 879 880 880 spin_lock_init(&channel->lock); 881 881 for (i = 0; i < NUM_OF_PHYS; i++) { 882 882 channel->rphys[i].phy = devm_phy_create(dev, NULL, 883 883 channel->phy_data->phy_usb2_ops); 884 - if (IS_ERR(channel->rphys[i].phy)) { 885 - dev_err(dev, "Failed to create USB2 PHY\n"); 886 - ret = PTR_ERR(channel->rphys[i].phy); 887 - goto error; 888 - } 884 + if (IS_ERR(channel->rphys[i].phy)) 885 + return dev_err_probe(dev, PTR_ERR(channel->rphys[i].phy), 886 + "Failed to create USB2 PHY\n"); 887 + 889 888 channel->rphys[i].ch = channel; 890 889 channel->rphys[i].int_enable_bits = rcar_gen3_int_enable[i]; 891 890 phy_set_drvdata(channel->rphys[i].phy, &channel->rphys[i]); ··· 895 896 else 896 897 channel->vbus = devm_regulator_get_optional(dev, "vbus"); 897 898 if (IS_ERR(channel->vbus)) { 898 - if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) { 899 - ret = PTR_ERR(channel->vbus); 900 - goto error; 901 - } 899 + if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) 900 + return PTR_ERR(channel->vbus); 901 + 902 902 channel->vbus = NULL; 903 903 } 904 904 905 905 irq = platform_get_irq_optional(pdev, 0); 906 906 if (irq < 0 && irq != -ENXIO) { 907 - ret = irq; 908 - goto error; 907 + return irq; 909 908 } else if (irq > 0) { 910 909 INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); 911 910 ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, 912 911 IRQF_SHARED, dev_name(dev), channel); 913 - if (ret < 0) { 914 - dev_err(dev, "Failed to request irq (%d)\n", irq); 915 - goto error; 916 - } 912 + if (ret < 0) 913 + return dev_err_probe(dev, ret, 914 + "Failed to request irq (%d)\n", 915 + irq); 917 916 } 918 917 919 918 provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); 920 919 if (IS_ERR(provider)) { 921 - dev_err(dev, "Failed to register PHY provider\n"); 922 - ret = PTR_ERR(provider); 923 - goto error; 920 + return dev_err_probe(dev, PTR_ERR(provider), 921 + "Failed to register PHY provider\n"); 924 922 } else if (channel->is_otg_channel) { 925 923 ret = device_create_file(dev, &dev_attr_role); 926 924 if (ret < 0) 927 - goto error; 925 + return ret; 928 926 } 929 927 930 928 return 0; 931 - 932 - error: 933 - pm_runtime_disable(dev); 934 - 935 - return ret; 936 929 } 937 930 938 931 static void rcar_gen3_phy_usb2_remove(struct platform_device *pdev) ··· 933 942 934 943 if (channel->is_otg_channel) 935 944 device_remove_file(&pdev->dev, &dev_attr_role); 936 - 937 - pm_runtime_disable(&pdev->dev); 938 945 } 939 946 940 947 static int rcar_gen3_phy_usb2_suspend(struct device *dev)