Skip to content

Commit dcb40e9

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Add platform_device_put for recovering the device refcnt
Add platform_device_put to match with of_find_device_by_node. Meanwhile, I add a new variable "pcommdev" which is for smi common device. Otherwise, "platform_device_put(plarbdev)" for smi-common dev may be not readable. And add a checking for whether pcommdev is NULL. Fixes: d2e9a11 ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3cd0e4a commit dcb40e9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10551055
struct mtk_iommu_data *data)
10561056
{
10571057
struct device_node *larbnode, *smicomm_node, *smi_subcomm_node;
1058-
struct platform_device *plarbdev;
1058+
struct platform_device *plarbdev, *pcommdev;
10591059
struct device_link *link;
10601060
int i, larb_nr, ret;
10611061

@@ -1086,12 +1086,14 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10861086
}
10871087
if (!plarbdev->dev.driver) {
10881088
of_node_put(larbnode);
1089+
platform_device_put(plarbdev);
10891090
return -EPROBE_DEFER;
10901091
}
10911092
data->larb_imu[id].dev = &plarbdev->dev;
10921093

10931094
component_match_add_release(dev, match, component_release_of,
10941095
component_compare_of, larbnode);
1096+
platform_device_put(plarbdev);
10951097
}
10961098

10971099
/* Get smi-(sub)-common dev from the last larb. */
@@ -1109,12 +1111,15 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
11091111
else
11101112
smicomm_node = smi_subcomm_node;
11111113

1112-
plarbdev = of_find_device_by_node(smicomm_node);
1114+
pcommdev = of_find_device_by_node(smicomm_node);
11131115
of_node_put(smicomm_node);
1114-
data->smicomm_dev = &plarbdev->dev;
1116+
if (!pcommdev)
1117+
return -ENODEV;
1118+
data->smicomm_dev = &pcommdev->dev;
11151119

11161120
link = device_link_add(data->smicomm_dev, dev,
11171121
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
1122+
platform_device_put(pcommdev);
11181123
if (!link) {
11191124
dev_err(dev, "Unable to link %s.\n", dev_name(data->smicomm_dev));
11201125
return -EINVAL;

0 commit comments

Comments
 (0)