iommu/arm-smmu: Use new devm_krealloc()
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.murphy@arm.com> Link: https://lore.kernel.org/r/355e8d70c7f47d462d85b386aa09f2b5c655f023.1603713428.git.robin.murphy@arm.com Signed-off-by: Will Deacon <will@kernel.org>
This commit is contained in:
Родитель
f9081b8ff5
Коммит
af9da91493
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -159,14 +159,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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче