[PATCH v3] mfd: cros_ec: Drop OF node reference in ec_device_probe()

From: Xiangwu Lai

Date: Sun Nov 22 2026 - 21:50:31 EST


ec_device_probe() calls of_find_compatible_node() only to check
whether a "google,cros-ec-ucsi" node exists in the device tree, but
the reference held by the returned node is never dropped.

Scope the lookup to the UCSI block and mark the node pointer with
__free(device_node), so that the reference is released automatically
when the block is left. Keeping the lookup inside the block also
preserves the short-circuit evaluation of the original condition:
the device tree is only walked when the EC_FEATURE_USB_PD,
EC_FEATURE_UCSI_PPM and ACPI checks already passed, instead of on
every probe of every cros_ec device.

Fixes: 17f95281839d ("mfd: cros_ec: Don't add cros_ec_ucsi if it is defined in OF or ACPI")
Suggested-by: Benson Leung <bleung@xxxxxxxxxxxx>
Reviewed-by: Benson Leung <bleung@xxxxxxxxxxxx>
Signed-off-by: Xiangwu Lai <laixiangwu@xxxxxxxxxxxxxxxxxxxx>
---

Changes in v3:
- Add the missing <linux/cleanup.h> include for __free() and fix the
continuation alignment of the mfd_add_hotplug_devices() call, as
pointed out by Tzung-Bi Shih. No functional change.

Link: https://lore.kernel.org/r/20261118062949.1250-1-laixiangwu@xxxxxxxxxxxxxxxxxxxx

drivers/mfd/cros_ec_dev.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index 529a23b80..cd1ce833a 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -6,6 +6,7 @@
*/

#include <linux/acpi.h>
+#include <linux/cleanup.h>
#include <linux/dmi.h>
#include <linux/kconfig.h>
#include <linux/mfd/core.h>
@@ -271,14 +272,20 @@ static int ec_device_probe(struct platform_device *pdev)
*/
if (cros_ec_check_features(ec, EC_FEATURE_USB_PD) &&
cros_ec_check_features(ec, EC_FEATURE_UCSI_PPM) &&
- !acpi_dev_found("GOOG0021") &&
- !of_find_compatible_node(NULL, NULL, "google,cros-ec-ucsi")) {
- retval = mfd_add_hotplug_devices(ec->dev,
- cros_ec_ucsi_cells,
- ARRAY_SIZE(cros_ec_ucsi_cells));
+ !acpi_dev_found("GOOG0021")) {
+ struct device_node *np __free(device_node) =
+ of_find_compatible_node(NULL, NULL, "google,cros-ec-ucsi");

- if (retval)
- dev_warn(ec->dev, "failed to add cros_ec_ucsi: %d\n", retval);
+ if (!np) {
+ retval = mfd_add_hotplug_devices(ec->dev,
+ cros_ec_ucsi_cells,
+ ARRAY_SIZE(cros_ec_ucsi_cells));
+
+ if (retval)
+ dev_warn(ec->dev,
+ "failed to add cros_ec_ucsi: %d\n",
+ retval);
+ }
}

/*
--
2.50.1.windows.1