Re: [PATCH v2] ACPI: LPSS: use acpi_dev_uid_match() for matching _UID

From: Andy Shevchenko
Date: Mon Oct 30 2023 - 06:12:36 EST


On Sat, Oct 28, 2023 at 11:58:12AM +0300, Raag Jadav wrote:
> On Fri, Oct 27, 2023 at 07:40:38PM +0200, Rafael J. Wysocki wrote:

...

> We'd probably end up with an oops trying to strcmp into a random address
> without knowing its type, so I think Mika's would be a better approach.
>
> #define acpi_dev_uid_match(adev, uid2) \
> ({ \
> const char *uid1 = acpi_device_uid(adev); \
> u64 __uid1; \
> \
> _Generic(uid2, \
> int: uid1 && !kstrtou64(uid1, 0, &__uid1) && (typeof(uid2))__uid1 == uid2, \
> const char *: uid1 && uid2 && !strcmp(uid1, (const char *)uid2), \
> default: false); \
> \
> })
>
> This one I atleast got to compile, but I'm not very well versed with _Generic,
> so this could definitely use some comments.

If you go this way, make _Generic() use simple in the macro with a help of two
additional functions (per type). Also you need to take care about uid2 type to
be _any_ unsigned integer. Or if you want to complicate things, then you need
to distinguish signed and unsigned cases.

P.S.
All to me it seems way too overengineered w/o any potential prospective user.

--
With Best Regards,
Andy Shevchenko