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

serial: 8250_dw: Use devm_clk_get_optional() to get the input clock

Simplify the code which fetches the input clock by using
devm_clk_get_optional(). This comes with a small functional change: previously
all errors were ignored except deferred probe. Now all errors are
treated as errors. 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 <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20190925162617.30368-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
a8afc193 254cc774

+32 -43
+32 -43
drivers/tty/serial/8250/8250_dw.c
··· 280 280 long rate; 281 281 int ret; 282 282 283 - if (IS_ERR(d->clk)) 284 - goto out; 285 - 286 283 clk_disable_unprepare(d->clk); 287 284 rate = clk_round_rate(d->clk, baud * 16); 288 285 if (rate < 0) ··· 290 293 ret = clk_set_rate(d->clk, rate); 291 294 clk_prepare_enable(d->clk); 292 295 293 - if (!ret) 294 - p->uartclk = rate; 296 + if (ret) 297 + goto out; 298 + 299 + p->uartclk = rate; 295 300 296 301 out: 297 302 p->status &= ~UPSTAT_AUTOCTS; ··· 471 472 device_property_read_u32(dev, "clock-frequency", &p->uartclk); 472 473 473 474 /* If there is separate baudclk, get the rate from it. */ 474 - data->clk = devm_clk_get(dev, "baudclk"); 475 - if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) 476 - data->clk = devm_clk_get(dev, NULL); 477 - if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) 478 - return -EPROBE_DEFER; 479 - if (!IS_ERR_OR_NULL(data->clk)) { 480 - err = clk_prepare_enable(data->clk); 481 - if (err) 482 - dev_warn(dev, "could not enable optional baudclk: %d\n", 483 - err); 484 - else 485 - p->uartclk = clk_get_rate(data->clk); 486 - } 475 + data->clk = devm_clk_get_optional(dev, "baudclk"); 476 + if (data->clk == NULL) 477 + data->clk = devm_clk_get_optional(dev, NULL); 478 + if (IS_ERR(data->clk)) 479 + return PTR_ERR(data->clk); 480 + 481 + err = clk_prepare_enable(data->clk); 482 + if (err) 483 + dev_warn(dev, "could not enable optional baudclk: %d\n", err); 484 + 485 + if (data->clk) 486 + p->uartclk = clk_get_rate(data->clk); 487 487 488 488 /* If no clock rate is defined, fail. */ 489 489 if (!p->uartclk) { ··· 491 493 goto err_clk; 492 494 } 493 495 494 - data->pclk = devm_clk_get(dev, "apb_pclk"); 495 - if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) { 496 - err = -EPROBE_DEFER; 496 + data->pclk = devm_clk_get_optional(dev, "apb_pclk"); 497 + if (IS_ERR(data->pclk)) { 498 + err = PTR_ERR(data->pclk); 497 499 goto err_clk; 498 500 } 499 - if (!IS_ERR(data->pclk)) { 500 - err = clk_prepare_enable(data->pclk); 501 - if (err) { 502 - dev_err(dev, "could not enable apb_pclk\n"); 503 - goto err_clk; 504 - } 501 + 502 + err = clk_prepare_enable(data->pclk); 503 + if (err) { 504 + dev_err(dev, "could not enable apb_pclk\n"); 505 + goto err_clk; 505 506 } 506 507 507 508 data->rst = devm_reset_control_get_optional_exclusive(dev, NULL); ··· 543 546 reset_control_assert(data->rst); 544 547 545 548 err_pclk: 546 - if (!IS_ERR(data->pclk)) 547 - clk_disable_unprepare(data->pclk); 549 + clk_disable_unprepare(data->pclk); 548 550 549 551 err_clk: 550 - if (!IS_ERR(data->clk)) 551 - clk_disable_unprepare(data->clk); 552 + clk_disable_unprepare(data->clk); 552 553 553 554 return err; 554 555 } ··· 562 567 563 568 reset_control_assert(data->rst); 564 569 565 - if (!IS_ERR(data->pclk)) 566 - clk_disable_unprepare(data->pclk); 570 + clk_disable_unprepare(data->pclk); 567 571 568 - if (!IS_ERR(data->clk)) 569 - clk_disable_unprepare(data->clk); 572 + clk_disable_unprepare(data->clk); 570 573 571 574 pm_runtime_disable(dev); 572 575 pm_runtime_put_noidle(dev); ··· 597 604 { 598 605 struct dw8250_data *data = dev_get_drvdata(dev); 599 606 600 - if (!IS_ERR(data->clk)) 601 - clk_disable_unprepare(data->clk); 607 + clk_disable_unprepare(data->clk); 602 608 603 - if (!IS_ERR(data->pclk)) 604 - clk_disable_unprepare(data->pclk); 609 + clk_disable_unprepare(data->pclk); 605 610 606 611 return 0; 607 612 } ··· 608 617 { 609 618 struct dw8250_data *data = dev_get_drvdata(dev); 610 619 611 - if (!IS_ERR(data->pclk)) 612 - clk_prepare_enable(data->pclk); 620 + clk_prepare_enable(data->pclk); 613 621 614 - if (!IS_ERR(data->clk)) 615 - clk_prepare_enable(data->clk); 622 + clk_prepare_enable(data->clk); 616 623 617 624 return 0; 618 625 }