Skip to contentSkip to conversation

platform/x86: int3472: Check for adev == NULL

PATCH In review Hans de Goede 2 participants 5 messages Dec 9, 2024 – Dec 10, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 platform/x86: int3472: Check for adev == NULL

Not all devices have an ACPI companion fwnode, so adev might be NULL. This can e.g. (theoretically) happen when a user manually binds one of the int3472 drivers to another i2c/platform device through sysfs.

Add a check for adev not being set and return -ENODEV in that case to avoid a possible NULL pointer deref in skl_int3472_get_acpi_buffer().

---
Changes in v2:
- Improve commit message

---
 drivers/platform/x86/intel/int3472/discrete.c | 3 +++
 drivers/platform/x86/intel/int3472/tps68470.c | 3 +++
 2 files changed, 6 insertions(+)
drivers/platform/x86/intel/int3472/discrete.c +3 -0
index d881b2cfcdfc..09fff213b091 100644
@@ -336,6 +336,9 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
 	struct int3472_cldb cldb;
 	int ret;
 
+	if (!adev)
+		return -ENODEV;
+
 	ret = skl_int3472_fill_cldb(adev, &cldb);
 	if (ret) {
 		dev_err(&pdev->dev, "Couldn't fill CLDB structure\n");
drivers/platform/x86/intel/int3472/tps68470.c +3 -0
index 1e107fd49f82..81ac4c691963 100644
@@ -152,6 +152,9 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
 	int ret;
 	int i;
 
+	if (!adev)
+		return -ENODEV;
+
 	n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata);
 	if (n_consumers < 0)
 		return n_consumers;
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 2/4 platform/x86: int3472: Make "pin number mismatch" message a debug message

It seems that Windows is only using the ACPI GPIO resources and never looks at the part of the _DSM return value which encodes the pin number.

For example on a Terra Pad 1262 v2 the following messages are printend:

int3472-discrete INT3472:01: reset \_SB.GPI0 pin number mismatch _DSM 103 resource 359 int3472-discrete INT3472:01: powerdown \_SB.GPI0 pin number mismatch _DSM 207 resource 335 int3472-discrete INT3472:02: reset \_SB.GPI0 pin number mismatch _DSM 101 resource 357

Notice for the 2 reset pins that the _DSM value is off by 256, this is caused by there only being 8 bits reserved in the _DSM return value for the pin-number.

As for the powerdown pin, testing has shown that the pin-number 335 from the ACPI GPIO resource is correct and the _DSM value is bogus.

Lower the warning about these mismatches to a debug message and only look at the lower 8 bits of the GPIO resource pin numbers.

---
Changes in v2:
- Lower message to debug level instead of dropping it

---
 drivers/platform/x86/intel/int3472/discrete.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +4 -4
index 09fff213b091..6e2b81da2d68 100644
@@ -220,10 +220,10 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 	int3472_get_func_and_polarity(type, &func, &polarity);
 
 	pin = FIELD_GET(INT3472_GPIO_DSM_PIN, obj->integer.value);
-	if (pin != agpio->pin_table[0])
-		dev_warn(int3472->dev, "%s %s pin number mismatch _DSM %d resource %d\n",
-			 func, agpio->resource_source.string_ptr, pin,
-			 agpio->pin_table[0]);
+	/* Pin field is not really used under Windows and wraps around at 8 bits */
+	if (pin != (agpio->pin_table[0] & 0xff))
+		dev_dbg(int3472->dev, FW_BUG "%s %s pin number mismatch _DSM %d resource %d\n",
+			func, agpio->resource_source.string_ptr, pin, agpio->pin_table[0]);
 
 	active_value = FIELD_GET(INT3472_GPIO_DSM_SENSOR_ON_VAL, obj->integer.value);
 	if (!active_value)
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 3/4 platform/x86: int3472: Fix skl_int3472_handle_gpio_resources() return value

In reply to Hans de Goede

The INT3472 code never wants a copy of the ACPI resource to be added to the list-head passed to acpi_dev_get_resources().

Make skl_int3472_handle_gpio_resources() always return -errno or 1.

Also update the inaccurate comment about the return value. skl_int3472_handle_gpio_resources() was already returning 1 in the case of not a GPIO resource or invalid _DSM return and not -EINVAL / -ENODEV as the comment claimed.

---
Despite the "Fix" in the subject this is not really a bugfix, the old code works fine too, so no Fixes tag
---
Changes in v2:
- Keep the acpi_dev_free_resource_list() call in place

---
 drivers/platform/x86/intel/int3472/discrete.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +7 -6
index 6e2b81da2d68..31015ebe20d8 100644
@@ -178,11 +178,11 @@ static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polar
  * to create clocks and regulators via the usual frameworks.
  *
  * Return:
- * * 1		- To continue the loop
- * * 0		- When all resources found are handled properly.
- * * -EINVAL	- If the resource is not a GPIO IO resource
- * * -ENODEV	- If the resource has no corresponding _DSM entry
- * * -Other	- Errors propagated from one of the sub-functions.
+ * * 1		- Continue the loop without adding a copy of the resource to
+ * *		  the list passed to acpi_dev_get_resources()
+ * * 0		- Continue the loop after adding a copy of the resource to
+ * *		  the list passed to acpi_dev_get_resources()
+ * * -errno	- Error, break loop
  */
 static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 					     void *data)
@@ -289,7 +289,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 	if (ret < 0)
 		return dev_err_probe(int3472->dev, ret, err_msg);
 
-	return ret;
+	/* Tell acpi_dev_get_resources() to not make a copy of the resource */
+	return 1;
 }
 
 static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
Signature · 1 line
2.47.1
#3 lore raw

PATCH v2 4/4 platform/x86: int3472: Debug log the sensor name

In reply to Hans de Goede

Debug log the sensor name to make it easier to figure out which INT3472 device is associated with which sensor.

---
 drivers/platform/x86/intel/int3472/common.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/platform/x86/intel/int3472/common.c +2 -0
index b3a2578e06c1..1638be8fa71e 100644
@@ -70,6 +70,8 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
 		return -ENODEV;
 	}
 
+	dev_dbg(dev, "Sensor name %s\n", acpi_dev_name(sensor));
+
 	*name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
 				   acpi_dev_name(sensor));
 	if (!*name_ret)
Signature · 1 line
2.47.1
maintainer
#4 lore raw
In reply to Hans de Goede
Quoted 8 lines · Hans de Goede

Not all devices have an ACPI companion fwnode, so adev might be NULL. This can e.g. (theoretically) happen when a user manually binds one of the int3472 drivers to another i2c/platform device through sysfs.

Add a check for adev not being set and return -ENODEV in that case to avoid a possible NULL pointer deref in skl_int3472_get_acpi_buffer().

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/4] platform/x86: int3472: Check for adev == NULL

      commit: cd2fd6eab480dfc247b737cf7a3d6b009c4d0f1c
[2/4] platform/x86: int3472: Make "pin number mismatch" message a debug message
      commit: 1dd0cb9cabf37fbe20f0a66e4c3972cb21240aed
[3/4] platform/x86: int3472: Fix skl_int3472_handle_gpio_resources() return value
      commit: 6718d42b6eb28228a554db6c8973693ad5320006
[4/4] platform/x86: int3472: Debug log the sensor name
      commit: cc115abc1f9b55092c11c183ebff9ad921251609

--
i.