drivers/clk/mediatek/clk-mtk.c:575 mtk_clk_simple_probe() warn: 'base' from of_iomap() not released on lines: 496.

From: Dan Carpenter
Date: Wed Mar 15 2023 - 04:14:54 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fc89d7fb499b0162e081f434d45e8d1b47e82ece
commit: 7b6183108c8ccf0dc295f39cdf78bd8078455636 clk: mediatek: clk-mtk: Extend mtk_clk_simple_probe()
config: openrisc-randconfig-m031-20230313 (https://download.01.org/0day-ci/archive/20230314/202303142331.mAJDR88r-lkp@xxxxxxxxx/config)
compiler: or1k-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Link: https://lore.kernel.org/r/202303142331.mAJDR88r-lkp@xxxxxxxxx/

New smatch warnings:
drivers/clk/mediatek/clk-mtk.c:575 mtk_clk_simple_probe() warn: 'base' from of_iomap() not released on lines: 496.

Old smatch warnings:
drivers/clk/mediatek/clk-mtk.c:573 mtk_clk_simple_probe() error: uninitialized symbol 'base'.

vim +/base +575 drivers/clk/mediatek/clk-mtk.c

c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 466 int mtk_clk_simple_probe(struct platform_device *pdev)
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 467 {
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 468 const struct mtk_clk_desc *mcd;
609cc5e1a82394 Chen-Yu Tsai 2022-05-19 469 struct clk_hw_onecell_data *clk_data;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 470 struct device_node *node = pdev->dev.of_node;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 471 void __iomem *base;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 472 int num_clks, r;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 473
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 474 mcd = of_device_get_match_data(&pdev->dev);
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 475 if (!mcd)
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 476 return -EINVAL;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 477
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 478 /* Composite clocks needs us to pass iomem pointer */
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 479 if (mcd->composite_clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 480 if (!mcd->shared_io)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 481 base = devm_platform_ioremap_resource(pdev, 0);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 482 else
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 483 base = of_iomap(node, 0);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 484
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 485 if (IS_ERR_OR_NULL(base))
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 486 return IS_ERR(base) ? PTR_ERR(base) : -ENOMEM;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 487 }
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 488
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 489 /* Calculate how many clk_hw_onecell_data entries to allocate */
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 490 num_clks = mcd->num_clks + mcd->num_composite_clks;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 491 num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 492 num_clks += mcd->num_mux_clks;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 493
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 494 clk_data = mtk_alloc_clk_data(num_clks);
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 495 if (!clk_data)
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 496 return -ENOMEM;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 497
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 498 if (mcd->fixed_clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 499 r = mtk_clk_register_fixed_clks(mcd->fixed_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 500 mcd->num_fixed_clks, clk_data);
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 501 if (r)
6203815bf97eea Chun-Jie Chen 2021-09-14 502 goto free_data;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 503 }
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 504
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 505 if (mcd->factor_clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 506 r = mtk_clk_register_factors(mcd->factor_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 507 mcd->num_factor_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 508 if (r)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 509 goto unregister_fixed_clks;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 510 }
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 511
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 512 if (mcd->mux_clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 513 r = mtk_clk_register_muxes(&pdev->dev, mcd->mux_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 514 mcd->num_mux_clks, node,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 515 mcd->clk_lock, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 516 if (r)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 517 goto unregister_factors;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 518 };
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 519
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 520 if (mcd->composite_clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 521 /* We don't check composite_lock because it's optional */
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 522 r = mtk_clk_register_composites(&pdev->dev,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 523 mcd->composite_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 524 mcd->num_composite_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 525 base, mcd->clk_lock, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 526 if (r)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 527 goto unregister_muxes;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 528 }
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 529
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 530 if (mcd->clks) {
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 531 r = mtk_clk_register_gates(&pdev->dev, node, mcd->clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 532 mcd->num_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 533 if (r)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 534 goto unregister_composites;
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 535 }
6203815bf97eea Chun-Jie Chen 2021-09-14 536
609cc5e1a82394 Chen-Yu Tsai 2022-05-19 537 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
6203815bf97eea Chun-Jie Chen 2021-09-14 538 if (r)
2d18b7e31aa804 Chen-Yu Tsai 2022-02-08 539 goto unregister_clks;
6203815bf97eea Chun-Jie Chen 2021-09-14 540
2204d96b191912 Chen-Yu Tsai 2022-02-08 541 platform_set_drvdata(pdev, clk_data);
2204d96b191912 Chen-Yu Tsai 2022-02-08 542
b27a604a579310 Rex-BC Chen 2022-05-23 543 if (mcd->rst_desc) {
b27a604a579310 Rex-BC Chen 2022-05-23 544 r = mtk_register_reset_controller_with_dev(&pdev->dev,
b27a604a579310 Rex-BC Chen 2022-05-23 545 mcd->rst_desc);
b27a604a579310 Rex-BC Chen 2022-05-23 546 if (r)
b27a604a579310 Rex-BC Chen 2022-05-23 547 goto unregister_clks;
b27a604a579310 Rex-BC Chen 2022-05-23 548 }
b27a604a579310 Rex-BC Chen 2022-05-23 549
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 550 return r;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 551
2d18b7e31aa804 Chen-Yu Tsai 2022-02-08 552 unregister_clks:
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 553 if (mcd->clks)
2d18b7e31aa804 Chen-Yu Tsai 2022-02-08 554 mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 555 unregister_composites:
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 556 if (mcd->composite_clks)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 557 mtk_clk_unregister_composites(mcd->composite_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 558 mcd->num_composite_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 559 unregister_muxes:
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 560 if (mcd->mux_clks)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 561 mtk_clk_unregister_muxes(mcd->mux_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 562 mcd->num_mux_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 563 unregister_factors:
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 564 if (mcd->factor_clks)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 565 mtk_clk_unregister_factors(mcd->factor_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 566 mcd->num_factor_clks, clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 567 unregister_fixed_clks:
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 568 if (mcd->fixed_clks)
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 569 mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 570 mcd->num_fixed_clks, clk_data);
6203815bf97eea Chun-Jie Chen 2021-09-14 571 free_data:
6203815bf97eea Chun-Jie Chen 2021-09-14 572 mtk_free_clk_data(clk_data);
7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 573 if (mcd->shared_io && base)

"base" is either valid or uninitialized. Perhaps:

- if (mcd->shared_io && base)
+ if (mcd->composite_clks && mcd->shared_io)


7b6183108c8ccf AngeloGioacchino Del Regno 2023-01-20 574 iounmap(base);
6203815bf97eea Chun-Jie Chen 2021-09-14 @575 return r;
c58cd0e40ffac6 Chun-Jie Chen 2021-07-26 576 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests