Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1325792rdh; Fri, 27 Oct 2023 10:41:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNmTJ7oeV6M8b4ZjjfUu72wBEYRfD3lFlSFNASPmQNBqTF5lv+DnXtmclCMiznnmK5VfyH X-Received: by 2002:a05:6870:32cc:b0:1ea:cdcb:5a2b with SMTP id r12-20020a05687032cc00b001eacdcb5a2bmr3704335oac.54.1698428469063; Fri, 27 Oct 2023 10:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698428469; cv=none; d=google.com; s=arc-20160816; b=aWdM4MrsX7cIPe6oTvFK5aC1xDUwhujHPMi4rw4gvvBw8+0DFr1PgLfhJC5mq0s16B zRR7qnCcWA2yZwDlFHzvU1V/qFEngPmhbz28+s18e+zIkRzz/zJ6QqVRzjaCBd3UuPmN Z7O7g99RFaVfft34hVxHll/snhAOpdQEYjKJF+XjFNICmOP+8h/kzfaWxKgzsdoj4wFd x/THyXusTJE0qcK9V/KqU6mHFCAG7yUFeFPkyfg6AfqHO5GXL6rOxF8jAKSQSDKyLriY JH9wWSYzguQCcqddwMuYR9CTV02oiMJGbPv6xfV0yUApteUUopvr10nbSd+utUyyqJBl 2buQ== 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=vM0QkXGVv4ANKU2fWp2nXWL7WBcQq8f/PJfJ28NqkRM=; fh=bjtcvhuB/cWaEzgHKVwH9ITzv7gDChSreaxJ53k4KNc=; b=TE9rIOkH96f1HSkU63CN018cMNtiOGz8HsuwrDLmD8muNNMyEbNQBC5iE1ZDkDswyD ulOW/RrkSfpF2NtKTK17TtCRaekUJdDXlmI6qJw3+SmSYdgFZez0LtTIjC4wXZPzVH9Z 6FSrexYqzeBftwtPSM6TlPigsEb3ksMepmSYE/L/UYhj57t3DS7ybZ4K4RIZ1PWfwZ1V xjg7n72SQYb4aEDUUtTK1D0IDUmJZjcEtq0qIboLaqmyhIWR6MFk1isF2PechPzbG2O0 sY0LY25XsKt07xY3s14NUolTgQtFIhUMygCi9N7X5BI7fSRKXGgy4r3vhKoMJ6GcYOAz 3Unw== 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 p136-20020a25428e000000b00d9a402dcd12si3368877yba.80.2023.10.27.10.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:41:09 -0700 (PDT) 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 0E2AF8388AD0; Fri, 27 Oct 2023 10:41:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232557AbjJ0Rky convert rfc822-to-8bit (ORCPT + 99 others); Fri, 27 Oct 2023 13:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232550AbjJ0Rkw (ORCPT ); Fri, 27 Oct 2023 13:40:52 -0400 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162121BF; Fri, 27 Oct 2023 10:40:50 -0700 (PDT) Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5845b7ee438so236374eaf.1; Fri, 27 Oct 2023 10:40:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698428449; x=1699033249; 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=2KOnH5/FFvstAu2M3w0vaUabYFluUiI04lKVVVH2LdQ=; b=RRIcRFEhGZpvbBJmUetxEvtcY1WXRJiNJrTX2V8Ax1Fpsqxa26BxcsHrIfWa531P8x fqF0qcREtixV/4NYMpB99oXh7Up/VXgwADCUm5sxjfEkTv3okkDwMcBs/bwVKFMOgeG5 qzHOeRiI6wfTloQEA7oWzrLUg5gL50LI6fKc5il9kWIGnbtwPOzwFPAuin/wgEtzlIT+ F1vKC3C/B6idQ/xlv/YR1ejp4ksMFYtdy8cPSXwna5nUaCH6sbRiWNRW15pT+NH3elZB nT9LA+WCBgWfvvj56snZ3Zi5AcahNFuNg2uWCs0mmSXT8oWt0SdPvrAhnnQjLHd6wtUS hUhA== X-Gm-Message-State: AOJu0YxXHoPhpO7U4Tohp0vvb/lcZMJAuf2yvok0zVf2dviPwqXf+s1B VmDLQB4qvvbyfMT/OQktrhCX1WGeU31cMPwRTF4= X-Received: by 2002:a4a:4184:0:b0:57c:6e35:251e with SMTP id x126-20020a4a4184000000b0057c6e35251emr3635145ooa.1.1698428449329; Fri, 27 Oct 2023 10:40:49 -0700 (PDT) MIME-Version: 1.0 References: <20231026083335.12551-1-raag.jadav@intel.com> <20231027081855.GK3208943@black.fi.intel.com> <20231027142856.GL3208943@black.fi.intel.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 27 Oct 2023 19:40:38 +0200 Message-ID: Subject: Re: [PATCH v2] ACPI: LPSS: use acpi_dev_uid_match() for matching _UID To: Raag Jadav Cc: Mika Westerberg , rafael@kernel.org, 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 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 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]); Fri, 27 Oct 2023 10:41:06 -0700 (PDT) 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: > > > On Fri, Oct 27, 2023 at 05:17:12PM +0300, Raag Jadav wrote: > > > > Or perhaps something like, > > > > > > > > bool acpi_dev_uid_match(struct acpi_device *adev, const void *uid2, enum uid_type type) > > > > { > > > > u64 uid1_d, uid2_d; > > > > > > > > if (type == UID_TYPE_STR) { > > > > char *uid2_s = (char *)uid2; > > > > if (!(uid2_s && !kstrtou64(uid2_s, 0, &uid2_d))) > > > > return false; > > > > } else if (type == UID_TYPE_INT) { > > > > u64 *uid2_p; > > > > uid2_p = (u64 *)uid2; > > > > uid2_d = *uid2_p; > > > > } else { > > > > return false; > > > > } > > > > > > > > if (!acpi_dev_uid_to_integer(adev, &uid1_d) && uid1_d == uid2_d) > > > > return true; > > > > else > > > > return false; > > > > } > > > > > > > > Although this looks unnecessarily hideous. > > > > > > 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.