Message ID | 20231121103829.10027-3-raag.jadav@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp528777vqb; Tue, 21 Nov 2023 02:39:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvPXtAhUz3OpPktI3EjctVAkxySauhD2BwjZBjUREamcWg/kg0PNm6ruWadxWs9Iattl1B X-Received: by 2002:a05:6a00:84a:b0:6bd:f760:6ab1 with SMTP id q10-20020a056a00084a00b006bdf7606ab1mr9681610pfk.14.1700563147223; Tue, 21 Nov 2023 02:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700563147; cv=none; d=google.com; s=arc-20160816; b=qzgb0h0F1sc/OqH1ZqYCQbZdNvD8X6JxpnOur1it0kavdmKTTiiRTfUo9EV8Jykg+o lFRw9hS0U0dY/yFFp9SoGGFexmnhKCrQsIEpYuszdujJRZ9DO0ktErd1PVZvhgJIw1Sv uT5xFIEPCse+6ia0izYp9UjR9rxSUTES1k3xo0tYlj6znpHtdevtD833u0p99eXJQKVo riffQ1A9djtCrzXNR1UqeB0G26wKnYXEpPGXENQzHbn1PoEkOXx8ES3DFWzK3m03lBzA PEz77AmTBxtqYAVWtt7KeZ3YM/786BeGqfZtDfi/NOSwjbDMjOqjoP0m2LGfhkpnlYrC Q9Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=/4qQRy0NOyDTR+2gPcLN1FR+x/TPHw0P4wjuMIBTrFQ=; fh=LrjGCQr9k+7CYyd6XEdJgJkCFIUW/cPwqK3zW8PbdHI=; b=ser/xJfX50FkDv59+Gg7vT8pPBFxcOomUbMtrd+oR4whoGmayBxW0TcNtv020d9QRv piFf2lXffacPgx/l4jp/kRXv4lBb147thKuU3BpcCcwbfjxBAzLNemYUsyIct1b7wg0P 7Eszg7z94oILD99zXIF7M406D4sJISZ2ji42JPiu9/zOM7u5nQD2LzJk175icw5j1n2t sHWh5o9UAgLlzx0Hj/6rH3UMoHEsN2iurZIniqLV6nGvga7Lu5PPSb5ZfwX8K19auz1J HZME/YNbNXegqlEpG2zPCQMP65Gsg/6M59u2830jL48z/404uQlFKRN2WPGBBzo/jnHQ Ka5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PJ25NazC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id cm9-20020a056a020a0900b005c200f02d9asi10842966pgb.621.2023.11.21.02.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:39:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PJ25NazC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3DFB080BB3F8; Tue, 21 Nov 2023 02:39:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233866AbjKUKiy (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 05:38:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbjKUKiv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 05:38:51 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB4D1113; Tue, 21 Nov 2023 02:38:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700563126; x=1732099126; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=U7qXPbkOU+uJnKsznZCchO4LL3iAWvuDM1CUIkNhqaI=; b=PJ25NazCbLyTp3oUFnggMQ9WcpDd1J44m+fZ68QyHNazjH5koDCT46FD Ot/BuNAJ8TR+Od5ridnGjd5vj3kHjZned4KcQkA2JEjv4DleyFUOP/+++ cPtUR1+zb78vVQgZ3kqQsC8J0tSxIxckwvz3hKvpIdgFTae6wlyd2i9dm YksFAehXMsvO/cExGeqZTsC6bDtWBbvSRmrPr1mm7MrM/G02u0ro4ukYF d8e01Y/xw/Tg6rj7pGTpWZylpD9tKiPftn44KrV8NAXBBbfX4YhszSJJ/ a+7Pnrrq+6HWZ2CYRwPa2esEzOVrHY31EwdYXsE2GkotOTqqZl/GC+rhf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="371986897" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="371986897" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 02:38:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="14871936" Received: from inlubt0316.iind.intel.com ([10.191.20.213]) by fmviesa001.fm.intel.com with ESMTP; 21 Nov 2023 02:38:42 -0800 From: Raag Jadav <raag.jadav@intel.com> To: mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, rafael@kernel.org, lenb@kernel.org, robert.moore@intel.com, ardb@kernel.org, will@kernel.org, mark.rutland@arm.com Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linuxfoundation.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mallikarjunappa.sangannavar@intel.com, bala.senthil@intel.com, Raag Jadav <raag.jadav@intel.com> Subject: [PATCH v2 2/6] ACPI: bus: update acpi_dev_uid_match() to support multiple types Date: Tue, 21 Nov 2023 16:08:25 +0530 Message-Id: <20231121103829.10027-3-raag.jadav@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231121103829.10027-1-raag.jadav@intel.com> References: <20231121103829.10027-1-raag.jadav@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:39:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783169702633100993 X-GMAIL-MSGID: 1783169702633100993 |
Series |
Support _UID matching for integer types
|
|
Commit Message
Raag Jadav
Nov. 21, 2023, 10:38 a.m. UTC
According to ACPI specification, a _UID object can evaluate to either
a numeric value or a string. Update acpi_dev_uid_match() helper to
support _UID matching for both integer and string types.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
drivers/acpi/utils.c | 19 -------------------
include/acpi/acpi_bus.h | 35 ++++++++++++++++++++++++++++++++++-
include/linux/acpi.h | 8 +++-----
3 files changed, 37 insertions(+), 25 deletions(-)
Comments
On Tue, Nov 21, 2023 at 04:08:25PM +0530, Raag Jadav wrote: > According to ACPI specification, a _UID object can evaluate to either > a numeric value or a string. Update acpi_dev_uid_match() helper to > support _UID matching for both integer and string types. > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
On Tue, Nov 21, 2023 at 11:38 AM Raag Jadav <raag.jadav@intel.com> wrote: > > According to ACPI specification, a _UID object can evaluate to either > a numeric value or a string. Update acpi_dev_uid_match() helper to > support _UID matching for both integer and string types. > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> You need to be careful with using this. There are some things below that go beyond what I have suggested. > Signed-off-by: Raag Jadav <raag.jadav@intel.com> > --- > drivers/acpi/utils.c | 19 ------------------- > include/acpi/acpi_bus.h | 35 ++++++++++++++++++++++++++++++++++- > include/linux/acpi.h | 8 +++----- > 3 files changed, 37 insertions(+), 25 deletions(-) > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > index 28c75242fca9..fe7e850c6479 100644 > --- a/drivers/acpi/utils.c > +++ b/drivers/acpi/utils.c > @@ -824,25 +824,6 @@ 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. > diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h > index ec6a673dcb95..bcd78939bab4 100644 > --- a/include/acpi/acpi_bus.h > +++ b/include/acpi/acpi_bus.h > @@ -9,6 +9,7 @@ > #ifndef __ACPI_BUS_H__ > #define __ACPI_BUS_H__ > > +#include <linux/compiler.h> > #include <linux/device.h> > #include <linux/property.h> > > @@ -857,10 +858,42 @@ 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); > > +static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) > +{ > + const char *uid1 = acpi_device_uid(adev); > + > + return uid1 && uid2 && !strcmp(uid1, uid2); > +} > + > +static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2) > +{ > + u64 uid1; > + > + return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2; > +} > + Up to this point it is all fine IMV. > +/** > + * 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. > + */ > + > +/* Treat uid as a string for array and pointer types, treat as an integer otherwise */ > +#define get_uid_type(x) \ > + (__builtin_choose_expr(is_array_or_pointer_type(x), (const char *)0, (u64)0)) But I wouldn't use the above. It is far more elaborate than needed for this use case and may not actually work as expected. For instance, why would a pointer to a random struct type be a good candidate for a string? > + > +#define acpi_dev_uid_match(adev, uid2) \ > + _Generic(get_uid_type(uid2), \ > + const char *: acpi_str_uid_match, \ > + u64: acpi_int_uid_match)(adev, uid2) > + Personally, I would just do something like the following #define acpi_dev_uid_match(adev, uid2) \ _Generic((uid2), \ const char *: acpi_str_uid_match, \ char *: acpi_str_uid_match, \ const void *: acpi_str_uid_match, \ void *: acpi_str_uid_match, \ default: acpi_int_uid_match)(adev, uid2) which doesn't require compiler.h to be fiddled with and is rather straightforward to follow. If I'm to apply the patches, this is about the level of complexity you need to target. > void acpi_dev_clear_dependencies(struct acpi_device *supplier); > bool acpi_dev_ready_for_enumeration(const struct acpi_device *device); > struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier, > diff --git a/include/linux/acpi.h b/include/linux/acpi.h > index b63d7811c728..aae3a459d63c 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -763,6 +763,9 @@ const char *acpi_get_subsystem_id(acpi_handle handle); > #define ACPI_HANDLE(dev) (NULL) > #define ACPI_HANDLE_FWNODE(fwnode) (NULL) > > +/* Get rid of the -Wunused-variable for adev */ > +#define acpi_dev_uid_match(adev, uid2) (adev && false) > + > #include <acpi/acpi_numa.h> > > struct fwnode_handle; > @@ -779,11 +782,6 @@ 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) > { > --
On Tue, Nov 21, 2023 at 08:25:20PM +0100, Rafael J. Wysocki wrote: > On Tue, Nov 21, 2023 at 11:38 AM Raag Jadav <raag.jadav@intel.com> wrote: > > > > According to ACPI specification, a _UID object can evaluate to either > > a numeric value or a string. Update acpi_dev_uid_match() helper to > > support _UID matching for both integer and string types. > > > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > You need to be careful with using this. There are some things below > that go beyond what I have suggested. I think we all suggested some bits and pieces so I included everyone. We can drop if there are any objections. > > Signed-off-by: Raag Jadav <raag.jadav@intel.com> > > --- > > drivers/acpi/utils.c | 19 ------------------- > > include/acpi/acpi_bus.h | 35 ++++++++++++++++++++++++++++++++++- > > include/linux/acpi.h | 8 +++----- > > 3 files changed, 37 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > > index 28c75242fca9..fe7e850c6479 100644 > > --- a/drivers/acpi/utils.c > > +++ b/drivers/acpi/utils.c > > @@ -824,25 +824,6 @@ 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. > > diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h > > index ec6a673dcb95..bcd78939bab4 100644 > > --- a/include/acpi/acpi_bus.h > > +++ b/include/acpi/acpi_bus.h > > @@ -9,6 +9,7 @@ > > #ifndef __ACPI_BUS_H__ > > #define __ACPI_BUS_H__ > > > > +#include <linux/compiler.h> > > #include <linux/device.h> > > #include <linux/property.h> > > > > @@ -857,10 +858,42 @@ 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); > > > > +static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) > > +{ > > + const char *uid1 = acpi_device_uid(adev); > > + > > + return uid1 && uid2 && !strcmp(uid1, uid2); > > +} > > + > > +static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2) > > +{ > > + u64 uid1; > > + > > + return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2; > > +} > > + > > Up to this point it is all fine IMV. > > > +/** > > + * 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. > > + */ > > + > > +/* Treat uid as a string for array and pointer types, treat as an integer otherwise */ > > +#define get_uid_type(x) \ > > + (__builtin_choose_expr(is_array_or_pointer_type(x), (const char *)0, (u64)0)) > > But I wouldn't use the above. > > It is far more elaborate than needed for this use case and may not > actually work as expected. For instance, why would a pointer to a > random struct type be a good candidate for a string? Such case will not compile, since its data type will not match with acpi_str_uid_match() prototype. The compiler does a very good job of qualifing only the compatible string types here, which is exactly what we want. error: passing argument 2 of 'acpi_str_uid_match' from incompatible pointer type [-Werror=incompatible-pointer-types] if (acpi_dev_uid_match(adev, adev)) { ^ ./include/acpi/acpi_bus.h:870:20: note: expected 'const char *' but argument is of type 'struct acpi_device *' static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) > > + > > +#define acpi_dev_uid_match(adev, uid2) \ > > + _Generic(get_uid_type(uid2), \ > > + const char *: acpi_str_uid_match, \ > > + u64: acpi_int_uid_match)(adev, uid2) > > + > > Personally, I would just do something like the following > > #define acpi_dev_uid_match(adev, uid2) \ > _Generic((uid2), \ > const char *: acpi_str_uid_match, \ > char *: acpi_str_uid_match, \ > const void *: acpi_str_uid_match, \ > void *: acpi_str_uid_match, \ > default: acpi_int_uid_match)(adev, uid2) > > which doesn't require compiler.h to be fiddled with and is rather > straightforward to follow. > > If I'm to apply the patches, this is about the level of complexity you > need to target. Understood, however this will limit the type support to only a handful of types and will not satisfy a few of the existing users, which, for example are passing signed or unsigned pointer or an array of u8. Listing every possible type manually for _Generic() looks a bit verbose for something that can be simply achieved by __builtin functions in my opinion. I can still send out a v3 to see if it really works. However, I prefer the v2 approach, as it covers all possible scenarios without any corner cases. Raag
On Tue, Nov 21, 2023 at 08:25:20PM +0100, Rafael J. Wysocki wrote: > On Tue, Nov 21, 2023 at 11:38 AM Raag Jadav <raag.jadav@intel.com> wrote: > > > > According to ACPI specification, a _UID object can evaluate to either > > a numeric value or a string. Update acpi_dev_uid_match() helper to > > support _UID matching for both integer and string types. > > > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > You need to be careful with using this. There are some things below > that go beyond what I have suggested. Same to me and actually I've asked several times to remove this tag of mine!
On Wed, Nov 22, 2023 at 5:58 AM Raag Jadav <raag.jadav@intel.com> wrote: > > On Tue, Nov 21, 2023 at 08:25:20PM +0100, Rafael J. Wysocki wrote: > > On Tue, Nov 21, 2023 at 11:38 AM Raag Jadav <raag.jadav@intel.com> wrote: > > > > > > According to ACPI specification, a _UID object can evaluate to either > > > a numeric value or a string. Update acpi_dev_uid_match() helper to > > > support _UID matching for both integer and string types. > > > > > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > > Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> > > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > You need to be careful with using this. There are some things below > > that go beyond what I have suggested. > > I think we all suggested some bits and pieces so I included everyone. > We can drop if there are any objections. There are, from me and from Andy. [cut] > > Up to this point it is all fine IMV. > > > > > +/** > > > + * 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. > > > + */ > > > + > > > +/* Treat uid as a string for array and pointer types, treat as an integer otherwise */ > > > +#define get_uid_type(x) \ > > > + (__builtin_choose_expr(is_array_or_pointer_type(x), (const char *)0, (u64)0)) > > > > But I wouldn't use the above. > > > > It is far more elaborate than needed for this use case and may not > > actually work as expected. For instance, why would a pointer to a > > random struct type be a good candidate for a string? > > Such case will not compile, since its data type will not match with > acpi_str_uid_match() prototype. The compiler does a very good job of > qualifing only the compatible string types here, which is exactly what > we want. > > error: passing argument 2 of 'acpi_str_uid_match' from incompatible pointer type [-Werror=incompatible-pointer-types] > if (acpi_dev_uid_match(adev, adev)) { > ^ > ./include/acpi/acpi_bus.h:870:20: note: expected 'const char *' but argument is of type 'struct acpi_device *' > static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) You are right, it won't compile, but that's not my point. Why would it be matched with acpi_str_uid_match() in the first place? > > > + > > > +#define acpi_dev_uid_match(adev, uid2) \ > > > + _Generic(get_uid_type(uid2), \ > > > + const char *: acpi_str_uid_match, \ > > > + u64: acpi_int_uid_match)(adev, uid2) > > > + > > > > Personally, I would just do something like the following > > > > #define acpi_dev_uid_match(adev, uid2) \ > > _Generic((uid2), \ > > const char *: acpi_str_uid_match, \ > > char *: acpi_str_uid_match, \ > > const void *: acpi_str_uid_match, \ > > void *: acpi_str_uid_match, \ > > default: acpi_int_uid_match)(adev, uid2) > > > > which doesn't require compiler.h to be fiddled with and is rather > > straightforward to follow. > > > > If I'm to apply the patches, this is about the level of complexity you > > need to target. > > Understood, however this will limit the type support to only a handful > of types, Indeed. > and will not satisfy a few of the existing users, which, for > example are passing signed or unsigned pointer or an array of u8. Fair enough, so those types would need to be added to the list. > Listing every possible type manually for _Generic() looks a bit verbose > for something that can be simply achieved by __builtin functions in my > opinion. But then you don't even need _Generic(), do you? Wouldn't something like the below work? #define acpi_dev_uid_match(adev, uid2) \ (__builtin_choose_expr(is_array_or_pointer_type((uid2)),acpi_str_uid_match(adev, uid2), acpi_int_uid_match(adev, uid2)) In any case, I'm not particularly convinced about the is_array_or_pointer_type() thing and so I'm not going to apply the series as is.
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 28c75242fca9..fe7e850c6479 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -824,25 +824,6 @@ 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. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index ec6a673dcb95..bcd78939bab4 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -9,6 +9,7 @@ #ifndef __ACPI_BUS_H__ #define __ACPI_BUS_H__ +#include <linux/compiler.h> #include <linux/device.h> #include <linux/property.h> @@ -857,10 +858,42 @@ 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); +static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) +{ + const char *uid1 = acpi_device_uid(adev); + + return uid1 && uid2 && !strcmp(uid1, uid2); +} + +static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2) +{ + u64 uid1; + + return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2; +} + +/** + * 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. + */ + +/* Treat uid as a string for array and pointer types, treat as an integer otherwise */ +#define get_uid_type(x) \ + (__builtin_choose_expr(is_array_or_pointer_type(x), (const char *)0, (u64)0)) + +#define acpi_dev_uid_match(adev, uid2) \ + _Generic(get_uid_type(uid2), \ + const char *: acpi_str_uid_match, \ + u64: acpi_int_uid_match)(adev, uid2) + void acpi_dev_clear_dependencies(struct acpi_device *supplier); bool acpi_dev_ready_for_enumeration(const struct acpi_device *device); struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index b63d7811c728..aae3a459d63c 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -763,6 +763,9 @@ const char *acpi_get_subsystem_id(acpi_handle handle); #define ACPI_HANDLE(dev) (NULL) #define ACPI_HANDLE_FWNODE(fwnode) (NULL) +/* Get rid of the -Wunused-variable for adev */ +#define acpi_dev_uid_match(adev, uid2) (adev && false) + #include <acpi/acpi_numa.h> struct fwnode_handle; @@ -779,11 +782,6 @@ 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) {