Skip to contentSkip to conversation

bus: fsl-mc: Check return value of platform_get_resource()

PATCH Superseded Salah Triki 3 participants 3 messages Jul 24, 2025 – Aug 25, 2025 QorIQ DPAA2 fsl-mc bus driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: fsl-mc: Check return value of platform_get_resource()

platform_get_resource() returns NULL in case of failure, so check its return value and propagate the error in order to prevent NULL pointer dereference.

---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bus/fsl-mc/fsl-mc-bus.c +4 -0
index 7671bd158545..980d427e857f 100644
@@ -1105,6 +1105,10 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
 	 * Get physical address of MC portal for the root DPRC:
 	 */
 	plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	if (!plat_res)
+		return -ENODEV;
+
 	mc_portal_phys_addr = plat_res->start;
 	mc_portal_size = resource_size(plat_res);
 	mc_portal_base_phys_addr = mc_portal_phys_addr & ~0x3ffffff;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 3 lines

platform_get_resource() returns NULL in case of failure, so check its return value and propagate the error in order to prevent NULL pointer dereference.

How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc7#n145

…

drivers/bus/fsl-mc/fsl-mc-bus.c static int fsl_mc_bus_probe(struct platform_device *pdev) · line 1110

Quoted 8 lines

+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c

drivers/bus/fsl-mc/fsl-mc-bus.c +3 -0
@@ -1105,6 +1105,10 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
 	 * Get physical address of MC portal for the root DPRC:
 	 */
 	plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	if (!plat_res)
+		return -ENODEV;

…

I suggest to omit a blank line before the if statement.

Regards,
Markus

#2 lore raw

Le 27/07/2025 à 18:24, Markus Elfring a écrit :

Quoted 7 lines
Quoted 3 lines

platform_get_resource() returns NULL in case of failure, so check its return value and propagate the error in order to prevent NULL pointer dereference.

How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc7#n145

Fixes 6305166c8771 ("bus: fsl-mc: Add ACPI support for fsl-mc")
Quoted 10 lines

…

drivers/bus/fsl-mc/fsl-mc-bus.c static int fsl_mc_bus_probe(struct platform_device *pdev) · line 1110

Quoted 8 lines

+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c

drivers/bus/fsl-mc/fsl-mc-bus.c +3 -0
@@ -1105,6 +1105,10 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
  	 * Get physical address of MC portal for the root DPRC:
  	 */
  	plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	if (!plat_res)
+		return -ENODEV;

Before the blame commit, of_address_to_resource() was used and of_address_to_resource() returns -EINVAL in case no resource is found. Should we keep the same return instead of ENODEV ?

Quoted 8 lines

…

I suggest to omit a blank line before the if statement.

Regards,
Markus