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

serial: sccnxp: Disable regulator on error

The patch disables the regulator in case of errors, if we have it.
In addition, the patch adds support for deferred regulator probe and
makes error path are a bit clean.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexander Shiyan and committed by
Greg Kroah-Hartman
e087ab74 3fc1eb5f

+18 -22
+18 -22
drivers/tty/serial/sccnxp.c
··· 787 787 struct sccnxp_port *s; 788 788 void __iomem *membase; 789 789 790 - if (!res) { 791 - dev_err(&pdev->dev, "Missing memory resource data\n"); 792 - return -EADDRNOTAVAIL; 793 - } 790 + membase = devm_ioremap_resource(&pdev->dev, res); 791 + if (IS_ERR(membase)) 792 + return PTR_ERR(membase); 794 793 795 794 s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL); 796 795 if (!s) { ··· 884 885 break; 885 886 default: 886 887 dev_err(&pdev->dev, "Unsupported chip type %i\n", chiptype); 887 - ret = -ENOTSUPP; 888 - goto err_out; 888 + return -ENOTSUPP; 889 889 } 890 + 891 + s->regulator = devm_regulator_get(&pdev->dev, "vcc"); 892 + if (!IS_ERR(s->regulator)) { 893 + ret = regulator_enable(s->regulator); 894 + if (ret) { 895 + dev_err(&pdev->dev, 896 + "Failed to enable regulator: %i\n", ret); 897 + return ret; 898 + } 899 + } else if (PTR_ERR(s->regulator) == -EPROBE_DEFER) 900 + return -EPROBE_DEFER; 890 901 891 902 if (!pdata) { 892 903 dev_warn(&pdev->dev, ··· 925 916 (s->pdata.frequency > freq_max)) { 926 917 dev_err(&pdev->dev, "Frequency out of bounds\n"); 927 918 ret = -EINVAL; 928 - goto err_out; 929 - } 930 - 931 - s->regulator = devm_regulator_get(&pdev->dev, "VCC"); 932 - if (!IS_ERR(s->regulator)) { 933 - ret = regulator_enable(s->regulator); 934 - if (ret) { 935 - dev_err(&pdev->dev, 936 - "Failed to enable regulator: %i\n", ret); 937 - return ret; 938 - } 939 - } 940 - 941 - membase = devm_ioremap_resource(&pdev->dev, res); 942 - if (IS_ERR(membase)) { 943 - ret = PTR_ERR(membase); 944 919 goto err_out; 945 920 } 946 921 ··· 990 997 } 991 998 992 999 err_out: 1000 + if (!IS_ERR(s->regulator)) 1001 + return regulator_disable(s->regulator); 1002 + 993 1003 return ret; 994 1004 } 995 1005