Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3600334pxb; Wed, 13 Oct 2021 09:08:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh47iYOyypRLD9JHJ5NmGpoaW0UKCeBP6zh5jp8lEQ7Ut4Xf3oZooDLl6kFtyh4fiy92TW X-Received: by 2002:a65:648b:: with SMTP id e11mr26283pgv.138.1634141308604; Wed, 13 Oct 2021 09:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634141308; cv=none; d=google.com; s=arc-20160816; b=ESefe6CifX5ougQKi0kXdY5n/RIRIV17kq4n/ZhKZup2Ji44IhG/k2y3shjD9kRszk P4zhlwCunpVoDhBtYLv/36gfH6GKvd0ccxIGAA4RaTmos2DWHq6tyyjqWNz4/wgDexO0 F55nQqFWho0w9j1cBpIIyiNehRNDqIcdmbbbTlH8FyNwUuve9CLjCDlvIvKRt+IvKMTj YnYE0AFo0yukJ/+SxRxUsLlECJ9flKNb5sMdrf6xPpUU3k6IoZyiZBorOgzzwatullzG f0Cd+wgglg81BfFT0YEdDO3b0wJw7sUvrason+V8ybkEFHP9+Is0/9XsxLLRGLaxL+Pn uNYw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JhmIT9SresNk9VoBGTXaJkIe+5nrVcr8m7jKKKkEDGg=; b=JE99c8NgIeJO0Pr/SoxWYmS0zNMzFJOBC4ZeL45Ra8LQpeI7aL27XgRuVBwvBzkDQn tcNAcJPNu4jXDIUg+mHjhwrMbPRMZDsyp/djXToBPcSFv3lfHIKZT1sc1GYMC9AnF3re Rs4DAVcy20+94XoIcwf34uzbwhpVNnNQYW81O9LeAyYfz/LIwMfBmilvoLEyyzWiusQs Xoj2DsBs+PlBGZzli2lY+bQu3LsZ7esZZKUpV606TPruG9eUCRAX4Tnz6PSIq8gObPzu k7GyOWwmJ8su7pF2p6/Y70uCPP41r9SepGVJQzoMW+B/7P5RWbehRQNXub0QeLggylaj m7mw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q13si7117428plk.34.2021.10.13.09.08.02; Wed, 13 Oct 2021 09:08:28 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbhJMQGR (ORCPT + 99 others); Wed, 13 Oct 2021 12:06:17 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:55576 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbhJMQGR (ORCPT ); Wed, 13 Oct 2021 12:06:17 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 3.0.0) id 5610ad909f428166; Wed, 13 Oct 2021 18:04:11 +0200 Received: from kreacher.localnet (unknown [213.134.161.244]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id E1E2166A871; Wed, 13 Oct 2021 18:04:10 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: linux-hwmon@vger.kernel.org, LKML , Jean Delvare , Guenter Roeck , Andy Shevchenko Subject: [PATCH v2] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() Date: Wed, 13 Oct 2021 18:04:09 +0200 Message-ID: <11871063.O9o76ZdvQC@kreacher> In-Reply-To: <11864888.O9o76ZdvQC@kreacher> References: <11864888.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.161.244 X-CLIENT-HOSTNAME: 213.134.161.244 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrvddutddgleegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvjeelgffhiedukedtleekkedvudfggefhgfegjefgueekjeelvefggfdvledutdenucfkphepvddufedrudefgedrudeiuddrvdeggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrdduiedurddvgeegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqhhifmhhonhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjuggvlhhvrghrvgesshhushgvrdgtohhmpdhrtghpthhtoheplhhinhhugiesrhhovggt khdquhhsrdhnvghtpdhrtghpthhtoheprghnughrihihrdhshhgvvhgthhgvnhhkoheslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki In read_domain_devices(), acpi_bus_get_device() is called to obtain the ACPI device object attached to the given ACPI handle and subsequently that object is passed to get_device() for reference counting, but there is a window between the acpi_bus_get_device() and get_device() calls in which the ACPI device object in question may go away. To address this issue, make read_domain_devices() use acpi_bus_get_acpi_device() to reference count and return the given ACPI device object in one go and export that function to modules. While at it, also make read_domain_devices() and remove_domain_devices() use acpi_dev_put() instead of calling put_device() directly on the ACPI device objects returned by acpi_bus_get_acpi_device(). Signed-off-by: Rafael J. Wysocki Reviewed-by: Andy Shevchenko --- -> v2: Resend with a different From and S-o-b address and with R-by from Andy. No other changes. --- drivers/acpi/scan.c | 1 + drivers/hwmon/acpi_power_meter.c | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) Index: linux-pm/drivers/hwmon/acpi_power_meter.c =================================================================== --- linux-pm.orig/drivers/hwmon/acpi_power_meter.c +++ linux-pm/drivers/hwmon/acpi_power_meter.c @@ -535,7 +535,7 @@ static void remove_domain_devices(struct sysfs_remove_link(resource->holders_dir, kobject_name(&obj->dev.kobj)); - put_device(&obj->dev); + acpi_dev_put(obj); } kfree(resource->domain_devices); @@ -597,18 +597,15 @@ static int read_domain_devices(struct ac continue; /* Create a symlink to domain objects */ - resource->domain_devices[i] = NULL; - if (acpi_bus_get_device(element->reference.handle, - &resource->domain_devices[i])) + obj = acpi_bus_get_acpi_device(element->reference.handle); + resource->domain_devices[i] = obj; + if (!obj) continue; - obj = resource->domain_devices[i]; - get_device(&obj->dev); - res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, kobject_name(&obj->dev.kobj)); if (res) { - put_device(&obj->dev); + acpi_dev_put(obj); resource->domain_devices[i] = NULL; } } Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_de { return handle_to_device(handle, get_acpi_device); } +EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device); static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id) {