Skip to contentSkip to conversation

HID: i2c-hid: acpi: Get ACPI companion only once and reuse it

PATCH Applied Andy Shevchenko 3 participants 8 messages Feb 26, 2021 – Mar 8, 2021 HID

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 HID: i2c-hid: acpi: Get ACPI companion only once and reuse it

Currently the ACPI companion and handle are retrieved and checked a few times in different functions. Instead get ACPI companion only once and reuse it everywhere.

---
v2: used companion indeed everywhere (i2c_hid_acpi_shutdown_tail() included)

 drivers/hid/i2c-hid/i2c-hid-acpi.c | 36 +++++++++++++-----------------
 1 file changed, 16 insertions(+), 20 deletions(-)
drivers/hid/i2c-hid/i2c-hid-acpi.c +16 -20
index bb8c00e6be78..7225a6bc42f0 100644
@@ -30,7 +30,7 @@
 
 struct i2c_hid_acpi {
 	struct i2chid_ops ops;
-	struct i2c_client *client;
+	struct acpi_device *adev;
 };
 
 static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
@@ -42,29 +42,22 @@ static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
 	{ },
 };
 
-static int i2c_hid_acpi_get_descriptor(struct i2c_client *client)
+static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
 {
 	static guid_t i2c_hid_guid =
 		GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
 			  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
+	acpi_handle handle = acpi_device_handle(adev);
 	union acpi_object *obj;
-	struct acpi_device *adev;
-	acpi_handle handle;
 	u16 hid_descriptor_address;
 
-	handle = ACPI_HANDLE(&client->dev);
-	if (!handle || acpi_bus_get_device(handle, &adev)) {
-		dev_err(&client->dev, "Error could not get ACPI device\n");
-		return -ENODEV;
-	}
-
 	if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
 		return -ENODEV;
 
 	obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
 				      ACPI_TYPE_INTEGER);
 	if (!obj) {
-		dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n");
+		acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
 		return -ENODEV;
 	}
 
@@ -76,10 +69,9 @@ static int i2c_hid_acpi_get_descriptor(struct i2c_client *client)
 
 static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
 {
-	struct i2c_hid_acpi *ihid_acpi =
-		container_of(ops, struct i2c_hid_acpi, ops);
-	struct device *dev = &ihid_acpi->client->dev;
-	acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD);
+	struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
+
+	acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
 }
 
 static int i2c_hid_acpi_probe(struct i2c_client *client,
@@ -91,21 +83,25 @@ static int i2c_hid_acpi_probe(struct i2c_client *client,
 	u16 hid_descriptor_address;
 	int ret;
 
+	adev = ACPI_COMPANION(dev);
+	if (!adev) {
+		dev_err(&client->dev, "Error could not get ACPI device\n");
+		return -ENODEV;
+	}
+
 	ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
 	if (!ihid_acpi)
 		return -ENOMEM;
 
-	ihid_acpi->client = client;
+	ihid_acpi->adev = adev;
 	ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
 
-	ret = i2c_hid_acpi_get_descriptor(client);
+	ret = i2c_hid_acpi_get_descriptor(adev);
 	if (ret < 0)
 		return ret;
 	hid_descriptor_address = ret;
 
-	adev = ACPI_COMPANION(dev);
-	if (adev)
-		acpi_device_fix_up_power(adev);
+	acpi_device_fix_up_power(adev);
 
 	if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
 		device_set_wakeup_capable(dev, true);
Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 2/4 HID: i2c-hid: acpi: Switch to new style i2c-driver probe function

Switch to the new style i2c-driver probe_new probe function.

---
v2: new patch

 drivers/hid/i2c-hid/i2c-hid-acpi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/i2c-hid/i2c-hid-acpi.c +2 -3
index 7225a6bc42f0..70955f21349a 100644
@@ -74,8 +74,7 @@ static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
 	acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
 }
 
-static int i2c_hid_acpi_probe(struct i2c_client *client,
-			      const struct i2c_device_id *dev_id)
+static int i2c_hid_acpi_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct i2c_hid_acpi *ihid_acpi;
@@ -127,7 +126,7 @@ static struct i2c_driver i2c_hid_acpi_driver = {
 		.acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
 	},
 
-	.probe		= i2c_hid_acpi_probe,
+	.probe_new	= i2c_hid_acpi_probe,
 	.remove		= i2c_hid_core_remove,
 	.shutdown	= i2c_hid_core_shutdown,
 };
Signature · 1 line
2.30.0
#3 lore raw

PATCH v2 4/4 HID: i2c-hid: acpi: Drop redundant ACPI_PTR()

In reply to Andy Shevchenko

The driver depends on ACPI, ACPI_PTR() resolution is always the same. Otherwise a compiler may produce a warning.

That said, the rule of thumb either ugly ifdeffery with ACPI_PTR or none should be used in a driver.

---
v2: no changes

 drivers/hid/i2c-hid/i2c-hid-acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid-acpi.c +1 -1
index a4810f199d59..a6f0257a26de 100644
@@ -126,7 +126,7 @@ static struct i2c_driver i2c_hid_acpi_driver = {
 		.name	= "i2c_hid_acpi",
 		.pm	= &i2c_hid_core_pm,
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
-		.acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
+		.acpi_match_table = i2c_hid_acpi_match,
 	},
 
 	.probe_new	= i2c_hid_acpi_probe,
Signature · 1 line
2.30.0
#2 lore raw

PATCH v2 3/4 HID: i2c-hid: acpi: Move GUID out of function and described it

In reply to Andy Shevchenko

Move static GUID variable out of the function and add a comment how it looks like in the human readable representation.

While at it, include uuid.h since the guid_t type is defined in it.

---
v2: rebased on top of patch 1 that used to be separate change

 drivers/hid/i2c-hid/i2c-hid-acpi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/hid/i2c-hid/i2c-hid-acpi.c +6 -3
index 70955f21349a..a4810f199d59 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pm.h>
+#include <linux/uuid.h>
 
 #include "i2c-hid.h"
 
@@ -42,11 +43,13 @@ static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
 	{ },
 };
 
+/* HID I²C Device: 3cdff6f7-4267-4555-ad05-b30a3d8938de */
+static guid_t i2c_hid_guid =
+	GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
+		  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
+
 static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
 {
-	static guid_t i2c_hid_guid =
-		GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
-			  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
 	acpi_handle handle = acpi_device_handle(adev);
 	union acpi_object *obj;
 	u16 hid_descriptor_address;
Signature · 1 line
2.30.0
Acked-by on v2 4/4
#4 lore raw

Re: [PATCH v2 4/4] HID: i2c-hid: acpi: Drop redundant ACPI_PTR()

In reply to Andy Shevchenko

Hi,

Quoted 8 lines · Andy Shevchenko

The driver depends on ACPI, ACPI_PTR() resolution is always the same. Otherwise a compiler may produce a warning.

That said, the rule of thumb either ugly ifdeffery with ACPI_PTR or none should be used in a driver.

Thanks a lot for the series. This indeed cleans things up.

For the series:

Jiri, I wonder where we want to land this one. This is not strictly bug fixes, but we could definitively sneak this one in 5.12-rc1. Well, I should probably run the series on an acpi laptop here before merging, but I'd like to know if delaying to 5.13 is OK or if we need this in 5.12.

Cheers,
Benjamin

Quoted 21 lines

---
v2: no changes

 drivers/hid/i2c-hid/i2c-hid-acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid-acpi.c +1 -2
index a4810f199d59..a6f0257a26de 100644
@@ -126,7 +126,7 @@ static struct i2c_driver i2c_hid_acpi_driver = {
                .name   = "i2c_hid_acpi",
                .pm     = &i2c_hid_core_pm,
                .probe_type = PROBE_PREFER_ASYNCHRONOUS,
-               .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
+               .acpi_match_table = i2c_hid_acpi_match,
        },
 
        .probe_new      = i2c_hid_acpi_probe,
--

2.30.0

maintainer
#5 lore raw

Re: [PATCH v2 4/4] HID: i2c-hid: acpi: Drop redundant ACPI_PTR()

Quoted 8 lines · Benjamin Tissoires

Hi,

Quoted 4 lines · Andy Shevchenko

The driver depends on ACPI, ACPI_PTR() resolution is always the same. Otherwise a compiler may produce a warning.

Quoted 6 lines
Quoted 4 lines

That said, the rule of thumb either ugly ifdeffery with ACPI_PTR or none should be used in a driver.

Thanks a lot for the series. This indeed cleans things up.

Indeed, thanks.

Quoted 8 lines

For the series:

Jiri, I wonder where we want to land this one. This is not strictly bug fixes, but we could definitively sneak this one in 5.12-rc1. Well, I should probably run the series on an acpi laptop here before merging, but I'd like to know if delaying to 5.13 is OK or if we need this in 5.12.

I'd like to do it the standard way and have it bake in for-next to see if it really doesn't break anything, so unless there are convicing arguments for 5.12-rcX, I'd rathre queue this for 5.13.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#6 lore raw

Re: [PATCH v2 4/4] HID: i2c-hid: acpi: Drop redundant ACPI_PTR()

Quoted 25 lines · Jiri Kosina
Quoted 6 lines · Benjamin Tissoires
Quoted 4 lines · Andy Shevchenko

The driver depends on ACPI, ACPI_PTR() resolution is always the same. Otherwise a compiler may produce a warning.

Quoted 6 lines
Quoted 4 lines

That said, the rule of thumb either ugly ifdeffery with ACPI_PTR or none should be used in a driver.

Thanks a lot for the series. This indeed cleans things up.

Indeed, thanks.

Quoted 8 lines

For the series:

Jiri, I wonder where we want to land this one. This is not strictly bug fixes, but we could definitively sneak this one in 5.12-rc1. Well, I should probably run the series on an acpi laptop here before merging, but I'd like to know if delaying to 5.13 is OK or if we need this in 5.12.

Quoted 3 lines

I'd like to do it the standard way and have it bake in for-next to see if it really doesn't break anything, so unless there are convicing arguments for 5.12-rcX, I'd rathre queue this for 5.13.

For the record, I'm not in hurry with this, up to you how to proceed. Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#7 lore raw

Re: [PATCH v2 4/4] HID: i2c-hid: acpi: Drop redundant ACPI_PTR()

Quoted 21 lines · Andy Shevchenko
Quoted 21 lines
Quoted 9 lines
Quoted 7 lines

The driver depends on ACPI, ACPI_PTR() resolution is always the same. Otherwise a compiler may produce a warning.

That said, the rule of thumb either ugly ifdeffery with ACPI_PTR or none should be used in a driver.

Thanks a lot for the series. This indeed cleans things up.

Indeed, thanks.

Quoted 8 lines

For the series:

Jiri, I wonder where we want to land this one. This is not strictly bug fixes, but we could definitively sneak this one in 5.12-rc1. Well, I should probably run the series on an acpi laptop here before merging, but I'd like to know if delaying to 5.13 is OK or if we need this in 5.12.

Quoted 6 lines
Quoted 3 lines

I'd like to do it the standard way and have it bake in for-next to see if it really doesn't break anything, so unless there are convicing arguments for 5.12-rcX, I'd rathre queue this for 5.13.

For the record, I'm not in hurry with this, up to you how to proceed. Thanks!

Queued in for-5.13/i2c-hid. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs