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

- Subsystems: HID CORE LAYER, THE REST
- Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds
- List: linux-input
- 8 messages, 3 authors
- Page: https://ratatoskr.run/linux-input/2021/02/6280330/t

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

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-02-26 19:36:51 
- Message: https://ratatoskr.run/linux-input/2021/02/6280330.md

```text
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
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(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
index bb8c00e6be78..7225a6bc42f0 100644
--- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
+++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
@@ -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);
-- 
2.30.0

```

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

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-02-26 19:36:50 
- Message: https://ratatoskr.run/linux-input/2021/02/6280329.md

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
 drivers/hid/i2c-hid/i2c-hid-acpi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
index 7225a6bc42f0..70955f21349a 100644
--- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
+++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
@@ -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,
 };
-- 
2.30.0

```

## \[PATCH v2 4/4\] HID: i2c-hid: acpi: Drop redundant ACPI\_PTR()

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-02-26 19:36:50 
- Message: https://ratatoskr.run/linux-input/2021/02/6280331.md

```text
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: no changes
 drivers/hid/i2c-hid/i2c-hid-acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
index a4810f199d59..a6f0257a26de 100644
--- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
+++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
@@ -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

```

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

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-02-26 19:36:51 
- Message: https://ratatoskr.run/linux-input/2021/02/6280332.md

```text
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
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(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
index 70955f21349a..a4810f199d59 100644
--- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
+++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
@@ -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;
-- 
2.30.0

```

## Re: \[PATCH v2 4/4\] HID: i2c-hid: acpi: Drop redundant ACPI\_PTR()

- From: Benjamin Tissoires \<hidden\>
- Date: 2021-03-01 14:40:28 
- Message: https://ratatoskr.run/linux-input/2021/03/6281618.md

```text
Hi,

On Fri, Feb 26, 2021 at 8:34 PM Andy Shevchenko
[ref] wrote:
>
> 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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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

For the series:
Acked-by: Benjamin Tissoires <redacted>

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

> ---
> v2: no changes
>  drivers/hid/i2c-hid/i2c-hid-acpi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
> index a4810f199d59..a6f0257a26de 100644
> --- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
> +++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
> @@ -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
>

```

## Re: \[PATCH v2 4/4\] HID: i2c-hid: acpi: Drop redundant ACPI\_PTR()

- From: Jiri Kosina \<jikos@kernel.org\>
- Date: 2021-03-01 15:36:27 
- Message: https://ratatoskr.run/linux-input/2021/03/6281710.md

```text
On Mon, 1 Mar 2021, Benjamin Tissoires wrote:

> Hi,
> 
> On Fri, Feb 26, 2021 at 8:34 PM Andy Shevchenko
> [ref] wrote:
> >
> > 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.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks a lot for the series. This indeed cleans things up.

Indeed, thanks.

> For the series:
> Acked-by: Benjamin Tissoires <redacted>
> 
> 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,

-- 
Jiri Kosina
SUSE Labs

```

## Re: \[PATCH v2 4/4\] HID: i2c-hid: acpi: Drop redundant ACPI\_PTR()

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-03-01 16:21:40 
- Message: https://ratatoskr.run/linux-input/2021/03/6281747.md

```text
On Mon, Mar 01, 2021 at 04:34:41PM +0100, Jiri Kosina wrote:
> On Mon, 1 Mar 2021, Benjamin Tissoires wrote:
> > On Fri, Feb 26, 2021 at 8:34 PM Andy Shevchenko
> > [ref] wrote:
> > >
> > > 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.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Thanks a lot for the series. This indeed cleans things up.
> 
> Indeed, thanks.
> 
> > For the series:
> > Acked-by: Benjamin Tissoires <redacted>
> > 
> > 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.

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

-- 
With Best Regards,
Andy Shevchenko


```

## Re: \[PATCH v2 4/4\] HID: i2c-hid: acpi: Drop redundant ACPI\_PTR()

- From: Jiri Kosina \<jikos@kernel.org\>
- Date: 2021-03-08 09:47:06 
- Message: https://ratatoskr.run/linux-input/2021/03/6291849.md

```text
On Mon, 1 Mar 2021, Andy Shevchenko wrote:

> > > > 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.
> > > >
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > 
> > > Thanks a lot for the series. This indeed cleans things up.
> > 
> > Indeed, thanks.
> > 
> > > For the series:
> > > Acked-by: Benjamin Tissoires <redacted>
> > > 
> > > 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.
> 
> 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,

-- 
Jiri Kosina
SUSE Labs

```
