Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp1028872rdf; Wed, 22 Nov 2023 03:57:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCEKzBcooDTda9UfpSuA8qBvy0psLeWFDCG2ihhz8/jiP5vv2p1k5+Haqb1mb1bF2MQR2z X-Received: by 2002:a17:90b:4a92:b0:283:9a71:4578 with SMTP id lp18-20020a17090b4a9200b002839a714578mr2381939pjb.37.1700654221300; Wed, 22 Nov 2023 03:57:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700654221; cv=none; d=google.com; s=arc-20160816; b=F9gG8726pwqdIxZ8KdG3gmUqhmzu8b6+7YRW9l0poBgLYww7u5M2RyCEI23L96wZxz ADlVvSVY8MPvOdtns2SF2jMamT0CYyZHAFOQkKJeNTbQt4mrJ1xaORkqZJA9dh1FTwN8 iCL1y6WW04tHWYRccmSUc9PJLSAEjHmfTj1cXdoPEX6y4a9hMiJU7GKUk0pNGVIDRqa5 6V1kZVJHb7rSlwN0K+PiD3qJiCUEFiowk+TUIzj+ojWMwmWgQpg5i2q5v/20D83HodBF qf5tcKW1zo9I5L94Tg3kpjxal0l4f3E4fvPytHji8AXgHPyHSi+KGdEAqUbfLxVlGuHH LrJA== 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=DbJR2veNQdopGlkiNCNQ5kXzzBIQC1o4LPezYMbM14E=; fh=q1mO0CKQQ1uewKY3XHo4LfUjgTfLze+q4aq/9JFXa0A=; b=SvlP6RMKheexebsoWgo18HpO4DxwmOwGAoRnVEMaqbwigmaEETLTtXiVJi981Q7RcL DfScFrpILip/mUTeatF9LKig+9WrX9MXot1PYfTKSLG/ukqsAuSbzbbRIfrRBUDOBkoW SVDA0qpM4ONMxOd1YkKVBiRd/mjO4ELogej8kVRKbiaAwMCArd2TDRH/enk1jeV/RhZD Ojzj9wMk0T0AD7Pc+doZ2L5U66f6HxxvzJa2EA+RS2sE7ldYWjMNrvla/Hc5MiB7bBtO FZ/4bq4Kl6Wirz9UO5atL0MTMt8p5legmbX/QYz13qoCvBvxTMzPse/hCHieMmjwWaRi p9Cw== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id qa3-20020a17090b4fc300b002764fc15dd3si1408160pjb.37.2023.11.22.03.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 03:57:01 -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; 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=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 78AC2822B2F5; Wed, 22 Nov 2023 03:56:25 -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 S1343927AbjKVLz5 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 22 Nov 2023 06:55:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343577AbjKVLzz (ORCPT ); Wed, 22 Nov 2023 06:55:55 -0500 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A87591; Wed, 22 Nov 2023 03:55:51 -0800 (PST) Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-6d7e89d48efso185584a34.1; Wed, 22 Nov 2023 03:55:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700654150; x=1701258950; 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=WnzgeFjuBItEyIVZYQBtxAG5TnFPC1Nz+dshenAaKC4=; b=lzt82JqMXjDrjKJqHRcWEA/7DdYOKdCXfv0OjcAjDCUtyn8f46u/eWRV60hAIwjiWG /nrhSAz8uO1D5UjpYAGUeT2+uJzkORhbjr+nItSuOWLD5Y2TGrEyaD01ho0ytOPweSkP ICtSwB+wetkNHSk90lPb6DmC43BaOVClPHHtQf9hDZ6gHqE5ybP4ziSwSBAszRKhSwnU iIZyNxeQFl6bzMAdWrfJNYPakW/d5IrowTHv14o5JZwZq1RpT6WXPWBNMNPuPFehvhXj VCp/ovpyUodYf9yxr9DYK/cDBZ346SUJ04QpB4OGmkT1Zf5WCuyggt2WbL+JhEBUD0Ec Z+UA== X-Gm-Message-State: AOJu0YyTItu35it00JXMIxLLi35OvFJu8qFYWQKurg2/B1siWKEtLXbm 0aExfWNgqrE4MN7Rybx1omCzK3YV3pbAM/MgNso= X-Received: by 2002:a05:6870:a924:b0:1f4:d544:2490 with SMTP id eq36-20020a056870a92400b001f4d5442490mr2623563oab.4.1700654150597; Wed, 22 Nov 2023 03:55:50 -0800 (PST) MIME-Version: 1.0 References: <20231121103829.10027-1-raag.jadav@intel.com> <20231121103829.10027-3-raag.jadav@intel.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 22 Nov 2023 12:55:39 +0100 Message-ID: Subject: Re: [PATCH v2 2/6] ACPI: bus: update acpi_dev_uid_match() to support multiple types To: Raag Jadav Cc: "Rafael J. Wysocki" , 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 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 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]); Wed, 22 Nov 2023 03:56:25 -0800 (PST) On Wed, Nov 22, 2023 at 5:58 AM Raag Jadav 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 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. 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.