Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1314873rdh; Fri, 27 Oct 2023 10:21:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFC10ki1vO9X1CvzY2zzGMLXAhlePL3UjbVRJBXAjqg8n8l3CiT8NKKukaO69246XRdnn2p X-Received: by 2002:a81:e608:0:b0:5a7:baae:329f with SMTP id u8-20020a81e608000000b005a7baae329fmr3067335ywl.15.1698427294590; Fri, 27 Oct 2023 10:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698427294; cv=none; d=google.com; s=arc-20160816; b=zsQG/qnve90IhveqCFDZKfIKuFMIjsiFqmtaGeoB1YZqUBPQ31nfBdkNWjA58S0HTV q5P5OVKzeQGQ3RD7kB6PBYc6TqNerqD8UhQTvls81hNx/0HD+wOf+OrITFQaR6eqqYJa 7lx1OLqYfji2lv5jQdC8tjpW/stmFKXfmPo1H8Txb1u2rxGKSIGISMOmiSrETJuZEYPP vykbh6WjoY66fiHZxSsqOro+KtAwcar9Yt2bUTQe+rRiVFbWkMYOmxDkbzG+fEtmaKMS TB8RJF1KCElAzZSOQSKfHaZtpV6LaalC9vdD+kf9yd6o2D6WWAyPceQq7APy83Z0MDc6 UG+w== 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=+q2mvSGJIhrqRXPr5Gtiyo+e+oenwbF6O7c4o4+znOY=; fh=bjtcvhuB/cWaEzgHKVwH9ITzv7gDChSreaxJ53k4KNc=; b=UXN+v2F2QjTE5CGo3+bm0YO6ZYi+BRQhuPnMmj49aG9xq1Jxx30iIP2gpHRfFz70DM 9jz8b3vnde92KRIi8UvKQoZoJRPqhuak/UTB4MzUtRhGWuZvnCj99ILbAF2mMyRPTw/S Iw69VyaxaaQJgsaAnrbq9rcIXDwuAllbzZKnApX1pSnkckDIrl+d4c893dnucHas81E5 oxrei2wXnlb+A2FzW6sIkEEiqbn4MYuDt4886GbVd4uNprD5+VDKX9H6ceyNF/pDm9bs 9EuboohVaZI0tc8dsG6p8eC48wPFU8p9vVH+Ctj8US7d6vFJ2QBLbMG67/1ZNDkqS8NE QQvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i145-20020a819197000000b005a7b492834dsi2928486ywg.406.2023.10.27.10.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 948048092161; Fri, 27 Oct 2023 10:20:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346012AbjJ0RUI convert rfc822-to-8bit (ORCPT + 99 others); Fri, 27 Oct 2023 13:20:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232781AbjJ0RUG (ORCPT ); Fri, 27 Oct 2023 13:20:06 -0400 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93F89128; Fri, 27 Oct 2023 10:20:01 -0700 (PDT) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-57f137dffa5so298908eaf.1; Fri, 27 Oct 2023 10:20:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698427200; x=1699032000; 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=5AStNFe6wJs0Em1n6/3g792uBA5JpFkSsw8YocrKn8w=; b=Cva7tRbjzJe4Km7Zh/mWL+yU7NRune2ybcpGY8RUdaCJFdM+xncyHlBsxR3O2kWas4 6m954i4r78O8oVU1wGCavkmPnaT8Y76regSOWvKcARV/IJf9b63qckw3d6g4SLvQJXb7 2dc41yJnYVWPeHYEGXhY9uVpuG+erIg5zbK4Vw3San1TSmb8sf3V4b3ciG3XgMDouoTp FLsKwMIl4rsLEnkybFpQsZKIZdgsAJJTRcsqksiXJQVq7fJQNNXZ7ZQsjaqOzf9mpkRK xZK+MWg7jdPxHTcnpoCk/Iycn1QCbNlIYNMwsNachNUBs8mLBjwXmJBqApUYYKgowdaw xjIg== X-Gm-Message-State: AOJu0YyW62m3SnCbpHYjP7oNFjIJPI+AHegD0S7OJPH390CTytxlVLOz j+0USL3V4UvJiJOkXcUEFjyR6IplHWznCiy0eqA= X-Received: by 2002:a4a:d743:0:b0:584:17d0:de3d with SMTP id h3-20020a4ad743000000b0058417d0de3dmr3482378oot.1.1698427200507; Fri, 27 Oct 2023 10:20:00 -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:19:49 +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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 27 Oct 2023 10:20:15 -0700 (PDT) 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.