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

serial: sccnxp: Fix error handling in sccnxp_probe()

sccnxp_probe() returns result of regulator_disable() that may lead
to returning zero, while device is not properly initialized.
Also the driver enables clocks, but it does not disable it.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexey Khoroshilov and committed by
Greg Kroah-Hartman
c9126143 9d7ee0e2

+11 -2
+11 -2
drivers/tty/serial/sccnxp.c
··· 889 889 goto err_out; 890 890 uartclk = 0; 891 891 } else { 892 - clk_prepare_enable(clk); 892 + ret = clk_prepare_enable(clk); 893 + if (ret) 894 + goto err_out; 895 + 896 + ret = devm_add_action_or_reset(&pdev->dev, 897 + (void(*)(void *))clk_disable_unprepare, 898 + clk); 899 + if (ret) 900 + goto err_out; 901 + 893 902 uartclk = clk_get_rate(clk); 894 903 } 895 904 ··· 997 988 uart_unregister_driver(&s->uart); 998 989 err_out: 999 990 if (!IS_ERR(s->regulator)) 1000 - return regulator_disable(s->regulator); 991 + regulator_disable(s->regulator); 1001 992 1002 993 return ret; 1003 994 }