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

serial: max310x: Use devm_clk_get_optional() to get the input clock

Simplify the code which fetches the input clock by using
devm_clk_get_optional(). If no input clock is present
devm_clk_get_optional() will return NULL instead of an error
which matches the behavior of the old code.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20201007084635.594991-2-andy.shevchenko@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
974e454d c808fab6

+15 -15
+15 -15
drivers/tty/serial/max310x.c
··· 1273 1273 struct regmap *regmap, int irq) 1274 1274 { 1275 1275 int i, ret, fmin, fmax, freq, uartclk; 1276 - struct clk *clk_osc, *clk_xtal; 1277 1276 struct max310x_port *s; 1278 1277 bool xtal = false; 1279 1278 ··· 1286 1287 return -ENOMEM; 1287 1288 } 1288 1289 1289 - clk_osc = devm_clk_get(dev, "osc"); 1290 - clk_xtal = devm_clk_get(dev, "xtal"); 1291 - if (!IS_ERR(clk_osc)) { 1292 - s->clk = clk_osc; 1290 + s->clk = devm_clk_get_optional(dev, "osc"); 1291 + if (IS_ERR(s->clk)) 1292 + return PTR_ERR(s->clk); 1293 + if (s->clk) { 1293 1294 fmin = 500000; 1294 1295 fmax = 35000000; 1295 - } else if (!IS_ERR(clk_xtal)) { 1296 - s->clk = clk_xtal; 1297 - fmin = 1000000; 1298 - fmax = 4000000; 1299 - xtal = true; 1300 - } else if (PTR_ERR(clk_osc) == -EPROBE_DEFER || 1301 - PTR_ERR(clk_xtal) == -EPROBE_DEFER) { 1302 - return -EPROBE_DEFER; 1303 1296 } else { 1304 - dev_err(dev, "Cannot get clock\n"); 1305 - return -EINVAL; 1297 + s->clk = devm_clk_get_optional(dev, "xtal"); 1298 + if (IS_ERR(s->clk)) 1299 + return PTR_ERR(s->clk); 1300 + if (s->clk) { 1301 + fmin = 1000000; 1302 + fmax = 4000000; 1303 + xtal = true; 1304 + } else { 1305 + dev_err(dev, "Cannot get clock\n"); 1306 + return -EINVAL; 1307 + } 1306 1308 } 1307 1309 1308 1310 ret = clk_prepare_enable(s->clk);