The implementation-specific subclassing of struct arm_smmu_device really
wanted an appropriate version of realloc(). Now that one exists, take
full advantage of it to clarify what's actually being done here.

Signed-off-by: Robin Murphy <robin.mur...@arm.com>
---
 drivers/iommu/arm/arm-smmu/arm-smmu-impl.c   |  5 +----
 drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c | 17 +----------------
 drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c   |  5 +----
 3 files changed, 3 insertions(+), 24 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c 
b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c
index 88f17cc33023..336f36ed9ed7 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c
@@ -91,15 +91,12 @@ static struct arm_smmu_device *cavium_smmu_impl_init(struct 
arm_smmu_device *smm
 {
        struct cavium_smmu *cs;
 
-       cs = devm_kzalloc(smmu->dev, sizeof(*cs), GFP_KERNEL);
+       cs = devm_krealloc(smmu->dev, smmu, sizeof(*cs), GFP_KERNEL);
        if (!cs)
                return ERR_PTR(-ENOMEM);
 
-       cs->smmu = *smmu;
        cs->smmu.impl = &cavium_impl;
 
-       devm_kfree(smmu->dev, smmu);
-
        return &cs->smmu;
 }
 
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c 
b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
index 31368057e9be..29117444e5a0 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
@@ -242,18 +242,10 @@ struct arm_smmu_device *nvidia_smmu_impl_init(struct 
arm_smmu_device *smmu)
        struct nvidia_smmu *nvidia_smmu;
        struct platform_device *pdev = to_platform_device(dev);
 
-       nvidia_smmu = devm_kzalloc(dev, sizeof(*nvidia_smmu), GFP_KERNEL);
+       nvidia_smmu = devm_krealloc(dev, smmu, sizeof(*nvidia_smmu), 
GFP_KERNEL);
        if (!nvidia_smmu)
                return ERR_PTR(-ENOMEM);
 
-       /*
-        * Copy the data from struct arm_smmu_device *smmu allocated in
-        * arm-smmu.c. The smmu from struct nvidia_smmu replaces the smmu
-        * pointer used in arm-smmu.c once this function returns.
-        * This is necessary to derive nvidia_smmu from smmu pointer passed
-        * through arm_smmu_impl function calls subsequently.
-        */
-       nvidia_smmu->smmu = *smmu;
        /* Instance 0 is ioremapped by arm-smmu.c. */
        nvidia_smmu->bases[0] = smmu->base;
 
@@ -267,12 +259,5 @@ struct arm_smmu_device *nvidia_smmu_impl_init(struct 
arm_smmu_device *smmu)
 
        nvidia_smmu->smmu.impl = &nvidia_smmu_impl;
 
-       /*
-        * Free the struct arm_smmu_device *smmu allocated in arm-smmu.c.
-        * Once this function returns, arm-smmu.c would use arm_smmu_device
-        * allocated as part of struct nvidia_smmu.
-        */
-       devm_kfree(dev, smmu);
-
        return &nvidia_smmu->smmu;
 }
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c 
b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
index be4318044f96..600670588521 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
@@ -69,14 +69,11 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct 
arm_smmu_device *smmu)
 {
        struct qcom_smmu *qsmmu;
 
-       qsmmu = devm_kzalloc(smmu->dev, sizeof(*qsmmu), GFP_KERNEL);
+       qsmmu = devm_krealloc(smmu->dev, smmu, sizeof(*qsmmu), GFP_KERNEL);
        if (!qsmmu)
                return ERR_PTR(-ENOMEM);
 
-       qsmmu->smmu = *smmu;
-
        qsmmu->smmu.impl = &qcom_smmu_impl;
-       devm_kfree(smmu->dev, smmu);
 
        return &qsmmu->smmu;
 }
-- 
2.28.0.dirty

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to