In cros_usbpd_notify_remove_acpi(), ACPI_COMPANION() may return NULL
in certain scenarios. Directly dereferencing adev->handle without
checking could lead to a kernel oops.
Add a NULL check and emit a warning when no ACPI companion is found,
then skip the notify handler removal to ensure safety.
Cc: stable@vger.kernel.org
Fixes: 7e91e1ac60bb ("platform/chrome: cros_usbpd_notify: Amend ACPI driver to plat")
Signed-off-by: Wang Jun <1742789905@qq.com>
---
drivers/platform/chrome/cros_usbpd_notify.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c
index c90174360004..cb3e59eada9e 100644
--- a/drivers/platform/chrome/cros_usbpd_notify.c
+++ b/drivers/platform/chrome/cros_usbpd_notify.c
@@ -153,6 +153,10 @@ static void cros_usbpd_notify_remove_acpi(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct acpi_device *adev = ACPI_COMPANION(dev);
+ if (!adev) {
+ dev_warn(dev, "No ACPI companion found\n");
+ return;
+ }
acpi_remove_notify_handler(adev->handle, ACPI_ALL_NOTIFY,
cros_usbpd_notify_acpi);
}
--
2.43.0