Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3417143pxf; Mon, 29 Mar 2021 01:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziAuZzMw+6bMM90WAmK8vBvJjN2COmsbnHAV5bvGOwrJdAj+ImlscfgtlH5SgsMlzj7+FK X-Received: by 2002:a05:6402:350f:: with SMTP id b15mr27219415edd.6.1617006342523; Mon, 29 Mar 2021 01:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617006342; cv=none; d=google.com; s=arc-20160816; b=Tjgk2DJv6nYXI+HbcJivyKHYF480pKkJjd+tOjQdFSUHRvLlOY2/EaY+jyPj7sCh7M ssrlpqoRInuR8MinjM1SwT4+aSYeRJOAlceJhp5OejWZLfCr+atXtRaakhxG4/uIy0c7 duEzr7m3cBcY+Z5TgOnAQA2nmf9VeBFF61pLwdaRQ89iyLK9sWaeKCjYbgNOkoVPRemO ZxnaBUhr0SRvbpmj/jcI4MEVMLDG4jH2wF0IMxH2hRX9LFadtRjsV5sGzv2xakckcw+4 L5LHNSTlROTF7f8cOfIEHroHrcirtSj48jYiPYGmmhXWZrQzT46/mTgGfDgi66zK+StI O8vw== 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=/yup2Hxkd3QXv9SFdXhD8y3J1nepUuiicUXl9HOfFGk=; b=ivaM8lACVYYkfWb3bE7fikJTP0lzyUaIAcKsym2h8xgTTUvM77GMvmN8a0R+Kx2brb 56dXTmpTCbvwIxIPIBYqsUWTaCkJfXzVHw40IAgfZrIPPKJhFcq9mGLTY5DArI8ABsp1 kxFYLhQtzn/vBK9QvYrfILGeEz07G9VJ0/dTXm5aefOcGN1k+of4pL4DYKm3LfIYq/wp qMpJx8e3KihxOYczHx8dKdoaf/wqZBdPgLb03PsKT851rQqTthsEiT9LQNO4pzWBkwA0 DA0QUW5NkAHkWgAc1/bwlKQZvp/hpXI7hb3EssumVTMdB2MNLDmcLQqvQt4Bm2///Ehb a23g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uCLWvN63; 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 ji5si12901206ejc.360.2021.03.29.01.25.20; Mon, 29 Mar 2021 01:25:42 -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=uCLWvN63; 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 S232491AbhC2IYd (ORCPT + 99 others); Mon, 29 Mar 2021 04:24:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:58964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233062AbhC2IPu (ORCPT ); Mon, 29 Mar 2021 04:15:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10D6A6195B; Mon, 29 Mar 2021 08:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005735; bh=EpxltyF83qJHhssFSch4pqQjGUE16w442ZAd/3+aQVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCLWvN63SBKaBloxbW9dHglcFX0h2LWzNbx5vD5hwIhV3BeWT/v7SsqHYAKEn5dVX S8xL+QssMbOJx+4E/90raOkmtA9GP5AJ6RYm+bqXN0fAedETWz2lPIwkQxntq6DS83 9cqiTYTW+rDoUdhBQS0hgedY3OEe9hdqJZ8AqWV0= 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 5.4 098/111] ACPI: scan: Use unique number for instance_no Date: Mon, 29 Mar 2021 09:58:46 +0200 Message-Id: <20210329075618.475816279@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075615.186199980@linuxfoundation.org> References: <20210329075615.186199980@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 1db2e1bb72ba..159c422601bc 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -9,6 +9,8 @@ #ifndef _ACPI_INTERNAL_H_ #define _ACPI_INTERNAL_H_ +#include + #define PREFIX "ACPI: " int early_acpi_osi_init(void); @@ -96,9 +98,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 ddde1229e2b3..dbb5919f23e2 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -483,9 +483,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); @@ -636,6 +635,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 *)) { @@ -670,7 +684,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); @@ -686,9 +702,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 defed629073b..4d67a67964fa 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -232,6 +232,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