Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated
@ 2023-09-11 16:27 Chen Yu
  2023-09-11 18:59 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Yu @ 2023-09-11 16:27 UTC (permalink / raw)
  To: Heikki Krogerus, Andy Shevchenko, Saranya Gopal
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Chen Yu

The following NULL pointer exception was found during boot up:

 calling  ucsi_acpi_platform_driver_init+0x0/0xff0 [ucsi_acpi] @ 394
 initcall mac_hid_init+0x0/0xff0 [mac_hid] returned 0 after 5 usecs
 BUG: kernel NULL pointer dereference, address: 0000000000000020
 Call Trace:
  ? ucsi_debugfs_unregister+0x15/0x30 [typec_ucsi]
  ucsi_destroy+0x17/0x30 [typec_ucsi]
  ucsi_acpi_probe+0x1d5/0x230 [ucsi_acpi]

It is possible that ucsi_acpi_probe() fails to install the notifier,
and calls ucsi_destroy() to release the resource. However at that
moment the debugfs has not been registered yet, thus the NULL pointer
exception is triggered. Add the check for debugfs pointer.

Fixes: Commit df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
 drivers/usb/typec/ucsi/debugfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
index 0c7bf88d4a7f..55533dc3d539 100644
--- a/drivers/usb/typec/ucsi/debugfs.c
+++ b/drivers/usb/typec/ucsi/debugfs.c
@@ -84,7 +84,8 @@ void ucsi_debugfs_register(struct ucsi *ucsi)
 
 void ucsi_debugfs_unregister(struct ucsi *ucsi)
 {
-	debugfs_remove_recursive(ucsi->debugfs->dentry);
+	if (ucsi->debugfs)
+		debugfs_remove_recursive(ucsi->debugfs->dentry);
 	kfree(ucsi->debugfs);
 }
 
-- 
2.25.1


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

* Re: [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated
  2023-09-11 16:27 [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated Chen Yu
@ 2023-09-11 18:59 ` Greg Kroah-Hartman
  2023-09-12 15:00   ` Chen Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-09-11 18:59 UTC (permalink / raw)
  To: Chen Yu
  Cc: Heikki Krogerus, Andy Shevchenko, Saranya Gopal, linux-usb,
	linux-kernel

On Tue, Sep 12, 2023 at 12:27:06AM +0800, Chen Yu wrote:
> The following NULL pointer exception was found during boot up:
> 
>  calling  ucsi_acpi_platform_driver_init+0x0/0xff0 [ucsi_acpi] @ 394
>  initcall mac_hid_init+0x0/0xff0 [mac_hid] returned 0 after 5 usecs
>  BUG: kernel NULL pointer dereference, address: 0000000000000020
>  Call Trace:
>   ? ucsi_debugfs_unregister+0x15/0x30 [typec_ucsi]
>   ucsi_destroy+0x17/0x30 [typec_ucsi]
>   ucsi_acpi_probe+0x1d5/0x230 [ucsi_acpi]
> 
> It is possible that ucsi_acpi_probe() fails to install the notifier,
> and calls ucsi_destroy() to release the resource. However at that
> moment the debugfs has not been registered yet, thus the NULL pointer
> exception is triggered. Add the check for debugfs pointer.
> 
> Fixes: Commit df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")

Incorrect format :(

> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> ---
>  drivers/usb/typec/ucsi/debugfs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
> index 0c7bf88d4a7f..55533dc3d539 100644
> --- a/drivers/usb/typec/ucsi/debugfs.c
> +++ b/drivers/usb/typec/ucsi/debugfs.c
> @@ -84,7 +84,8 @@ void ucsi_debugfs_register(struct ucsi *ucsi)
>  
>  void ucsi_debugfs_unregister(struct ucsi *ucsi)
>  {
> -	debugfs_remove_recursive(ucsi->debugfs->dentry);
> +	if (ucsi->debugfs)
> +		debugfs_remove_recursive(ucsi->debugfs->dentry);
>  	kfree(ucsi->debugfs);
>  }

What's wrong with this patch instead:
	https://lore.kernel.org/all/20230906084842.1922052-1-heikki.krogerus@linux.intel.com/

thanks,

greg k-h

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

* Re: [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated
  2023-09-11 18:59 ` Greg Kroah-Hartman
@ 2023-09-12 15:00   ` Chen Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chen Yu @ 2023-09-12 15:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Heikki Krogerus, Andy Shevchenko, Saranya Gopal, linux-usb,
	linux-kernel

Hi Greg,

thanks for your time,

On 2023-09-11 at 20:59:18 +0200, Greg Kroah-Hartman wrote:
> On Tue, Sep 12, 2023 at 12:27:06AM +0800, Chen Yu wrote:
> > The following NULL pointer exception was found during boot up:
> > 
> >  calling  ucsi_acpi_platform_driver_init+0x0/0xff0 [ucsi_acpi] @ 394
> >  initcall mac_hid_init+0x0/0xff0 [mac_hid] returned 0 after 5 usecs
> >  BUG: kernel NULL pointer dereference, address: 0000000000000020
> >  Call Trace:
> >   ? ucsi_debugfs_unregister+0x15/0x30 [typec_ucsi]
> >   ucsi_destroy+0x17/0x30 [typec_ucsi]
> >   ucsi_acpi_probe+0x1d5/0x230 [ucsi_acpi]
> > 
> > It is possible that ucsi_acpi_probe() fails to install the notifier,
> > and calls ucsi_destroy() to release the resource. However at that
> > moment the debugfs has not been registered yet, thus the NULL pointer
> > exception is triggered. Add the check for debugfs pointer.
> > 
> > Fixes: Commit df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")
> 
> Incorrect format :(
>

Ah, the 'Commit' was incorrectly added.

> > Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> > ---
> >  drivers/usb/typec/ucsi/debugfs.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
> > index 0c7bf88d4a7f..55533dc3d539 100644
> > --- a/drivers/usb/typec/ucsi/debugfs.c
> > +++ b/drivers/usb/typec/ucsi/debugfs.c
> > @@ -84,7 +84,8 @@ void ucsi_debugfs_register(struct ucsi *ucsi)
> >  
> >  void ucsi_debugfs_unregister(struct ucsi *ucsi)
> >  {
> > -	debugfs_remove_recursive(ucsi->debugfs->dentry);
> > +	if (ucsi->debugfs)
> > +		debugfs_remove_recursive(ucsi->debugfs->dentry);
> >  	kfree(ucsi->debugfs);
> >  }
> 
> What's wrong with this patch instead:
> 	https://lore.kernel.org/all/20230906084842.1922052-1-heikki.krogerus@linux.intel.com/
>

Thanks for this link, I'll patch my kernel using above version.

thanks,
Chenyu

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

end of thread, other threads:[~2023-09-12 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 16:27 [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated Chen Yu
2023-09-11 18:59 ` Greg Kroah-Hartman
2023-09-12 15:00   ` Chen Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox