diff mbox series

[v1,4/8] ACPI: utils: use acpi_dev_uid_match() for matching _UID

Message ID 20231020084732.17130-5-raag.jadav@intel.com
State New
Headers show
Series Refine _UID references across kernel | expand

Commit Message

Raag Jadav Oct. 20, 2023, 8:47 a.m. UTC
Convert manual _UID references to use standard ACPI helpers.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/acpi/utils.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Andy Shevchenko Oct. 20, 2023, 10:36 a.m. UTC | #1
On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> Convert manual _UID references to use standard ACPI helpers.

Yes, while not so obvious this is the correct replacement.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Raag Jadav Oct. 20, 2023, 11:38 a.m. UTC | #2
On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > Convert manual _UID references to use standard ACPI helpers.
> 
> Yes, while not so obvious this is the correct replacement.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

I think this is the only case which would suffer from the more obvious
behaviour, i.e.

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);
}

That said, we can't be particularly sure about it's potential future users,
especially when the usage will not be limited to just ACPI core since we're
exporting it.

Raag
Andy Shevchenko Oct. 20, 2023, 1:42 p.m. UTC | #3
On Fri, Oct 20, 2023 at 02:38:06PM +0300, Raag Jadav wrote:
> On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> > On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > > Convert manual _UID references to use standard ACPI helpers.
> > 
> > Yes, while not so obvious this is the correct replacement.
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> I think this is the only case which would suffer from the more obvious
> behaviour, i.e.

No, that's not true. The same with override CPU in the other patch, where the
check is simply absent, but the result will be the same. So, all with negation
will suffer from the "obvious" implementation.

> 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);
> }
> 
> That said, we can't be particularly sure about it's potential future users,
> especially when the usage will not be limited to just ACPI core since we're
> exporting it.
Raag Jadav Oct. 20, 2023, 2 p.m. UTC | #4
On Fri, Oct 20, 2023 at 04:42:08PM +0300, Andy Shevchenko wrote:
> On Fri, Oct 20, 2023 at 02:38:06PM +0300, Raag Jadav wrote:
> > On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> > > On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > > > Convert manual _UID references to use standard ACPI helpers.
> > > 
> > > Yes, while not so obvious this is the correct replacement.
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > I think this is the only case which would suffer from the more obvious
> > behaviour, i.e.
> 
> No, that's not true. The same with override CPU in the other patch, where the
> check is simply absent, but the result will be the same. So, all with negation
> will suffer from the "obvious" implementation.

Forgot to add, we don't need to change the original acpi_dev_hid_uid_match()
behaviour, i.e.

bool acpi_dev_hid_uid_match(struct acpi_device *adev,
                            const char *hid2, const char *uid2)
{
        const char *hid1 = acpi_device_hid(adev);

        if (strcmp(hid1, hid2))
                return false;

        if (!uid2)
                return true;

        return acpi_dev_uid_match(adev, uid2);
}

I'm fine with both, this just makes more sense to me.

Raag
Rafael J. Wysocki Oct. 20, 2023, 5:11 p.m. UTC | #5
On Fri, Oct 20, 2023 at 1:38 PM Raag Jadav <raag.jadav@intel.com> wrote:
>
> On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> > On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > > Convert manual _UID references to use standard ACPI helpers.
> >
> > Yes, while not so obvious this is the correct replacement.
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> I think this is the only case which would suffer from the more obvious
> behaviour, i.e.
>
> 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);
> }
>
> That said, we can't be particularly sure about it's potential future users,
> especially when the usage will not be limited to just ACPI core since we're
> exporting it.

I actually agree with this, so please switch over to the above.

The above is straightforward and easy to understand and if somebody
wants to treat uid2 == NULL as a match, let them check that explicitly
before calling this function.
Raag Jadav Oct. 20, 2023, 6:11 p.m. UTC | #6
On Fri, Oct 20, 2023 at 07:11:53PM +0200, Rafael J. Wysocki wrote:
> On Fri, Oct 20, 2023 at 1:38 PM Raag Jadav <raag.jadav@intel.com> wrote:
> >
> > On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> > > On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > > > Convert manual _UID references to use standard ACPI helpers.
> > >
> > > Yes, while not so obvious this is the correct replacement.
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > I think this is the only case which would suffer from the more obvious
> > behaviour, i.e.
> >
> > 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);
> > }
> >
> > That said, we can't be particularly sure about it's potential future users,
> > especially when the usage will not be limited to just ACPI core since we're
> > exporting it.
> 
> I actually agree with this, so please switch over to the above.

Will send out a v2, thanks.

Andy, can I add your review for this?

Raag
Raag Jadav Oct. 21, 2023, 6:51 a.m. UTC | #7
On Fri, Oct 20, 2023 at 09:11:56PM +0300, Raag Jadav wrote:
> On Fri, Oct 20, 2023 at 07:11:53PM +0200, Rafael J. Wysocki wrote:
> > On Fri, Oct 20, 2023 at 1:38 PM Raag Jadav <raag.jadav@intel.com> wrote:
> > >
> > > On Fri, Oct 20, 2023 at 01:36:27PM +0300, Andy Shevchenko wrote:
> > > > On Fri, Oct 20, 2023 at 02:17:28PM +0530, Raag Jadav wrote:
> > > > > Convert manual _UID references to use standard ACPI helpers.
> > > >
> > > > Yes, while not so obvious this is the correct replacement.
> > > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >
> > > I think this is the only case which would suffer from the more obvious
> > > behaviour, i.e.
> > >
> > > 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);
> > > }
> > >
> > > That said, we can't be particularly sure about it's potential future users,
> > > especially when the usage will not be limited to just ACPI core since we're
> > > exporting it.
> > 
> > I actually agree with this, so please switch over to the above.
> 
> Will send out a v2, thanks.
> 
> Andy, can I add your review for this?

IIUC you agree with the usage format, but not the actual helper.
So I'm gonna drop it from the first patch and keep it for the rest,
except this one.

Let me know if I'm doing this wrong.

Raag
diff mbox series

Patch

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 664b9890b625..e3ba835e6590 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -889,8 +889,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 (!acpi_dev_uid_match(adev, match->uid))
 		return 0;
 
 	if (match->hrv == -1)