Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2721009pxb; Tue, 12 Oct 2021 12:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLZc9vvJMFVj04qvfYDU7SDG1rp7RVV3vZ7Lx7qgF0ix5V51AUFAyvywujXE6cYg8A2OSl X-Received: by 2002:a63:9d06:: with SMTP id i6mr1251840pgd.42.1634065518913; Tue, 12 Oct 2021 12:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634065518; cv=none; d=google.com; s=arc-20160816; b=1COoZ+u72KagbMzAOHFYqtNnPj9ymSG3HiAiBomftPyzzplLgwYkKgb5x2qClxPzzE J3FFGTbJNsRDYTDUGVHRaG5G1ZxMlKEfenihaTiRq4eGOM5ilDp1D6oH9bqQR1aMChl8 FlEr/KxNMjkuECHNnqax7K1/kKUcuJThT2gldeA6GC0+1DYwQV80gch3IljhZhC4Sg9g z9VZ4nNOmq/wXtVePgci7ga6mURMxg0bhkv8j8jcb/lkkItabkI1/4z/QRJuT1SnlPgu DqaWiC9MoL7d5xTwdcZ8ZigIr17Ij+YQWcYJ/HsWLxW4/A1Z5eclW96C68AaElmxYXz1 qreQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=VLZHP69DtUmkBt4gT01OG09uszZlkn+5cD/T1PG9gdA=; b=iV0JRztChYXXKlNpF2WVcpM29DF7xnHwiBnIZeAe/HZuL8WK17o41QIitkl+3u9INf IPCSGBdBvH87rdaE44uaTPPYnrCNHEXpX9/24iHT/1HbFbU6hf9S61W60ehvXhN9CkjO NV1b8+LtwpVTD+NsboHoWBBk6Myg+QWHvSLVJqOsZs/X5A2xF/awTElA93qaZ1dXthwp lLw7LPEZgt9BhHkJYowApBwZXHjOSWsJkid5hbDCHen8okzCs7M8bxDMEHtxk8+H6GxU GMrB4HIrGBGfzbul8zx1bNBcS1K9uYE0y7YZXow0XzIXMjTA1LXytyAdN3TFC68BEMd7 tJ6w== 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si3467892plh.349.2021.10.12.12.05.06; Tue, 12 Oct 2021 12:05:18 -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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233507AbhJLTE3 (ORCPT + 99 others); Tue, 12 Oct 2021 15:04:29 -0400 Received: from mga18.intel.com ([134.134.136.126]:1838 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbhJLTE2 (ORCPT ); Tue, 12 Oct 2021 15:04:28 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10135"; a="214189599" X-IronPort-AV: E=Sophos;i="5.85,368,1624345200"; d="scan'208";a="214189599" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2021 12:02:26 -0700 X-IronPort-AV: E=Sophos;i="5.85,368,1624345200"; d="scan'208";a="591882244" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.159]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2021 12:02:24 -0700 Received: from andy by smile with local (Exim 4.95) (envelope-from ) id 1maN28-0003OA-BY; Tue, 12 Oct 2021 22:01:52 +0300 Date: Tue, 12 Oct 2021 22:01:52 +0300 From: Andy Shevchenko To: "Rafael J. Wysocki" Cc: Linux ACPI , linux-hwmon@vger.kernel.org, LKML , Jean Delvare , Guenter Roeck Subject: Re: [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() Message-ID: References: <11864888.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11864888.O9o76ZdvQC@kreacher> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 12, 2021 at 07:30:40PM +0200, Rafael J. Wysocki wrote: > 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(). Good catch! Reviewed-by: Andy Shevchenko > Signed-off-by: Rafael J. Wysocki > --- > 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) > { > > > -- With Best Regards, Andy Shevchenko