Re: [PATCH v3 2/3] iommu/tegra-smmu: Rework .probe_device and .attach_dev
From: Dmitry Osipenko
Date: Wed Sep 30 2020 - 10:41:47 EST
...
> + struct tegra_mc *mc = devm_tegra_get_memory_controller(dev);
> + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
>
> - of_node_put(args.np);
> - index++;
> - }
> + /* An invalid mc pointer means mc and smmu drivers are not ready */
> + if (IS_ERR(mc))
> + return ERR_PTR(-EPROBE_DEFER);
>
> - if (!smmu)
> + /*
> + * IOMMU core allows -ENODEV return to carry on. So bypass any call
> + * from bus_set_iommu() during tegra_smmu_probe(), as a device will
> + * call in again via of_iommu_configure when fwspec is prepared.
> + */
> + if (!mc->smmu || !fwspec || fwspec->ops != &tegra_smmu_ops)
> return ERR_PTR(-ENODEV);
>
> - return &smmu->iommu;
> + dev_iommu_priv_set(dev, mc->smmu);
> +
> + return &mc->smmu->iommu;
> }
Is it really okay to use devm_tegra_get_memory_controller() here?
I assume it should be more preferred to do it only for devices that have
fwspec->ops == &tegra_smmu_ops.
Secondly, it also looks to me that a non-devm variant should be more
appropriate here because tegra_smmu_probe_device() isn't invoked by the
devices themselves.