]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu: Unexport iommu_fwspec_free()
authorRobin Murphy <robin.murphy@arm.com>
Thu, 27 Feb 2025 14:47:47 +0000 (14:47 +0000)
committerJoerg Roedel <jroedel@suse.de>
Tue, 11 Mar 2025 13:05:39 +0000 (14:05 +0100)
The drivers doing their own fwspec parsing have no need to call
iommu_fwspec_free() since fwspecs were moved into dev_iommu, as
returning an error from .probe_device will tear down the whole lot
anyway. Move it into the private interface now that it only serves
for of_iommu to clean up in an error case.

I have no idea what mtk_v1 was doing in effectively guaranteeing
a NULL fwspec would be dereferenced if no "iommus" DT property was
found, so add a check for that to at least make the code look sane.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/36e245489361de2d13db22a510fa5c79e7126278.1740667667.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/iommu-priv.h
drivers/iommu/iommu.c
drivers/iommu/mtk_iommu_v1.c
drivers/iommu/tegra-smmu.c
include/linux/iommu.h

index de205a34ffc6df36c08f8db92499e6b99ba50308..ea9f8e484e3545017b4e0e6c434b73b20d304665 100644 (file)
@@ -1486,7 +1486,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
 out_cfg_free:
        kfree(cfg);
 out_free:
-       iommu_fwspec_free(dev);
        return ERR_PTR(ret);
 }
 
index b4508423e13ba0d66d33d1a4829cc5c0e445996a..fed55fbfe99cb49d6ccffa71fa36632addc15bec 100644 (file)
@@ -24,6 +24,8 @@ static inline const struct iommu_ops *iommu_fwspec_ops(struct iommu_fwspec *fwsp
        return iommu_ops_from_fwnode(fwspec ? fwspec->iommu_fwnode : NULL);
 }
 
+void iommu_fwspec_free(struct device *dev);
+
 int iommu_device_register_bus(struct iommu_device *iommu,
                              const struct iommu_ops *ops,
                              const struct bus_type *bus,
index d96cfb3af8a3f57beba59acb96f1d7f472b8859a..ac4731d13a83ef9fe7b7209412acb7d9341de449 100644 (file)
@@ -2837,7 +2837,6 @@ void iommu_fwspec_free(struct device *dev)
                dev_iommu_fwspec_set(dev, NULL);
        }
 }
-EXPORT_SYMBOL_GPL(iommu_fwspec_free);
 
 int iommu_fwspec_add_ids(struct device *dev, const u32 *ids, int num_ids)
 {
index a565b9e40f4a63184fa2931275cfffb81b217432..3e724e7f10f022f5304ef2359e1c74eec11088f2 100644 (file)
@@ -446,22 +446,13 @@ static int mtk_iommu_v1_create_mapping(struct device *dev,
 
 static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
 {
-       struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+       struct iommu_fwspec *fwspec = NULL;
        struct of_phandle_args iommu_spec;
        struct mtk_iommu_v1_data *data;
        int err, idx = 0, larbid, larbidx;
        struct device_link *link;
        struct device *larbdev;
 
-       /*
-        * In the deferred case, free the existed fwspec.
-        * Always initialize the fwspec internally.
-        */
-       if (fwspec) {
-               iommu_fwspec_free(dev);
-               fwspec = dev_iommu_fwspec_get(dev);
-       }
-
        while (!of_parse_phandle_with_args(dev->of_node, "iommus",
                                           "#iommu-cells",
                                           idx, &iommu_spec)) {
@@ -476,6 +467,9 @@ static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
                idx++;
        }
 
+       if (!fwspec)
+               return ERR_PTR(-ENODEV);
+
        data = dev_iommu_priv_get(dev);
 
        /* Link the consumer device with the smi-larb device(supplier) */
index 7f633bb5efef166b551f3d632bd221d9b5dd1bd1..69d353e1df84396350cacb6f1a5028c4f8bbba9d 100644 (file)
@@ -846,7 +846,6 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
        err = ops->of_xlate(dev, args);
        if (err < 0) {
                dev_err(dev, "failed to parse SW group ID: %d\n", err);
-               iommu_fwspec_free(dev);
                return err;
        }
 
index e93d2e918599f837529e8864873835ff7dca2b22..cf8c16ba04a08296e58ddc03662dc770cc4ec238 100644 (file)
@@ -1099,7 +1099,6 @@ struct iommu_mm_data {
 };
 
 int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode);
-void iommu_fwspec_free(struct device *dev);
 int iommu_fwspec_add_ids(struct device *dev, const u32 *ids, int num_ids);
 
 static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
@@ -1410,10 +1409,6 @@ static inline int iommu_fwspec_init(struct device *dev,
        return -ENODEV;
 }
 
-static inline void iommu_fwspec_free(struct device *dev)
-{
-}
-
 static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids,
                                       int num_ids)
 {