Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp859778rdf; Tue, 21 Nov 2023 20:58:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IESGHG6TvFvvO3XEx/1Ar4wBkayKPH/uz9eRvGd22nJt3/8O/olIKdIMg7ij1dXKUVPuwmw X-Received: by 2002:a17:903:41c3:b0:1cf:6b68:31ad with SMTP id u3-20020a17090341c300b001cf6b6831admr1358381ple.17.1700629118051; Tue, 21 Nov 2023 20:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700629118; cv=none; d=google.com; s=arc-20160816; b=EeM7XrUEF62EGoaN0bmqu//Z8gbTN1XF6FI/Uyyj/HZU72pDHJTYx1eZeiEO93kR/V jYbEd6jT6NHpkYhoMDUjRSelpDXBc0dtQm7vSKrCsmcJoH7Hb+ZhaKkoPZTMqDoGy8Fv xTHPFujvRpCir/mly+a/25p5uxjHTorTmDIOCwPZg9gum32ii1SDcMS8p8pezBSyVNWg /t5g8u5Yt5kG6aLvte05nU5bJkRud+Qgp/TRTYUzec8iur58jl9u0IYKCpyN/20tZYUl 4JrkzvazMKaxRjHSEMQSRhldYWavT+TyM82YeAembWN4j33DFIIKq+xnd0VdhQ3HcKvE shgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=v0QBl/W13FWtLM1zPsufsD6mybbGW1OCz8IPydDaEmU=; fh=gRrUU/tXMi7teLf1gYE0HZHgv/84v7Kveba9JIGLspg=; b=HryJ8G5SQIz5tSpyVPhg4c714SGCWpg7MBnyDT+ES90dXGhJNDCipwLnj8tr9bixuC P39MJtLGc3vkZq4xY07LKQ6E/q5tMzX7rWZ3Mi5Rtt878NGpvoYkLxQ7Kuynnps6VFLa B6YZWH5I0wOzyZL91WBQlog4x79obfvggyIEHC6IWV1gMfbgEtrYJY+36HT1mp8vENqm S9XsyHLRhxHgrIhylWqCYZ2tHUDdieIMha8oU9vAViF3BLxh2r5ZhCntIaoqnO9yLBk3 5X0ppCk0m2qbLwzyrsBuVuclS6SSgqPxzflvBhNyMW/r6mBQP98NkwKa1AqB93rhHPKb K19g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mTC07sXe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id f8-20020a17090274c800b001c9c8e0cbafsi11596618plt.202.2023.11.21.20.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 20:58:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mTC07sXe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 1AD4180266AF; Tue, 21 Nov 2023 20:58:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbjKVE6X (ORCPT + 99 others); Tue, 21 Nov 2023 23:58:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjKVE6W (ORCPT ); Tue, 21 Nov 2023 23:58:22 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A802CF4; Tue, 21 Nov 2023 20:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700629099; x=1732165099; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=6OOZDIt/V+EllWbRkUq5IJR0w5aDlkstgw6hwmoGvqE=; b=mTC07sXeg8tAtvXZ9wSuttiPjjV93Clf0qxwoAvyMmW4mVYbJAK/J9ZL +e6G0yModyqbodDTpL3bhxbIuDNyPqGvGdWSbEI2EES+a8UoipDWReb7T 2SCYPkrkX157omCWheTVd+IjNSWAQWrqZRltbwiwKaKwacBlo6DQJaoKP u6ULLASiziBZu3SJfudenafKnswDuO/lofb339cXc/ilRFwgdcvbYaa0D 2y45zSL4uVqCLbm+4bttBCMnshx+N8GtkZn8zwlJWdS7wyUW9K9PT13Ds hXP5/14bWr0XTvdjynBu8bvoo9FtfDov8rKAZrQ+6rssRjocBR6nXCSCe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10901"; a="10650220" X-IronPort-AV: E=Sophos;i="6.04,217,1695711600"; d="scan'208";a="10650220" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 20:58:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10901"; a="795971891" X-IronPort-AV: E=Sophos;i="6.04,217,1695711600"; d="scan'208";a="795971891" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 20:58:13 -0800 Date: Wed, 22 Nov 2023 06:58:10 +0200 From: Raag Jadav To: "Rafael J. Wysocki" Cc: mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, lenb@kernel.org, robert.moore@intel.com, ardb@kernel.org, will@kernel.org, mark.rutland@arm.com, 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 Subject: Re: [PATCH v2 2/6] ACPI: bus: update acpi_dev_uid_match() to support multiple types Message-ID: References: <20231121103829.10027-1-raag.jadav@intel.com> <20231121103829.10027-3-raag.jadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 20:58:35 -0800 (PST) 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 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 > > Suggested-by: Mika Westerberg > > Suggested-by: Rafael J. Wysocki > > 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 > > --- > > 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 > > #include > > #include > > > > @@ -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