Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2707792pxf; Sun, 4 Apr 2021 11:12:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD+ZaUViBTAIPWvEzcBugoukgpxVW8ckkI6qgTudrXThKZXeSsVi8AR6l0AEVXkPgCWbCO X-Received: by 2002:a92:cb90:: with SMTP id z16mr16596533ilo.34.1617559976708; Sun, 04 Apr 2021 11:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617559976; cv=none; d=google.com; s=arc-20160816; b=rEOJopxymV7NbJJcb/3a5yMLA7DuY7FJFe6tQ9h2NpAQ7R0SbkE8z1qCxl3yH1+wjB d3XQVDUBF6MfgCSmQ3SKRi+Ty+AHKkc4Qa1l4iGfzRcr1ywhmtKvHR6eXAyfVX/+RaM/ Rbtv/YJF4LUm+R+WzcbGP0zlAhM2jpl8NTr3de/PaDbeYB/VefuCr87Vjoy3dqDtIrXX p0nuj5uf1w7daxGmhKE87GEVvFyR4K/zXFoAo44TfbpuDOqBZFnLlVEOlVg6U7/VMaLN 2c1f3+JjkXMBwm/YocE4aciowBHZD5QLpgUdNnElK1rOy8X0e1XNVev6I4qP9918lUlS Krcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=IgZwejo2npTmRIjCIl61JoqCZ0h+wa9oJBWjX/mT2GE=; b=O9dYVCi6hI+UtQ9e2aBVZYVgL0cB597ILsxQSrjLKNArLpNDvdWgj33Up2Of95OZUG vrrX435ssdzepVRrDoZLYJ6Z7hK92CFsaKUYgbfZc5OFGMvrtIkF6LsjIq7LumOgf6+l vxB7YOFa92aeV5H5JL+edygFcIdNq82RSP4Q5K3482JJG6s/gPPuMliwn9cOZIGDAROY JfOZS5OHico34PuVlN6xa0YWnMNiGaFm27lLSyt/fYyEoeTODcojeW8DqKkifXJwmlhL +XVrAQRuGG21NHaxYyGVRQgZEWs8zwwpgV2+YOhWt5gM0sOOgKOjRhVxl0AcpfsfmxPI LETQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p7si12938765iol.88.2021.04.04.11.12.43; Sun, 04 Apr 2021 11:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbhDDSM2 (ORCPT + 99 others); Sun, 4 Apr 2021 14:12:28 -0400 Received: from fgw20-7.mail.saunalahti.fi ([62.142.5.81]:53553 "EHLO fgw20-7.mail.saunalahti.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbhDDSM0 (ORCPT ); Sun, 4 Apr 2021 14:12:26 -0400 Received: from localhost (88-115-248-186.elisa-laajakaista.fi [88.115.248.186]) by fgw20.mail.saunalahti.fi (Halon) with ESMTP id 4baa567f-9571-11eb-ba24-005056bd6ce9; Sun, 04 Apr 2021 21:12:20 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Lukas Wunner Subject: [PATCH v2 1/1] efi/dev-path-parser: Switch to use for_each_acpi_dev_match() Date: Sun, 4 Apr 2021 21:12:16 +0300 Message-Id: <20210404181216.1450776-1-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch to use for_each_acpi_dev_match() instead of home grown analogue. No functional change intended. Signed-off-by: Andy Shevchenko --- v2: fixed refcounting (example from which I took the v1 approach has been broken, fix is sent :-) drivers/firmware/efi/dev-path-parser.c | 49 ++++++++++---------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c index 5c9625e552f4..10d4457417a4 100644 --- a/drivers/firmware/efi/dev-path-parser.c +++ b/drivers/firmware/efi/dev-path-parser.c @@ -12,52 +12,39 @@ #include #include -struct acpi_hid_uid { - struct acpi_device_id hid[2]; - char uid[11]; /* UINT_MAX + null byte */ -}; - -static int __init match_acpi_dev(struct device *dev, const void *data) -{ - struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data; - struct acpi_device *adev = to_acpi_device(dev); - - if (acpi_match_device_ids(adev, hid_uid.hid)) - return 0; - - if (adev->pnp.unique_id) - return !strcmp(adev->pnp.unique_id, hid_uid.uid); - else - return !strcmp("0", hid_uid.uid); -} - static long __init parse_acpi_path(const struct efi_dev_path *node, struct device *parent, struct device **child) { - struct acpi_hid_uid hid_uid = {}; + char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */ + struct acpi_device *adev; struct device *phys_dev; if (node->header.length != 12) return -EINVAL; - sprintf(hid_uid.hid[0].id, "%c%c%c%04X", + sprintf(hid, "%c%c%c%04X", 'A' + ((node->acpi.hid >> 10) & 0x1f) - 1, 'A' + ((node->acpi.hid >> 5) & 0x1f) - 1, 'A' + ((node->acpi.hid >> 0) & 0x1f) - 1, node->acpi.hid >> 16); - sprintf(hid_uid.uid, "%u", node->acpi.uid); - - *child = bus_find_device(&acpi_bus_type, NULL, &hid_uid, - match_acpi_dev); - if (!*child) + sprintf(uid, "%u", node->acpi.uid); + + for_each_acpi_dev_match(adev, hid, NULL, -1) { + if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid)) + break; + if (!adev->pnp.unique_id && node->acpi.uid == 0) + break; + acpi_dev_put(adev); + } + if (!adev) return -ENODEV; - phys_dev = acpi_get_first_physical_node(to_acpi_device(*child)); + phys_dev = acpi_get_first_physical_node(adev); if (phys_dev) { - get_device(phys_dev); - put_device(*child); - *child = phys_dev; - } + *child = get_device(phys_dev); + acpi_dev_put(adev); + } else + *child = &adev->dev; return 0; } -- 2.31.1