iommu/mediatek: Add platform_device_put for recovering the device refcnt
authorYong Wu <yong.wu@mediatek.com>
Tue, 18 Oct 2022 02:42:53 +0000 (10:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:51 +0000 (13:32 +0100)
[ Upstream commit dcb40e9fcce9bd251eaff19f3724131db522846c ]

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: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE")
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
Link: https://lore.kernel.org/r/20221018024258.19073-2-yong.wu@mediatek.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/mtk_iommu.c

index 2d14dc846b8392894892e26bc5b0c3a5d2f53756..febcca8fcbcff56c7b2a11e2d00925ae2c0bc353 100644 (file)
@@ -1044,7 +1044,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
                                  struct mtk_iommu_data *data)
 {
        struct device_node *larbnode, *smicomm_node, *smi_subcomm_node;
-       struct platform_device *plarbdev;
+       struct platform_device *plarbdev, *pcommdev;
        struct device_link *link;
        int i, larb_nr, ret;
 
@@ -1075,12 +1075,14 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
                }
                if (!plarbdev->dev.driver) {
                        of_node_put(larbnode);
+                       platform_device_put(plarbdev);
                        return -EPROBE_DEFER;
                }
                data->larb_imu[id].dev = &plarbdev->dev;
 
                component_match_add_release(dev, match, component_release_of,
                                            component_compare_of, larbnode);
+               platform_device_put(plarbdev);
        }
 
        /* Get smi-(sub)-common dev from the last larb. */
@@ -1098,12 +1100,15 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
        else
                smicomm_node = smi_subcomm_node;
 
-       plarbdev = of_find_device_by_node(smicomm_node);
+       pcommdev = of_find_device_by_node(smicomm_node);
        of_node_put(smicomm_node);
-       data->smicomm_dev = &plarbdev->dev;
+       if (!pcommdev)
+               return -ENODEV;
+       data->smicomm_dev = &pcommdev->dev;
 
        link = device_link_add(data->smicomm_dev, dev,
                               DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
+       platform_device_put(pcommdev);
        if (!link) {
                dev_err(dev, "Unable to link %s.\n", dev_name(data->smicomm_dev));
                return -EINVAL;