linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: fsl-mc: Check return value of platform_get_resource()
@ 2025-07-24  9:11 Salah Triki
  2025-07-27 16:24 ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Salah Triki @ 2025-07-24  9:11 UTC (permalink / raw)
  To: Ioana Ciornei, linuxppc-dev, linux-kernel; +Cc: salah.triki

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.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 7671bd158545..980d427e857f 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bus: fsl-mc: Check return value of platform_get_resource()
  2025-07-24  9:11 [PATCH] bus: fsl-mc: Check return value of platform_get_resource() Salah Triki
@ 2025-07-27 16:24 ` Markus Elfring
  2025-08-25  6:21   ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2025-07-27 16:24 UTC (permalink / raw)
  To: Salah Triki, linuxppc-dev, Ioana Ciornei; +Cc: LKML

> 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> +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
> @@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bus: fsl-mc: Check return value of platform_get_resource()
  2025-07-27 16:24 ` Markus Elfring
@ 2025-08-25  6:21   ` Christophe Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2025-08-25  6:21 UTC (permalink / raw)
  To: Markus Elfring, Salah Triki, linuxppc-dev, Ioana Ciornei; +Cc: LKML



Le 27/07/2025 à 18:24, Markus Elfring a écrit :
>> 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")

> 
> …
>> +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
>> @@ -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 ?

> …
> 
> I suggest to omit a blank line before the if statement.
> 
> Regards,
> Markus
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-25  6:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24  9:11 [PATCH] bus: fsl-mc: Check return value of platform_get_resource() Salah Triki
2025-07-27 16:24 ` Markus Elfring
2025-08-25  6:21   ` Christophe Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).