Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1659482rdh; Sat, 28 Oct 2023 01:59:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETvfJTpY+YixMWZxWDzEJT4FLC6bbRyjMLP9VSyV8rev4na4A4T34jN4zK2At0SsRTqswY X-Received: by 2002:a05:6358:441d:b0:168:e6d4:68d2 with SMTP id z29-20020a056358441d00b00168e6d468d2mr5541794rwc.32.1698483555387; Sat, 28 Oct 2023 01:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698483555; cv=none; d=google.com; s=arc-20160816; b=U3zgqS6RTvJpn85VXbWt7/WE2k6SuomAyXKvgnuYQgoNyE1gACdqIn+Hm5y/p2+fo1 N6TWl5YR9tEwDMkJQnF96XC2W4Qniv0ZAuKSTb6jvQujCC9DyLkAjK1enE+PUSxD1U6V XnlBkQC9Nwo/yp1FPvCsaaGr/JoEEMJU6KlZdzUSfGBNbrOH2vwRiKzpJm3jVlzkgt9l /Us7VFHAzeOUVcXV9Z+Vu1wBVAV3xmjICCTWPGVHbQB2yGBQwF2e09qd1Cd0TypBWmog DYRKm1AnO/TciCXhF+iz/xi+xJzvW23U0S67czg4KsrKHOJngZnFcejrMwfhJf4xOYlJ 1x2Q== 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=StywQ2x9gfSO8gv7lOutspQbPeeuVCDL26I2KcOMqZA=; fh=v5ywX9EL/4XOMCDQQTA5MIC9a1J7olaOLXxwWSuKb4M=; b=PE3lJS2031vHr1Yc38Z/Crl1LhcTBuudUSMbMSidx9Tmi7JodgL1w4g2cFDGHoQTKS 0WDDEV1ANCRPjtfWGVtScrNpsmxAt0cjtIMBpytmMKkoxHpIq5F1c3N6Oxo+O1DoCh0M eQLxdfPewbclKBvubj9z5mNgxqx9jW6KAb67zaW+qeoy8MeR5lSEYpqGN3W9RjUAqEMS 5h4zaRDzE0BA7Mmc+0TXpxOrKKJT8MsFyk/oHOye5VuobutVoOqu1smuB8/pR501auKq +5vovg48/O1LVj0RdeaLQyGfYXslC3moPz6vPE04z8eQXgCX9K4Ew7X02W3qN4gZIIvT Axvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nxZz79By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l15-20020a170902f68f00b001c9ad8ca211si2345398plg.18.2023.10.28.01.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 01:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nxZz79By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 11C4B816F0D8; Sat, 28 Oct 2023 01:59:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbjJ1I6W (ORCPT + 99 others); Sat, 28 Oct 2023 04:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjJ1I6V (ORCPT ); Sat, 28 Oct 2023 04:58:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FBF6F0; Sat, 28 Oct 2023 01:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698483498; x=1730019498; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=zkDqM+9rJKFk7nc3myPOxx1gyUxiQNwZjfLWSN5JOjA=; b=nxZz79By0PSJPrAJ48xwFUB6VTaKoM4zINiIikbN8bfTdnfaHzOzq5PK JDGkBXCrB9YwtASZMAfKcqvn7Mv5u4rC8au7T20BmFD5IT2kc7fAcsJtg zKnPut+Ypdj607IJDiWuRA2jZYsf/MKrVBsy8x8+nqfP7+nHiprPjDtoA JVpXi4WcUBrAPWMtShS/RxnsNKG4zTKQ57TXub2+ijB7463GUnV+RrzsP 2RSUserdCzyhstGccjVCPbCf7Lm+i0JD9N6qITxh2zVbq5vh7cmnvTenb 61lWG248axnqGWCnSgW4bXdpdr3vm6QAQBf+8K+3i5Y51+0WJr51vG8X0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="368103964" X-IronPort-AV: E=Sophos;i="6.03,258,1694761200"; d="scan'208";a="368103964" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2023 01:58:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="830235817" X-IronPort-AV: E=Sophos;i="6.03,258,1694761200"; d="scan'208";a="830235817" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2023 01:58:15 -0700 Date: Sat, 28 Oct 2023 11:58:12 +0300 From: Raag Jadav To: "Rafael J. Wysocki" Cc: Mika Westerberg , len.brown@intel.com, andriy.shevchenko@linux.intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mallikarjunappa.sangannavar@intel.com, bala.senthil@intel.com Subject: Re: [PATCH v2] ACPI: LPSS: use acpi_dev_uid_match() for matching _UID Message-ID: References: <20231026083335.12551-1-raag.jadav@intel.com> <20231027081855.GK3208943@black.fi.intel.com> <20231027142856.GL3208943@black.fi.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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Sat, 28 Oct 2023 01:59:13 -0700 (PDT) On Fri, Oct 27, 2023 at 07:40:38PM +0200, Rafael J. Wysocki wrote: > On Fri, Oct 27, 2023 at 7:19 PM Rafael J. Wysocki wrote: > > > > On Fri, Oct 27, 2023 at 6:51 PM Raag Jadav wrote: > > > > > > On Fri, Oct 27, 2023 at 05:28:56PM +0300, Mika Westerberg wrote: > > > > > > > > Indeed, but using the _Generic() you should be able to have > > > > a single acpi_dev_uid_match() to work for either type so: > > > > > > > > acpi_dev_uid_match(adev, "1") > > > > > > > > and > > > > > > > > acpi_dev_uid_match(adev, 1) > > > > > > > > would both work with type checkings etc. > > > > > > > > Not sure if this is worth the trouble though. > > > > > > Well, in that case we can probably try both and hope for the best ;) > > > > > > bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2) > > > { > > > const char *uid1 = acpi_device_uid(adev); > > > u64 uid1_d; > > > > > > return uid1 && uid2 && (!strcmp(uid1, uid2) || > > > (!kstrtou64(uid1, 0, &uid1_d) && uid1_d == (u64)uid2)); > > > } > > > > > > But I'm guessing the compiler wouldn't be very happy about this. > > > > IMO it would be better to use the observation that if the uid2 string > > can be successfully cast to an int and the device's unique_id string > > can't be cast to an int (or the other way around), there is no match. > > > > If they both can be cast to an int, they match as long as the casting > > results are equal. > > > > If none of them can be cast to an int, they need to be compared as strings. > > Or if the strings don't match literally, try to convert them both to > ints and compare. 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. Raag