Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3411266pxf; Mon, 29 Mar 2021 01:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF8XaiXkg+l6ezkK+N22yNtHYLrTWxS2ngD5VseBbE3AfFOhoeBw3bzhPqde1lAsLYS+++ X-Received: by 2002:aa7:dd97:: with SMTP id g23mr27049781edv.154.1617005626350; Mon, 29 Mar 2021 01:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617005626; cv=none; d=google.com; s=arc-20160816; b=FdPPlc43kmNaF+96E6BwF3Mvv8DC8mqlu+YS7XXIdEd3gXmwRn9Kjhlai8LjwJM/lP +RT1KLdQuU7B9Z4dJd7dqaWbjCEoUE7hlqJJlL1krLcL37FBSd+yv5/KL5lxrQVfl5oL eEbqLx8hbklPq5Ycl3J86CxCo8E6WswCjUa0pRDAfQ0D4Mc4P6kcswWI0I4vH9S/MRF8 upOXqn61zGMQ+o4htxmo2wqVeG2TCOGo72IXj59s/psawVcVbB+FwWwNQzljOigN9vS0 sNam/mq0/yzYtejgFcT42L8sEIw0v/qx6Mzbf2bPpFETu+BIrcSXzrpw4CI5mPUspyal 6t8g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bFQDXEle/eZomAwJBxIs1jSuxPu+0rwQebZQRPB9qCY=; b=IzLo01F8QNCSiz45LfEiiZhP4LgxtIWScODCyF8qzA4jKVVsXBfJCPsblWvXslWW/O qJe/zHf0ZJyVd4POsbwFi438JDt3xuFV/YbAXqHrIB2pI0yK4MkaqXsD/IHvysc4j2DZ 49VeRed7p3HhxGtlUqtlBazcQXTVj2Zc70PZyoAhG5C/8CjLl1Z/AzDpX5WOWwxKsmR9 RUn7BUOyGiK1XIVwjicFMeqJDTDLUPKTZLbnbOBBnnlKb4W3K3nTDtAuq5LL2Mih3N1w fW81cKTAv3Bp7g8Ufg3TI8r36TM84ZKp5VOS7YbmlMREI4ozYFiiEe2nxwjtOzQ+cFFL 4OYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uLkFT6jb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si12224048ejm.194.2021.03.29.01.13.22; Mon, 29 Mar 2021 01:13:46 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uLkFT6jb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232623AbhC2IKS (ORCPT + 99 others); Mon, 29 Mar 2021 04:10:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbhC2IGI (ORCPT ); Mon, 29 Mar 2021 04:06:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 980D9619B4; Mon, 29 Mar 2021 08:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005168; bh=6ux4RafXB43Riu8oKSioC4axeyE7JJrDxxNnz+duII8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLkFT6jbcyh4fhLVXAm+h7McqE8efbHssjF+PXj3y7BxtmE5cJxFHex/XsPZ2fZLE wox8+1xKpFNb+V8gmYA7jhHN/mkEoMbdzP9jc7qGtum81MX23IfUeABv3SG82Yx46u 4Mu/FEcWXV3Is5TcXbUM0M0UiLa7cFWCXrmUf79M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.14 49/59] ACPI: scan: Use unique number for instance_no Date: Mon, 29 Mar 2021 09:58:29 +0200 Message-Id: <20210329075610.490962494@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075608.898173317@linuxfoundation.org> References: <20210329075608.898173317@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko [ Upstream commit eb50aaf960e3bedfef79063411ffd670da94b84b ] The decrementation of acpi_device_bus_id->instance_no in acpi_device_del() is incorrect, because it may cause a duplicate instance number to be allocated next time a device with the same acpi_device_bus_id is added. Replace above mentioned approach by using IDA framework. While at it, define the instance range to be [0, 4096). Fixes: e49bd2dd5a50 ("ACPI: use PNPID:instance_no as bus_id of ACPI device") Fixes: ca9dc8d42b30 ("ACPI / scan: Fix acpi_bus_id_list bookkeeping") Signed-off-by: Andy Shevchenko Cc: 4.10+ # 4.10+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/internal.h | 6 +++++- drivers/acpi/scan.c | 33 ++++++++++++++++++++++++++++----- include/acpi/acpi_bus.h | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index e6b10aad55d5..6ac1c6b04199 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -18,6 +18,8 @@ #ifndef _ACPI_INTERNAL_H_ #define _ACPI_INTERNAL_H_ +#include + #define PREFIX "ACPI: " int early_acpi_osi_init(void); @@ -97,9 +99,11 @@ void acpi_scan_table_handler(u32 event, void *table, void *context); extern struct list_head acpi_bus_id_list; +#define ACPI_MAX_DEVICE_INSTANCES 4096 + struct acpi_device_bus_id { const char *bus_id; - unsigned int instance_no; + struct ida instance_ida; struct list_head node; }; diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 9ec463da9a50..57a213466721 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -481,9 +481,8 @@ static void acpi_device_del(struct acpi_device *device) list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) if (!strcmp(acpi_device_bus_id->bus_id, acpi_device_hid(device))) { - if (acpi_device_bus_id->instance_no > 0) - acpi_device_bus_id->instance_no--; - else { + ida_simple_remove(&acpi_device_bus_id->instance_ida, device->pnp.instance_no); + if (ida_is_empty(&acpi_device_bus_id->instance_ida)) { list_del(&acpi_device_bus_id->node); kfree_const(acpi_device_bus_id->bus_id); kfree(acpi_device_bus_id); @@ -634,6 +633,21 @@ static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id) return NULL; } +static int acpi_device_set_name(struct acpi_device *device, + struct acpi_device_bus_id *acpi_device_bus_id) +{ + struct ida *instance_ida = &acpi_device_bus_id->instance_ida; + int result; + + result = ida_simple_get(instance_ida, 0, ACPI_MAX_DEVICE_INSTANCES, GFP_KERNEL); + if (result < 0) + return result; + + device->pnp.instance_no = result; + dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, result); + return 0; +} + int acpi_device_add(struct acpi_device *device, void (*release)(struct device *)) { @@ -668,7 +682,9 @@ int acpi_device_add(struct acpi_device *device, acpi_device_bus_id = acpi_device_bus_id_match(acpi_device_hid(device)); if (acpi_device_bus_id) { - acpi_device_bus_id->instance_no++; + result = acpi_device_set_name(device, acpi_device_bus_id); + if (result) + goto err_unlock; } else { acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id), GFP_KERNEL); @@ -684,9 +700,16 @@ int acpi_device_add(struct acpi_device *device, goto err_unlock; } + ida_init(&acpi_device_bus_id->instance_ida); + + result = acpi_device_set_name(device, acpi_device_bus_id); + if (result) { + kfree(acpi_device_bus_id); + goto err_unlock; + } + list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); } - dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no); if (device->parent) list_add_tail(&device->node, &device->parent->children); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 67f4fce22209..3746d4ce4857 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -245,6 +245,7 @@ struct acpi_pnp_type { struct acpi_device_pnp { acpi_bus_id bus_id; /* Object name */ + int instance_no; /* Instance number of this object */ struct acpi_pnp_type type; /* ID type */ acpi_bus_address bus_address; /* _ADR */ char *unique_id; /* _UID */ -- 2.30.1