platform/chrome: cros_usbpd_notify: Only use parent drvdata when parent is GOOG0004
Subsystems (5)
PATCH 1/1 platform/chrome: cros_usbpd_notify: Only use parent drvdata when parent is GOOG0004
cros_usbpd_notify_probe_acpi() takes the EC device pointer from dev_get_drvdata(dev->parent) and assumes it is a struct cros_ec_device. That only holds when GOOG0003 is a child of GOOG0004. On older devices without that hierarchy, such as Google Nami, GOOG0003 and GOOG0004 are siblings under the ACPI EC (PNP0C09):
PNP0C09:00 (acpi-ec)
|-- GOOG0003:00 (cros-usbpd-notify-acpi)
`-- GOOG0004:00 (cros_ec_lpcs)
Before commit db65a06d10b3 ("ACPI: EC: Convert the driver to a platform one") the parent platform device had no driver data, so the driver warned and continued without an EC pointer, as intended for these devices. Since that commit the ACPI EC driver stores its struct acpi_ec there, so the driver treats a struct acpi_ec as a struct cros_ec_device and calls cros_ec_cmd() on it for every USB-C PD host event. Plugging or unplugging a charger then intermittently oopses, followed by soft lockups and a hung system:
BUG: unable to handle page fault for address: ffffffff9cf03220 #PF: supervisor write access in kernel mode Hardware name: Google Nami/Nami, BIOS 09/19/2019 Workqueue: kacpi_notify acpi_os_execute_deferred RIP: 0010:native_queued_spin_lock_slowpath+0x29d/0x330 Call Trace: _raw_spin_lock_irqsave+0x59/0x80 __mutex_lock.constprop.0+0x129/0x930 cros_ec_cmd_xfer+0x2a/0xf0 [cros_ec_proto] cros_ec_cmd_xfer_status+0x1a/0x90 [cros_ec_proto] cros_ec_cmd+0xb7/0x140 [cros_ec_proto] cros_usbpd_get_event_and_notify+0x42/0xc0 [cros_usbpd_notify] acpi_ev_notify_dispatch+0x4e/0x70 acpi_os_execute_deferred+0x1a/0x30
Only read the parent's driver data when the parent's ACPI node is GOOG0004, and otherwise continue without an EC pointer. While at it, drop the reference taken by fwnode_get_parent().
---
Tested on a Google Nami-based Chromebook (BIOS 09/19/2019) running a 7.2.5 distro kernel (linux-omarchy 7.2.5-3). The unpatched driver oopsed twice in two days, each time on a charger plug/unplug. With this patch built as a module against that kernel, the probe logs "Couldn't get Chrome EC device pointer." (confirming GOOG0003's parent is not GOOG0004 here), and 12 charger unplug/replug cycles produced no oops, with charging negotiating 20V/3.5A as before.
Not done: I have not boot-tested a full chrome-platform for-next kernel; the change was built and run as an out-of-tree module on 7.2.5, where this function is identical apart from a comment typo fix. Only Nami hardware was tested. Because the original crash is intermittent, the clean run shows the fix doesn't regress charging rather than proving the absence of the crash; the main evidence is the probe warning above plus the oops register state (the qspinlock tail encodes CPU 74 on an 8-CPU machine, i.e. a non-lock word was being treated as a lock).
AI assistance: the crash was diagnosed and the patch and changelog were written with Claude Opus 5.5 (Claude Code), from the journal oops traces, the sysfs device hierarchy and the driver source. I reviewed the change and ran the test above.
drivers/platform/chrome/cros_usbpd_notify.c | 39 +++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-)
drivers/platform/chrome/cros_usbpd_notify.c +21 -18
@@ -110,26 +110,29 @@ static int cros_usbpd_notify_probe_acpi(struct platform_device *pdev)if (!pdnotify)return -ENOMEM ; -/* Get the EC device pointer needed to talk to the EC. */ - ec_dev =dev_get_drvdata (dev->parent); -if (!ec_dev) { -/* -* We continue even for older devices which don't have the -* correct device hierarchy, namely, GOOG0003 is a child -* of GOOG0004. If GOOG0003 is a child of GOOG0004 and we -* can't get a pointer to the Chrome EC device, defer the -* probe function. -*/ - parent_fwnode =fwnode_get_parent (dev->fwnode); -if (parent_fwnode) { - parent_adev =to_acpi_device_node (parent_fwnode); -if (parent_adev && -acpi_dev_hid_match (parent_adev,CREC_DRV_NAME )) { -return -EPROBE_DEFER ; - } +/* +* Get the EC device pointer needed to talk to the EC. The parent's +* driver data is only a struct cros_ec_device when GOOG0003 is a +* child of GOOG0004. On older devices without that hierarchy the +* parent may be bound to an unrelated driver (e.g. the ACPI EC +* driver for PNP0C09), so don't touch its driver data and continue +* without an EC pointer. If GOOG0003 is a child of GOOG0004 and we +* can't get a pointer to the Chrome EC device yet, defer the probe. +*/ + ec_dev =NULL ; + parent_fwnode =fwnode_get_parent (dev->fwnode); + parent_adev =to_acpi_device_node (parent_fwnode); +if (parent_adev &&acpi_dev_hid_match (parent_adev,CREC_DRV_NAME )) { + ec_dev =dev_get_drvdata (dev->parent); +if (!ec_dev) { +fwnode_handle_put (parent_fwnode); +return -EPROBE_DEFER ; } -dev_warn (dev,"Couldn't get Chrome EC device pointer.\n" ); } +fwnode_handle_put (parent_fwnode); + +if (!ec_dev) +dev_warn (dev,"Couldn't get Chrome EC device pointer.\n" ); pdnotify->dev = dev; pdnotify->ec = ec_dev;
Signature · 1 line
2.55.0
Tzung-Bi Shih
maintainerQuoted 3 lines · James Fairweather
Only read the parent's driver data when the parent's ACPI node is GOOG0004, and otherwise continue without an EC pointer. While at it, drop the reference taken by
fwnode_get_parent().
Because of this, I'll add "Fixes: e4ee0bb077cd ..." as well when applying the patch.
Quoted 7 lines
Tested on a Google Nami-based Chromebook (BIOS 09/19/2019) running a 7.2.5 distro kernel (linux-omarchy 7.2.5-3). The unpatched driver oopsed twice in two days, each time on a charger plug/unplug. With this patch built as a module against that kernel, the probe logs "Couldn't get Chrome EC device pointer." (confirming GOOG0003's parent is not GOOG0004 here), and 12 charger unplug/replug cycles produced no oops, with charging negotiating 20V/3.5A as before.
Hi James,
Thanks for looking into this.
Sergey Tiraspolsky ran into the same issue on a Pixelbook (Eve) and sent a patch shortly before yours [1]. However, because your patch also catches and resolves the preexisting fwnode reference leak, I plan to proceed with your patch.
When applying, I plan to credit Sergey's earlier report by adding a "Reported-by" tag. I've also CC'd Sergey and invited testing on Eve if feasible.
Quoted 3 lines · James Fairweather
Only read the parent's driver data when the parent's ACPI node is GOOG0004, and otherwise continue without an EC pointer. While at it, drop the reference taken by
fwnode_get_parent().
Tested on a 2017 Google Pixelbook (Eve), where GOOG0003 is also a child of PNP0C09, on 7.2.5 (linux-omarchy 7.2.5-3), with this patch built as an out-of-tree module. The probe prints "Couldn't get Chrome EC device pointer.", a charger unplug/replug while awake and another while suspended produced 13 USB PD notifications, all taking the "EC device inaccessible; sending 0 event status" path, the suspend resumed normally, and there were no oopses. Without a fix the same machine oopsed on charger events and on resume.
The test was set up and checked with the help of an AI coding assistant; I ran it on the hardware.
Tzung-Bi Shih
maintainerQuoted 11 lines · James Fairweather
cros_usbpd_notify_probe_acpi()takes the EC device pointer fromdev_get_drvdata(dev->parent)and assumes it is a structcros_ec_device. That only holds when GOOG0003 is a child of GOOG0004. On older devices without that hierarchy, such as Google Nami, GOOG0003 and GOOG0004 are siblings under the ACPI EC (PNP0C09):PNP0C09:00 (acpi-ec)
|-- GOOG0003:00 (cros-usbpd-notify-acpi)
`-- GOOG0004:00 (cros_ec_lpcs)[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
[1/1] platform/chrome: cros_usbpd_notify: Only use parent drvdata when parent is GOOG0004
commit: ca75b38b1a3c2eabe81d231dae4ea180cf6287cd
Thanks!
Hi James,
I wanted to report successful testing of this fix on another affected Chromebook.
Hardware:
- ASUS Chromebook C223NA (BABYMEGA, CORAL)
- Intel Apollo Lake
- Omarchy / Arch Linux, kernel 7.2.5-3-omarchy
Before the fix, disconnecting and reconnecting the USB-C charger could cause a kernel oops and leave the system unresponsive. On this machine, GOOG0003:00 has PNP0C09:00 as its parent rather than GOOG0004.
I built and loaded a locally adapted version of cros_usbpd_notify incorporating the parent-device validation and NULL fallback described in your patch.
After applying the fix:
- Six consecutive USB-C charger disconnect/reconnect cycles succeeded.
- No kernel oops or system hangs were observed.
- SSH remained responsive throughout testing.
- USB-PD negotiation reached 15V/3A (45W).
- The battery correctly reported Charging after reconnection.
The driver also produced the expected diagnostic message:
Couldn't get Chrome EC device pointer.
This was a locally adapted implementation rather than a byte-for-byte build of the submitted patch, but the results support the fix on the BABYMEGA platform as well.
Thanks for tracking this down!
David