2023-10-23 05:36:44

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 0/6] Refine _UID references across kernel

This series refines _UID references across kernel by:

- Extracting _UID matching functionality from acpi_dev_hid_uid_match()
helper and introducing it as a separate acpi_dev_uid_match() helper.

- Converting manual _UID references to use the standard ACPI helpers.

Changes since v1:
- Change acpi_dev_uid_match() to return false in case of NULL argument.
- Drop accepted patches.

Raag Jadav (6):
ACPI: utils: Introduce acpi_dev_uid_match() for matching _UID
pinctrl: intel: use acpi_dev_uid_match() for matching _UID
ACPI: utils: use acpi_dev_uid_match() for matching _UID
ACPI: x86: use acpi_dev_uid_match() for matching _UID
hwmon: nct6775: use acpi_dev_hid_uid_match() for matching _HID and
_UID
perf: arm_cspmu: use acpi_dev_hid_uid_match() for matching _HID and
_UID

drivers/acpi/utils.c | 34 ++++++++++++++++++++++-----
drivers/acpi/x86/utils.c | 3 +--
drivers/hwmon/nct6775-platform.c | 4 +---
drivers/perf/arm_cspmu/arm_cspmu.c | 8 +++----
drivers/pinctrl/intel/pinctrl-intel.c | 2 +-
include/acpi/acpi_bus.h | 1 +
include/linux/acpi.h | 5 ++++
7 files changed, 40 insertions(+), 17 deletions(-)


base-commit: 64b6555f2fe6b43fb6782aa3e2cbb34bfe39047d
--
2.17.1


2023-10-23 05:36:51

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 2/6] pinctrl: intel: use acpi_dev_uid_match() for matching _UID

Convert manual _UID references to use the standard ACPI helper.

Signed-off-by: Raag Jadav <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/intel/pinctrl-intel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 3be04ab760d3..999f453344d2 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1694,7 +1694,7 @@ const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_
unsigned int i;

for (i = 0; table[i]; i++) {
- if (!strcmp(adev->pnp.unique_id, table[i]->uid)) {
+ if (acpi_dev_uid_match(adev, table[i]->uid)) {
data = table[i];
break;
}
--
2.17.1

2023-10-23 05:36:57

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 4/6] ACPI: x86: use acpi_dev_uid_match() for matching _UID

Convert manual _UID references to use the standard ACPI helper.

Signed-off-by: Raag Jadav <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
drivers/acpi/x86/utils.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c
index 63d834dd3811..bc65ebfcdf76 100644
--- a/drivers/acpi/x86/utils.c
+++ b/drivers/acpi/x86/utils.c
@@ -184,8 +184,7 @@ bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *s
if (acpi_match_device_ids(adev, override_status_ids[i].hid))
continue;

- if (!adev->pnp.unique_id ||
- strcmp(adev->pnp.unique_id, override_status_ids[i].uid))
+ if (!acpi_dev_uid_match(adev, override_status_ids[i].uid))
continue;
}

--
2.17.1

2023-10-23 05:36:59

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 3/6] ACPI: utils: use acpi_dev_uid_match() for matching _UID

Convert manual _UID references to use the standard ACPI helper.

Signed-off-by: Raag Jadav <[email protected]>
---
drivers/acpi/utils.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index be21b77059af..28c75242fca9 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -942,8 +942,7 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
if (acpi_match_device_ids(adev, match->hid))
return 0;

- if (match->uid && (!adev->pnp.unique_id ||
- strcmp(adev->pnp.unique_id, match->uid)))
+ if (match->uid && !acpi_dev_uid_match(adev, match->uid))
return 0;

if (match->hrv == -1)
--
2.17.1

2023-10-23 05:37:06

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 5/6] hwmon: nct6775: use acpi_dev_hid_uid_match() for matching _HID and _UID

Convert manual _UID references to use the standard ACPI helper.

Signed-off-by: Raag Jadav <[email protected]>
---
drivers/hwmon/nct6775-platform.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/hwmon/nct6775-platform.c b/drivers/hwmon/nct6775-platform.c
index 81bf03dad6bb..0adeeab7ee03 100644
--- a/drivers/hwmon/nct6775-platform.c
+++ b/drivers/hwmon/nct6775-platform.c
@@ -1465,10 +1465,8 @@ static const char * const asus_msi_boards[] = {
static int nct6775_asuswmi_device_match(struct device *dev, void *data)
{
struct acpi_device *adev = to_acpi_device(dev);
- const char *uid = acpi_device_uid(adev);
- const char *hid = acpi_device_hid(adev);

- if (hid && !strcmp(hid, ASUSWMI_DEVICE_HID) && uid && !strcmp(uid, data)) {
+ if (acpi_dev_hid_uid_match(adev, ASUSWMI_DEVICE_HID, data)) {
asus_acpi_dev = adev;
return 1;
}
--
2.17.1

2023-10-23 05:37:11

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 1/6] ACPI: utils: Introduce acpi_dev_uid_match() for matching _UID

Introduce acpi_dev_uid_match() helper that matches the device with
supplied _UID string.

Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Raag Jadav <[email protected]>
---
drivers/acpi/utils.c | 31 +++++++++++++++++++++++++++----
include/acpi/acpi_bus.h | 1 +
include/linux/acpi.h | 5 +++++
3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 79915d4a0031..be21b77059af 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -824,20 +824,43 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
}
EXPORT_SYMBOL(acpi_check_dsm);

+/**
+ * acpi_dev_uid_match - Match device by supplied UID
+ * @adev: ACPI device to match.
+ * @uid2: Unique ID of the device.
+ *
+ * Matches UID in @adev with given @uid2.
+ *
+ * Returns:
+ * - %true if matches.
+ * - %false otherwise.
+ */
+bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
+{
+ const char *uid1 = acpi_device_uid(adev);
+
+ return uid1 && uid2 && !strcmp(uid1, uid2);
+}
+EXPORT_SYMBOL_GPL(acpi_dev_uid_match);
+
/**
* acpi_dev_hid_uid_match - Match device by supplied HID and UID
* @adev: ACPI device to match.
* @hid2: Hardware ID of the device.
* @uid2: Unique ID of the device, pass NULL to not check _UID.
*
- * Matches HID and UID in @adev with given @hid2 and @uid2.
- * Returns true if matches.
+ * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
+ * will be treated as a match. If user wants to validate @uid2, it should be
+ * done before calling this function.
+ *
+ * Returns:
+ * - %true if matches or @uid2 is NULL.
+ * - %false otherwise.
*/
bool acpi_dev_hid_uid_match(struct acpi_device *adev,
const char *hid2, const char *uid2)
{
const char *hid1 = acpi_device_hid(adev);
- const char *uid1 = acpi_device_uid(adev);

if (strcmp(hid1, hid2))
return false;
@@ -845,7 +868,7 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev,
if (!uid2)
return true;

- return uid1 && !strcmp(uid1, uid2);
+ return acpi_dev_uid_match(adev, uid2);
}
EXPORT_SYMBOL(acpi_dev_hid_uid_match);

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 756b3f3c2c45..afeed6e72049 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -763,6 +763,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
}

+bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2);
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index afd94c9b8b8a..db3a33e19c97 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -787,6 +787,11 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)

struct acpi_device;

+static inline bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
+{
+ return false;
+}
+
static inline bool
acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2)
{
--
2.17.1

2023-10-23 05:37:27

by Raag Jadav

[permalink] [raw]
Subject: [PATCH v2 6/6] perf: arm_cspmu: use acpi_dev_hid_uid_match() for matching _HID and _UID

Convert manual _UID references to use the standard ACPI helpers.

Signed-off-by: Raag Jadav <[email protected]>
---
drivers/perf/arm_cspmu/arm_cspmu.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/arm_cspmu/arm_cspmu.c b/drivers/perf/arm_cspmu/arm_cspmu.c
index e2b7827c4563..f0e6d14281d6 100644
--- a/drivers/perf/arm_cspmu/arm_cspmu.c
+++ b/drivers/perf/arm_cspmu/arm_cspmu.c
@@ -1061,7 +1061,7 @@ static int arm_cspmu_request_irq(struct arm_cspmu *cspmu)

static inline int arm_cspmu_find_cpu_container(int cpu, u32 container_uid)
{
- u32 acpi_uid;
+ u64 acpi_uid;
struct device *cpu_dev;
struct acpi_device *acpi_dev;

@@ -1071,10 +1071,8 @@ static inline int arm_cspmu_find_cpu_container(int cpu, u32 container_uid)

acpi_dev = ACPI_COMPANION(cpu_dev);
while (acpi_dev) {
- if (!strcmp(acpi_device_hid(acpi_dev),
- ACPI_PROCESSOR_CONTAINER_HID) &&
- !kstrtouint(acpi_device_uid(acpi_dev), 0, &acpi_uid) &&
- acpi_uid == container_uid)
+ if (acpi_dev_hid_uid_match(acpi_dev, ACPI_PROCESSOR_CONTAINER_HID, NULL) &&
+ !acpi_dev_uid_to_integer(acpi_dev, &acpi_uid) && acpi_uid == container_uid)
return 0;

acpi_dev = acpi_dev_parent(acpi_dev);
--
2.17.1

2023-10-23 11:34:39

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] ACPI: utils: Introduce acpi_dev_uid_match() for matching _UID

On Mon, Oct 23, 2023 at 11:05:25AM +0530, Raag Jadav wrote:
> Introduce acpi_dev_uid_match() helper that matches the device with
> supplied _UID string.

...

> Suggested-by: Andy Shevchenko <[email protected]>

Sorry, I suggested another helper. Please either drop this tag, or change
helper to what I suggested (as in your v1 I assume).

--
With Best Regards,
Andy Shevchenko


2023-10-23 11:36:06

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 2/6] pinctrl: intel: use acpi_dev_uid_match() for matching _UID

On Mon, Oct 23, 2023 at 11:05:26AM +0530, Raag Jadav wrote:
> Convert manual _UID references to use the standard ACPI helper.

> Signed-off-by: Raag Jadav <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

As I asked you, please drop this one. It has a hidden logic that is not aligned
with acpi_dev_hid_uid_match(). Or revert to your v1 I assume.

--
With Best Regards,
Andy Shevchenko


2023-10-23 11:36:55

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 4/6] ACPI: x86: use acpi_dev_uid_match() for matching _UID

On Mon, Oct 23, 2023 at 11:05:28AM +0530, Raag Jadav wrote:
> Convert manual _UID references to use the standard ACPI helper.

> Signed-off-by: Raag Jadav <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

Please, drop this tag, since I disagree with patch 1 implementation.

--
With Best Regards,
Andy Shevchenko


2023-10-23 14:46:33

by Raag Jadav

[permalink] [raw]
Subject: Re: [PATCH v2 2/6] pinctrl: intel: use acpi_dev_uid_match() for matching _UID

On Mon, Oct 23, 2023 at 02:35:13PM +0300, Andy Shevchenko wrote:
> On Mon, Oct 23, 2023 at 11:05:26AM +0530, Raag Jadav wrote:
> > Convert manual _UID references to use the standard ACPI helper.
>
> > Signed-off-by: Raag Jadav <[email protected]>
> > Reviewed-by: Andy Shevchenko <[email protected]>
>
> It has a hidden logic that is not aligned with acpi_dev_hid_uid_match().
> Or revert to your v1 I assume.

I don't see how this has to be aligned with acpi_dev_hid_uid_match() or
if acpi_dev_hid_uid_match() implementation concerns this specific change,
since that's not what we intend to do here.

Also, I think acpi_dev_uid_match() implementation in v2 is actually more
aligned with the previous logic that we're replacing here, since it gives
us a guaranteed match result as originally intended with strcmp in this
case. And the "hidden logic" in v1 implementation (match with @uid2 == NULL)
is what ends up breaking it in my opinion.

Regardless, for any version (v1 or v2) the usage still remains the same
in this case.

> As I asked you, please drop this one.

But okay, as you wish :(

Rafael, should I send a v3 with dropped tags?

Raag

2023-10-23 18:46:23

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/6] pinctrl: intel: use acpi_dev_uid_match() for matching _UID

On Mon, Oct 23, 2023 at 4:43 PM Raag Jadav <[email protected]> wrote:
>
> On Mon, Oct 23, 2023 at 02:35:13PM +0300, Andy Shevchenko wrote:
> > On Mon, Oct 23, 2023 at 11:05:26AM +0530, Raag Jadav wrote:
> > > Convert manual _UID references to use the standard ACPI helper.
> >
> > > Signed-off-by: Raag Jadav <[email protected]>
> > > Reviewed-by: Andy Shevchenko <[email protected]>
> >
> > It has a hidden logic that is not aligned with acpi_dev_hid_uid_match().
> > Or revert to your v1 I assume.
>
> I don't see how this has to be aligned with acpi_dev_hid_uid_match() or
> if acpi_dev_hid_uid_match() implementation concerns this specific change,
> since that's not what we intend to do here.
>
> Also, I think acpi_dev_uid_match() implementation in v2 is actually more
> aligned with the previous logic that we're replacing here, since it gives
> us a guaranteed match result as originally intended with strcmp in this
> case. And the "hidden logic" in v1 implementation (match with @uid2 == NULL)
> is what ends up breaking it in my opinion.
>
> Regardless, for any version (v1 or v2) the usage still remains the same
> in this case.

Right, so it is a bit unclear what all of the fuss is about.

> > As I asked you, please drop this one.
>
> But okay, as you wish :(
>
> Rafael, should I send a v3 with dropped tags?

No need to resend in general, I can drop tags from the patches just fine.

For this one, though, I'd like to get a maintainer's ACK, so it may be
necessary to resend it without the tag.