All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname
@ 2026-11-19  0:18 linux
  2026-11-19 13:20 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: linux @ 2026-11-19  0:18 UTC (permalink / raw)
  To: dave, gregkh, rafael, dakr, johan; +Cc: driver-core, Dr. David Alan Gilbert

From: "Dr. David Alan Gilbert" <linux@treblig.org>

Drivers are calling platform_get_resource_byname() with a name string
derived from a DT.  If that's a DT that's broken without the field
that should land in the name field, a NULL is passed and it OOPSs
in the strcmp.  Check for a NULL name and return NULL; turning
a crash into one broken device.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
---
 drivers/base/platform.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 3593d45f4a7a..5ef1cf79e57b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -464,6 +464,9 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
 {
 	u32 i;
 
+	if (unlikely(!name))
+		return NULL;
+
 	for (i = 0; i < dev->num_resources; i++) {
 		struct resource *r = &dev->resource[i];
 
-- 
2.56.1


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

* Re: [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname
  2026-11-19  0:18 [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname linux
@ 2026-11-19 13:20 ` Greg KH
  2026-11-19 13:37   ` Dr. David Alan Gilbert
  2026-11-19 16:13   ` Jens Glathe
  0 siblings, 2 replies; 4+ messages in thread
From: Greg KH @ 2026-11-19 13:20 UTC (permalink / raw)
  To: linux; +Cc: dave, rafael, dakr, johan, driver-core

On Thu, Nov 19, 2026 at 12:18:20AM +0000, linux@treblig.org wrote:
> From: "Dr. David Alan Gilbert" <linux@treblig.org>
> 
> Drivers are calling platform_get_resource_byname() with a name string
> derived from a DT.  If that's a DT that's broken without the field
> that should land in the name field, a NULL is passed and it OOPSs
> in the strcmp.  Check for a NULL name and return NULL; turning
> a crash into one broken device.

Nope, this is as-intended, fix the DT :)

Also:

> @@ -464,6 +464,9 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
>  {
>  	u32 i;
>  
> +	if (unlikely(!name))
> +		return NULL;

Only ever use unlikely/likely if you can measure the difference with it
not being there.  For a call like this, you can't :)

thanks,

greg k-h

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

* Re: [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname
  2026-11-19 13:20 ` Greg KH
@ 2026-11-19 13:37   ` Dr. David Alan Gilbert
  2026-11-19 16:13   ` Jens Glathe
  1 sibling, 0 replies; 4+ messages in thread
From: Dr. David Alan Gilbert @ 2026-11-19 13:37 UTC (permalink / raw)
  To: Greg KH; +Cc: rafael, dakr, johan, driver-core

* Greg KH (gregkh@linuxfoundation.org) wrote:
> On Thu, Nov 19, 2026 at 12:18:20AM +0000, linux@treblig.org wrote:
> > From: "Dr. David Alan Gilbert" <linux@treblig.org>
> > 
> > Drivers are calling platform_get_resource_byname() with a name string
> > derived from a DT.  If that's a DT that's broken without the field
> > that should land in the name field, a NULL is passed and it OOPSs
> > in the strcmp.  Check for a NULL name and return NULL; turning
> > a crash into one broken device.
> 
> Nope, this is as-intended, fix the DT :)

This makes the difference between a machine
   a) that panics and was leaving me at a black screen and
having to rely on pstore to figure out what happened (then
later once I knew the device I could then load the module later
after boot, but still then it made the module un-removable)

and
   b) something where I get reasonable errors, I can unload
the module and reload it with function tracing on and figure
out which bit of the DT to fix easily.

which given that it's just the webcam is one hell of a difference.

If your worry is that it'll just leave people shipping even more broken
DTs then perhaps a WARN would help.

It would be good to have a kernel we can actually debug.

> Also:
> 
> > @@ -464,6 +464,9 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
> >  {
> >  	u32 i;
> >  
> > +	if (unlikely(!name))
> > +		return NULL;
> 
> Only ever use unlikely/likely if you can measure the difference with it
> not being there.  For a call like this, you can't :)

OK, I was just being consistent with the check directly below it.

Dave

> thanks,
> 
> greg k-h
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/

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

* Re: [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname
  2026-11-19 13:20 ` Greg KH
  2026-11-19 13:37   ` Dr. David Alan Gilbert
@ 2026-11-19 16:13   ` Jens Glathe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Glathe @ 2026-11-19 16:13 UTC (permalink / raw)
  To: Greg KH, linux; +Cc: dave, rafael, dakr, johan, driver-core

On Thu, Nov 19, 2026 at 01:37:51PM +0000, Dr. David Alan Gilbert wrote:
 > If your worry is that it'll just leave people shipping even more broken
 > DTs then perhaps a WARN would help.

+1 for this from the aarch64 laptop corner.

Sure, fix the DT. But most of the X1E laptop DTs get written from
DSDT dumps and guesswork, and broken nodes are just part of bring-up.
No serial on these things, so an oops in some probe at boot = black
screen and digging in pstore. For a webcam.

WARN_ON_ONCE + return NULL would be loud enough to get the DT fixed
and not kill the box.

with best regards

Jens

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

end of thread, other threads:[~2026-11-19 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  0:18 [PATCH] driver core: platform: Check for NULL name in platform_get_resource_byname linux
2026-11-19 13:20 ` Greg KH
2026-11-19 13:37   ` Dr. David Alan Gilbert
2026-11-19 16:13   ` Jens Glathe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.