git: 17ebd95594cd - main - acpi_iicbus: Return _DSD properties of the I2C children

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Mon, 23 Nov 2026 23:50:48 UTC
The branch main has been updated by olivier:

URL: https://cgit.FreeBSD.org/src/commit/?id=17ebd95594cd106b73cc9422ba86245e0bf5ab99

commit 17ebd95594cd106b73cc9422ba86245e0bf5ab99
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-21 17:29:07 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-23 23:45:39 +0000

    acpi_iicbus: Return _DSD properties of the I2C children
    
    acpi_iicbus has no bus_get_property method, so device_get_property()
    on one of its children reaches acpi(4) through
    bus_generic_get_property().  acpi_bus_get_prop() then takes the
    child's acpi_iicbus ivars for a struct acpi_device and follows garbage
    pointers: on an HP ZBook Ultra G1a, a driver reading _DSD of its I2C
    device froze the machine.
    
    Answer for the I2C children from their own ACPI handle, with a _DSD
    cache in the ivars, through a helper split out of acpi_bus_get_prop().
    
    Reviewed by:    wulf, imp
    Approved by:    wulf, imp
    MFC after:      1 week
    Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/117
---
 sys/dev/acpica/acpi.c        | 26 ++++++++++++++++++++++----
 sys/dev/acpica/acpivar.h     |  3 +++
 sys/dev/iicbus/acpi_iicbus.c | 21 +++++++++++++++++++++
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index 993203c5caab..f63373ee06f9 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -168,6 +168,8 @@ static int	acpi_isa_get_compatid(device_t dev, uint32_t *cids, int count);
 static ACPI_STATUS acpi_device_scan_cb(ACPI_HANDLE h, UINT32 level,
 		    void *context, void **retval);
 static ACPI_STATUS acpi_find_dsd(struct acpi_device *ad);
+static ACPI_STATUS acpi_ad_get_prop(struct acpi_device *ad,
+		    const char *propname, const ACPI_OBJECT **value);
 static void	acpi_platform_osc(device_t dev);
 static void	acpi_probe_children(device_t bus);
 static void	acpi_probe_order(ACPI_HANDLE handle, int *order);
@@ -1999,14 +2001,18 @@ acpi_device_eval_obj(device_t bus, device_t dev, const char *pathname,
 static ACPI_STATUS
 acpi_device_get_prop(device_t bus, device_t dev, const char *propname,
     const ACPI_OBJECT **value)
+{
+	return (acpi_ad_get_prop(device_get_ivars(dev), propname, value));
+}
+
+static ACPI_STATUS
+acpi_ad_get_prop(struct acpi_device *ad, const char *propname,
+    const ACPI_OBJECT **value)
 {
 	const ACPI_OBJECT *pkg, *name, *val;
-	struct acpi_device *ad;
 	ACPI_STATUS status;
 	int i;
 
-	ad = device_get_ivars(dev);
-
 	if (ad == NULL || propname == NULL)
 		return (AE_BAD_PARAMETER);
 	if (ad->dsd_pkg == NULL) {
@@ -2102,11 +2108,23 @@ err:
 static ssize_t
 acpi_bus_get_prop(device_t bus, device_t child, const char *propname,
     void *propvalue, size_t size, device_property_type_t type)
+{
+	return (acpi_ad_get_property(device_get_ivars(child), propname,
+	    propvalue, size, type));
+}
+
+/*
+ * Return a _DSD property of the device described by ad, for buses whose
+ * children are ACPI devices but whose ivars are not a struct acpi_device.
+ */
+ssize_t
+acpi_ad_get_property(struct acpi_device *ad, const char *propname,
+    void *propvalue, size_t size, device_property_type_t type)
 {
 	ACPI_STATUS status;
 	const ACPI_OBJECT *obj;
 
-	status = acpi_device_get_prop(bus, child, propname, &obj);
+	status = acpi_ad_get_prop(ad, propname, &obj);
 	if (ACPI_FAILURE(status))
 		return (-1);
 
diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h
index 66050662853c..7dfdc2e600c5 100644
--- a/sys/dev/acpica/acpivar.h
+++ b/sys/dev/acpica/acpivar.h
@@ -508,6 +508,9 @@ acpi_d_state_to_str(int state)
 char		*acpi_name(ACPI_HANDLE handle);
 int		acpi_avoid(ACPI_HANDLE handle);
 int		acpi_disabled(char *subsys);
+ssize_t		acpi_ad_get_property(struct acpi_device *ad,
+		    const char *propname, void *propvalue, size_t size,
+		    device_property_type_t type);
 int		acpi_get_acpi_device_path(device_t bus, device_t child,
 		    const char *locator, struct sbuf *sb);
 int		acpi_machdep_init(device_t dev);
diff --git a/sys/dev/iicbus/acpi_iicbus.c b/sys/dev/iicbus/acpi_iicbus.c
index ffad1bfb9be7..5bee1fccd56c 100644
--- a/sys/dev/iicbus/acpi_iicbus.c
+++ b/sys/dev/iicbus/acpi_iicbus.c
@@ -73,6 +73,7 @@ struct acpi_iicbus_softc {
 struct acpi_iicbus_ivars {
 	struct iicbus_ivar	super_ivar;
 	ACPI_HANDLE		handle;
+	struct acpi_device	ad;	/* _DSD cache */
 };
 
 static int install_space_handler = 1;
@@ -674,9 +675,28 @@ acpi_iicbus_child_deleted(device_t bus, device_t child)
 		return;
 	if (acpi_get_device(devi->handle) == child)
 		AcpiDetachData(devi->handle, acpi_fake_objhandler);
+	if (devi->ad.dsd.Pointer != NULL)
+		AcpiOsFree(devi->ad.dsd.Pointer);
 	iicbus_child_deleted(bus, child);
 }
 
+static ssize_t
+acpi_iicbus_get_property(device_t bus, device_t child, const char *propname,
+    void *propvalue, size_t size, device_property_type_t type)
+{
+	struct acpi_iicbus_ivars *devi;
+
+	/* Deeper devices do not carry our ivars. */
+	if (device_get_parent(child) != bus)
+		return (-1);
+	devi = device_get_ivars(child);
+	if (devi->handle == NULL)
+		return (-1);
+	devi->ad.ad_handle = devi->handle;
+	return (acpi_ad_get_property(&devi->ad, propname, propvalue, size,
+	    type));
+}
+
 static int
 acpi_iicbus_read_ivar(device_t bus, device_t child, int which, uintptr_t *res)
 {
@@ -768,6 +788,7 @@ static device_method_t acpi_iicbus_methods[] = {
 	DEVMETHOD(bus_child_location,	acpi_iicbus_child_location),
 	DEVMETHOD(bus_child_pnpinfo,	acpi_iicbus_child_pnpinfo),
 	DEVMETHOD(bus_get_device_path,	acpi_get_acpi_device_path),
+	DEVMETHOD(bus_get_property,	acpi_iicbus_get_property),
 
 	DEVMETHOD_END,
 };