Skip to content

Commit 305f254

Browse files
macpaul-lin-mtkstorulf
authored andcommitted
pmdomain: mtk-pm-domains: Fix spinlock recursion fix in probe
Remove scpsys_get_legacy_regmap(), replacing its usage with of_find_node_with_property(). Explicitly call of_node_get(np) before each of_find_node_with_property() to maintain correct node reference counting. The of_find_node_with_property() function "consumes" its input by calling of_node_put() internally, whether or not it finds a match. Currently, dev->of_node (np) is passed multiple times in sequence without incrementing its reference count, causing it to be decremented multiple times and risking early memory release. Adding of_node_get(np) before each call balances the reference count, preventing premature node release. Fixes: c1bac49 ("pmdomains: mtk-pm-domains: Fix spinlock recursion in probe") Cc: stable@vger.kernel.org Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com> Tested-by: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent f8f9c1f commit 305f254

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

drivers/pmdomain/mediatek/mtk-pm-domains.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -984,18 +984,6 @@ static void scpsys_domain_cleanup(struct scpsys *scpsys)
984984
}
985985
}
986986

987-
static struct device_node *scpsys_get_legacy_regmap(struct device_node *np, const char *pn)
988-
{
989-
struct device_node *local_node;
990-
991-
for_each_child_of_node(np, local_node) {
992-
if (of_property_present(local_node, pn))
993-
return local_node;
994-
}
995-
996-
return NULL;
997-
}
998-
999987
static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *scpsys)
1000988
{
1001989
const u8 bp_blocks[3] = {
@@ -1017,7 +1005,8 @@ static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
10171005
* this makes it then possible to allocate the array of bus_prot
10181006
* regmaps and convert all to the new style handling.
10191007
*/
1020-
node = scpsys_get_legacy_regmap(np, "mediatek,infracfg");
1008+
of_node_get(np);
1009+
node = of_find_node_with_property(np, "mediatek,infracfg");
10211010
if (node) {
10221011
regmap[0] = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg");
10231012
of_node_put(node);
@@ -1030,7 +1019,8 @@ static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
10301019
regmap[0] = NULL;
10311020
}
10321021

1033-
node = scpsys_get_legacy_regmap(np, "mediatek,smi");
1022+
of_node_get(np);
1023+
node = of_find_node_with_property(np, "mediatek,smi");
10341024
if (node) {
10351025
smi_np = of_parse_phandle(node, "mediatek,smi", 0);
10361026
of_node_put(node);
@@ -1048,7 +1038,8 @@ static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
10481038
regmap[1] = NULL;
10491039
}
10501040

1051-
node = scpsys_get_legacy_regmap(np, "mediatek,infracfg-nao");
1041+
of_node_get(np);
1042+
node = of_find_node_with_property(np, "mediatek,infracfg-nao");
10521043
if (node) {
10531044
regmap[2] = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao");
10541045
num_regmaps++;

0 commit comments

Comments
 (0)