Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp622871rdf; Tue, 21 Nov 2023 11:26:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV5FcbNjHm8x9lcBic5oqIRCV7zD5LNTwNqHg6YlxPflNv0LxDxev6T+h0IFUOHSHS9vTp X-Received: by 2002:a05:6a00:9395:b0:6c6:1648:5ac6 with SMTP id ka21-20020a056a00939500b006c616485ac6mr132709pfb.5.1700594760434; Tue, 21 Nov 2023 11:26:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700594760; cv=none; d=google.com; s=arc-20160816; b=A0nDg4W21JaPzOHlH+Ms/zEZqE1AjYObSTi26694awDxnD7LKc9mcisP3MPDIyzhS+ dwz0ikDq6X+e0rFMSFubHhZzdrxTrBhBoC93mxdz6fjHcrONkOx8zIjd39mM5dfrtZsN vQgolZzMwbQEwGR4FlGrhWQBUVH7N9t3dT8CMPR6i5q3BFSV6Gh+vH3U6PhUw0ayF/kB dmcKBi7RDXbWVruOUFKlO/3fsjtMLbyH2prnxNbyIJzw+BoPKLYZhcpG5yIO+xxCIXR1 vlLiI/bGn0HUvYreTiYeBWfJX64L+u1cbMpS68HA9zrl7PABF6mFcOjMdTmUtgxLHL1Z Nmwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=MvqPfIVnYukQzmyj4RnhjJ1TssvOnXprmZhe9EDaJXs=; fh=taYAf9iJgVsAXrZUU+WLvAPOG1eoJOvA6WUv+j7q9T0=; b=PF0s4AZy/cIuyD2ZrhOu0Ksz3wPdeijdI0eBrXNohJqTjCGSj+dS381hJXwrw1ZEoq UtR0dgrox9DpGnTqPt5P7JqG4ft0Pg7isDNUDvM+1OVsvwgipX949NMOSNacgS6CV70Q BDDnlRhscXxG5NPfrM1cmw8iYf5FnZK6daCJayDCvy0g2qH2JXsriJ19eqIpFBRABi+n +yMzo0RA3Qirtygd5FmYmgNElfFQ39qaNvDE5uczJBGTLkb/GJ0GnxPQgppHZ3zr/iOq fbm+bgiLzQXzGmQzw8mbcXO8kn+E2SMVDaEQWW5eZItO13WCGr7UoTuX0eTfSk8zw5Vk 1dCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h3-20020a635303000000b005bdbdd396eesi10527941pgb.633.2023.11.21.11.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 11:26:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5BF1780A43B3; Tue, 21 Nov 2023 11:25:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbjKUTZi convert rfc822-to-8bit (ORCPT + 99 others); Tue, 21 Nov 2023 14:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbjKUTZg (ORCPT ); Tue, 21 Nov 2023 14:25:36 -0500 Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B2318C; Tue, 21 Nov 2023 11:25:32 -0800 (PST) Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-1f947682bfdso118231fac.0; Tue, 21 Nov 2023 11:25:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700594732; x=1701199532; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZmF7VsRXyf5IAN8XB8CDp7srxIlqRHtK3S2F91eHJ+c=; b=D7tHfuQKy1Ywjv5BrMs3kAAXsrJ8tYojAAWgYvduVsuRnKVtbq/FvEKXdjaJ0ELI44 VSnNRds7iFIoT+dFAnAQ8uTAEYweO32UgdHBPHMkpNAJZj/yv9Al3FaEoEg5bVSHsag8 PwmyLih8cBtS7YmTBpLw5C8JH0qJGlv3fV7prWCzqTGpiqdHoIZKzsLYw4xRtMY2SPyp D4SXpWt3jrg10uxz7oKoQ9esGhf5NCk80N6KnJl32BPxOi4F6fOCBE5YZ7+n6qGLsfsI tMqRp+slk34GLVxTGz1X6DSWDZ0zfGx1BI08iBeyoVtv6AeIgYIRKMfMq8kYekcsoVbv UgWA== X-Gm-Message-State: AOJu0Yy+kYsoVr2B0/mWMq45RSrK98Bul49FuWcwWnraQjFhJuqPIv7+ 0Xivikpnd7PkfyJNB+EhJNThHVAyukm/nojyBxU= X-Received: by 2002:a05:6871:53cd:b0:1f9:602e:7b0d with SMTP id hz13-20020a05687153cd00b001f9602e7b0dmr342897oac.2.1700594731741; Tue, 21 Nov 2023 11:25:31 -0800 (PST) MIME-Version: 1.0 References: <20231121103829.10027-1-raag.jadav@intel.com> <20231121103829.10027-3-raag.jadav@intel.com> In-Reply-To: <20231121103829.10027-3-raag.jadav@intel.com> From: "Rafael J. Wysocki" Date: Tue, 21 Nov 2023 20:25:20 +0100 Message-ID: Subject: Re: [PATCH v2 2/6] ACPI: bus: update acpi_dev_uid_match() to support multiple types To: Raag Jadav Cc: 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, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=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 fry.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 (fry.vger.email [0.0.0.0]); Tue, 21 Nov 2023 11:25:57 -0800 (PST) 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. > 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? > + > +#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 > > 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) > { > --