Hello,
Actually, I think that the of_node_put on line 598 should move to line
594. If the loop terminates normally, positions will be the loop header,
and it will not be apporpriate to call of node put on it.
julia
---------- Forwarded message ----------
Date: Mon, 25 Dec 2023 05:23:49 +0800
From: kernel test robot <[email protected]>
To: [email protected]
Cc: [email protected], Julia Lawall <[email protected]>
Subject: drivers/mtd/mtdcore.c:577:1-23: WARNING: Function
"for_each_child_of_node" should have of_node_put() before break around line
594.
BCC: [email protected]
CC: [email protected]
CC: [email protected]
TO: "Rafał Miłecki" <[email protected]>
CC: Miquel Raynal <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 861deac3b092f37b2c5e6871732f3e11486f7082
commit: 2df11f00100d7278185a9dbefa20ba3f5d32401d mtd: core: try to find OF node for every MTD partition
date: 1 year, 2 months ago
:::::: branch date: 21 hours ago
:::::: commit date: 1 year, 2 months ago
config: loongarch-randconfig-r062-20231222 (https://download.01.org/0day-ci/archive/20231225/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Julia Lawall <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
cocci warnings: (new ones prefixed by >>)
>> drivers/mtd/mtdcore.c:577:1-23: WARNING: Function "for_each_child_of_node" should have of_node_put() before break around line 594.
vim +/for_each_child_of_node +577 drivers/mtd/mtdcore.c
c4dfa25ab307a2 Alban Bedel 2018-11-13 548
ad9b10d1eaada1 Christian Marangi 2022-06-22 549 static void mtd_check_of_node(struct mtd_info *mtd)
ad9b10d1eaada1 Christian Marangi 2022-06-22 550 {
ad9b10d1eaada1 Christian Marangi 2022-06-22 551 struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
ad9b10d1eaada1 Christian Marangi 2022-06-22 552 const char *pname, *prefix = "partition-";
ad9b10d1eaada1 Christian Marangi 2022-06-22 553 int plen, mtd_name_len, offset, prefix_len;
ad9b10d1eaada1 Christian Marangi 2022-06-22 554
ad9b10d1eaada1 Christian Marangi 2022-06-22 555 /* Check if MTD already has a device node */
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 556 if (mtd_get_of_node(mtd))
ad9b10d1eaada1 Christian Marangi 2022-06-22 557 return;
ad9b10d1eaada1 Christian Marangi 2022-06-22 558
7ec4cdb321738d Tetsuo Handa 2022-07-25 559 if (!mtd_is_partition(mtd))
7ec4cdb321738d Tetsuo Handa 2022-07-25 560 return;
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 561
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 562 parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
ad9b10d1eaada1 Christian Marangi 2022-06-22 563 if (!parent_dn)
ad9b10d1eaada1 Christian Marangi 2022-06-22 564 return;
ad9b10d1eaada1 Christian Marangi 2022-06-22 565
2df11f00100d72 Rafał Miłecki 2022-10-04 566 if (mtd_is_partition(mtd->parent))
2df11f00100d72 Rafał Miłecki 2022-10-04 567 partitions = of_node_get(parent_dn);
2df11f00100d72 Rafał Miłecki 2022-10-04 568 else
ad9b10d1eaada1 Christian Marangi 2022-06-22 569 partitions = of_get_child_by_name(parent_dn, "partitions");
ad9b10d1eaada1 Christian Marangi 2022-06-22 570 if (!partitions)
ad9b10d1eaada1 Christian Marangi 2022-06-22 571 goto exit_parent;
ad9b10d1eaada1 Christian Marangi 2022-06-22 572
ad9b10d1eaada1 Christian Marangi 2022-06-22 573 prefix_len = strlen(prefix);
ad9b10d1eaada1 Christian Marangi 2022-06-22 574 mtd_name_len = strlen(mtd->name);
ad9b10d1eaada1 Christian Marangi 2022-06-22 575
ad9b10d1eaada1 Christian Marangi 2022-06-22 576 /* Search if a partition is defined with the same name */
ad9b10d1eaada1 Christian Marangi 2022-06-22 @577 for_each_child_of_node(partitions, mtd_dn) {
ad9b10d1eaada1 Christian Marangi 2022-06-22 578 /* Skip partition with no/wrong prefix */
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 579 if (!of_node_name_prefix(mtd_dn, prefix))
ad9b10d1eaada1 Christian Marangi 2022-06-22 580 continue;
ad9b10d1eaada1 Christian Marangi 2022-06-22 581
ad9b10d1eaada1 Christian Marangi 2022-06-22 582 /* Label have priority. Check that first */
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 583 if (!of_property_read_string(mtd_dn, "label", &pname)) {
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 584 offset = 0;
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 585 } else {
c5f5d0cd40e3bc Rafał Miłecki 2022-10-04 586 pname = mtd_dn->name;
ad9b10d1eaada1 Christian Marangi 2022-06-22 587 offset = prefix_len;
ad9b10d1eaada1 Christian Marangi 2022-06-22 588 }
ad9b10d1eaada1 Christian Marangi 2022-06-22 589
ad9b10d1eaada1 Christian Marangi 2022-06-22 590 plen = strlen(pname) - offset;
ad9b10d1eaada1 Christian Marangi 2022-06-22 591 if (plen == mtd_name_len &&
ad9b10d1eaada1 Christian Marangi 2022-06-22 592 !strncmp(mtd->name, pname + offset, plen)) {
2df11f00100d72 Rafał Miłecki 2022-10-04 593 mtd_set_of_node(mtd, mtd_dn);
ad9b10d1eaada1 Christian Marangi 2022-06-22 @594 break;
ad9b10d1eaada1 Christian Marangi 2022-06-22 595 }
ad9b10d1eaada1 Christian Marangi 2022-06-22 596 }
ad9b10d1eaada1 Christian Marangi 2022-06-22 597
ad9b10d1eaada1 Christian Marangi 2022-06-22 598 of_node_put(partitions);
ad9b10d1eaada1 Christian Marangi 2022-06-22 599 exit_parent:
ad9b10d1eaada1 Christian Marangi 2022-06-22 600 of_node_put(parent_dn);
ad9b10d1eaada1 Christian Marangi 2022-06-22 601 }
ad9b10d1eaada1 Christian Marangi 2022-06-22 602
:::::: The code at line 577 was first introduced by commit
:::::: ad9b10d1eaada169bd764abcab58f08538877e26 mtd: core: introduce of support for dynamic partitions
:::::: TO: Christian Marangi <[email protected]>
:::::: CC: Miquel Raynal <[email protected]>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki