Skip to contentSkip to conversation

iommu/qcom: Fix local_base status check

PATCH Markus Elfring 1 participant 2 messages Apr 19, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

The function qcom_iommu_device_probe() does not perform sufficient error checking after executing devm_ioremap_resource(), which can result in crashes if a critical error path is encountered.

Your update suggestion will be rechecked once more.

* Can it be that the patch would need a higher version number according to previous review comments?

* Would you like to adjust the patch subject?

…

Review static int qcom_iommu_device_probe(struct platform_device *pdev) · line 816

Quoted 6 lines

+++ b/drivers/iommu/qcom_iommu.c

(quoted diff) +0 -1
@@ -813,8 +813,11 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	qcom_iommu->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (res)

I find the deletion of this check appropriate.

Review static int qcom_iommu_device_probe(struct platform_device *pdev) · line 817

Quoted 2 lines
(quoted diff) +1 -0
+	if (res) {
 		qcom_iommu->local_base = devm_ioremap_resource(dev, res);

But I do not see a need to preserve such a check because this function performs input parameter validation.
https://elixir.bootlin.com/linux/v5.7-rc1/source/lib/devres.c#L116
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/devres.c?id=50cc09c18985eacbbd666acfd7be2391394733f5#n116

Please take another look at a corresponding usage example.

Regards,
Markus

#1 lore raw
Quoted 6 lines

…

Quoted 5 lines

+++ b/drivers/iommu/qcom_iommu.c

(quoted diff) +0 -0
@@ -813,8 +813,11 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	qcom_iommu->dev = dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

…

Quoted 1 line
Quoted 1 line

qcom_iommu->local_base = devm_ioremap_resource(dev, res);

…

Quoted 1 line

Please take another look at a corresponding usage example.

I would like to point another possibility out for desirable software evolution. How do you think about to call a “known” wrapper function instead?

devm_platform_get_and_ioremap_resource
https://elixir.bootlin.com/linux/v5.7-rc1/source/drivers/base/platform.c#L66
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/drivers/base/platform.c

Regards,
Markus