Linux USB
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Saranya Gopal <saranya.gopal@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chen Yu <yu.c.chen@intel.com>
Subject: [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated
Date: Tue, 12 Sep 2023 00:27:06 +0800	[thread overview]
Message-ID: <20230911162706.2856910-1-yu.c.chen@intel.com> (raw)

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


             reply	other threads:[~2023-09-11 21:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 16:27 Chen Yu [this message]
2023-09-11 18:59 ` [PATCH] usb: typec: ucsi: Release debugfs only if it has been allocated Greg Kroah-Hartman
2023-09-12 15:00   ` Chen Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230911162706.2856910-1-yu.c.chen@intel.com \
    --to=yu.c.chen@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=saranya.gopal@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox