Message ID | 20231006173055.2938160-6-michal.wilczynski@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp488767vqo; Fri, 6 Oct 2023 10:32:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0DZC6keLhveVnApmH+hICP/c7QigYtI9H5TxAmg0HeylJn482a3vi1msoFRZcXnCdt+EO X-Received: by 2002:a17:90a:bc92:b0:263:fbe5:2125 with SMTP id x18-20020a17090abc9200b00263fbe52125mr8530965pjr.15.1696613537374; Fri, 06 Oct 2023 10:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696613537; cv=none; d=google.com; s=arc-20160816; b=ApPqklb6i6hVg6KYlw5O9VbfA2ADBufZRUEQoJkbI3nDdXRUaeuBs6IEfYeqUoyZLZ sCLkpT22vTr6tvwCP1B/1VmvI/IwtVtcuNK2uwDhi4NSfouFveGNl6yTFY+i/a2LpGll nGoq58UTQ7noo2rXi6X7J8FL/1ZzhLjZAuvU0eLiP2MmqYRoo8NaaSWHyK1dZq2OuQdx 4TqSWMn0W9neQ3kdUYdgENONLOsyM3G8OGAMkRC9mFVjcpYuvEfLTvGv2nsDLmYybIlg p4iKlp27PoKwvnqkm04jDZVOSsJm8+g8tzC2Eq7pvaGHRjWsjNdHa387ApBVL6HCJN5M i+pw== 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 :dkim-signature; bh=JzwRwTwBVT5iDuV+nhi1w0nC8mGQ7BVO+GYWSj3/fDM=; fh=pmO2GOaxRwgO5+LItasZBY6NOhKBrZd5NDojoBR8jzw=; b=KXr2iuixU6wKj5BpSEpR2wuTmD9OmgkklKLG8SK9GvHJiMsxGec8CwMTUdgByMiU/1 4brfXzH3xEVoB7N6CJVdTNM1BV34scPpSl5DUy8x03cg8NNzvQO02BaDgFCxepFCopjF mdmjmdV2d2bz2E3+GE4BFgRO1wCwH8gIS6a0K2mjbZ6iL3hUEqLhgegFhP5E23T3qh6I WjwgeGi5W5TBMUeTpG9orrkyY7iDduNr2+x1ue1b6SnBMnj8E3XFgmpCZmDmGodgc44z bGgzt3CRa7LzLfJfDncBt5hYZxwqdT8XNBuOnE8CuneIeslPTymmbROiw26qD4O0FMLu Lhjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l5vKD2Bu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id pi14-20020a17090b1e4e00b00276bf69ac44si4721072pjb.5.2023.10.06.10.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:32:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l5vKD2Bu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5209180D6E65; Fri, 6 Oct 2023 10:31:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233098AbjJFRbh (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Fri, 6 Oct 2023 13:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233066AbjJFRbc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 6 Oct 2023 13:31:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B35BFC; Fri, 6 Oct 2023 10:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696613487; x=1728149487; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q/SGBfl7Je7pNa8w+6+4h+GBn7+eWQRv7gJpu1bn1/k=; b=l5vKD2Bu75Gd1SqYYVfQm9CuZv3+lXZ4ffvgFhPkXrPg0F4aGMaAaNaw gL7WJRVuJ701z1DVW2K0JCkHVf/I7gzRXtto87Yq09UKb/KG2rFi3mzuX e3QlYDiiWIest8wYSWuvymgL9BzT+rnYBL57kjjYiBRmhfoGZOhyUSFzo ni/MhQl05kxRLlg1RedyIs/skvQ2UELq/tfduAO6XaV97mIVCmiYVF8zB ofDpqMyknITprcZ7YZKhrwoc0vE2hieEn2HySuAamd0sUxN18Nap9PK7g BdlNIfmplEXfAUzIIkgAaPcLbh6eQJQr/It4lgzuvUj6Ew7palHBtx3Rp Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="387676836" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="387676836" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 10:31:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="745937517" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="745937517" Received: from powerlab.fi.intel.com ([10.237.71.25]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 10:31:23 -0700 From: Michal Wilczynski <michal.wilczynski@intel.com> To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev Cc: rafael.j.wysocki@intel.com, andriy.shevchenko@intel.com, lenb@kernel.org, dan.j.williams@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, Michal Wilczynski <michal.wilczynski@intel.com> Subject: [PATCH v2 5/6] ACPI: NFIT: Replace acpi_driver with platform_driver Date: Fri, 6 Oct 2023 20:30:54 +0300 Message-ID: <20231006173055.2938160-6-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231006173055.2938160-1-michal.wilczynski@intel.com> References: <20231006173055.2938160-1-michal.wilczynski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 10:31:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779028236706179761 X-GMAIL-MSGID: 1779028236706179761 |
Series |
Replace acpi_driver with platform_driver
|
|
Commit Message
Wilczynski, Michal
Oct. 6, 2023, 5:30 p.m. UTC
NFIT driver uses struct acpi_driver incorrectly to register itself.
This is wrong as the instances of the ACPI devices are not meant
to be literal devices, they're supposed to describe ACPI entry of a
particular device.
Use platform_driver instead of acpi_driver. In relevant places call
platform devices instances pdev to make a distinction with ACPI
devices instances.
NFIT driver uses devm_*() family of functions extensively. This change
has no impact on correct functioning of the whole devm_*() family of
functions, since the lifecycle of the device stays the same. It is still
being created during the enumeration, and destroyed on platform device
removal.
Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
---
drivers/acpi/nfit/core.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
Comments
On 10/6/2023 7:30 PM, Michal Wilczynski wrote: > NFIT driver uses struct acpi_driver incorrectly to register itself. > This is wrong as the instances of the ACPI devices are not meant > to be literal devices, they're supposed to describe ACPI entry of a > particular device. > > Use platform_driver instead of acpi_driver. In relevant places call > platform devices instances pdev to make a distinction with ACPI > devices instances. > > NFIT driver uses devm_*() family of functions extensively. This change > has no impact on correct functioning of the whole devm_*() family of > functions, since the lifecycle of the device stays the same. It is still > being created during the enumeration, and destroyed on platform device > removal. > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com> Hi Dan, Rafael already reviewed this patch series and merged patches that he likes. We're waiting on your input regarding two NFIT commits in this series. Thanks a lot ! Michał > --- > drivers/acpi/nfit/core.c | 34 ++++++++++++++++++---------------- > 1 file changed, 18 insertions(+), 16 deletions(-) > > diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c > index 942b84d94078..fb0bc16fa186 100644 > --- a/drivers/acpi/nfit/core.c > +++ b/drivers/acpi/nfit/core.c > @@ -15,6 +15,7 @@ > #include <linux/sort.h> > #include <linux/io.h> > #include <linux/nd.h> > +#include <linux/platform_device.h> > #include <asm/cacheflush.h> > #include <acpi/nfit.h> > #include "intel.h" > @@ -98,7 +99,7 @@ static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) > || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) > return NULL; > > - return to_acpi_device(acpi_desc->dev); > + return ACPI_COMPANION(acpi_desc->dev); > } > > static int xlat_bus_status(void *buf, unsigned int cmd, u32 status) > @@ -3284,11 +3285,11 @@ static void acpi_nfit_put_table(void *table) > > static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data) > { > - struct acpi_device *adev = data; > + struct device *dev = data; > > - device_lock(&adev->dev); > - __acpi_nfit_notify(&adev->dev, handle, event); > - device_unlock(&adev->dev); > + device_lock(dev); > + __acpi_nfit_notify(dev, handle, event); > + device_unlock(dev); > } > > static void acpi_nfit_remove_notify_handler(void *data) > @@ -3329,11 +3330,12 @@ void acpi_nfit_shutdown(void *data) > } > EXPORT_SYMBOL_GPL(acpi_nfit_shutdown); > > -static int acpi_nfit_add(struct acpi_device *adev) > +static int acpi_nfit_probe(struct platform_device *pdev) > { > struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; > struct acpi_nfit_desc *acpi_desc; > - struct device *dev = &adev->dev; > + struct device *dev = &pdev->dev; > + struct acpi_device *adev = ACPI_COMPANION(dev); > struct acpi_table_header *tbl; > acpi_status status = AE_OK; > acpi_size sz; > @@ -3360,7 +3362,7 @@ static int acpi_nfit_add(struct acpi_device *adev) > acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > if (!acpi_desc) > return -ENOMEM; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > + acpi_nfit_desc_init(acpi_desc, dev); > > /* Save the acpi header for exporting the revision via sysfs */ > acpi_desc->acpi_header = *tbl; > @@ -3391,7 +3393,7 @@ static int acpi_nfit_add(struct acpi_device *adev) > return rc; > > rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, > - acpi_nfit_notify, adev); > + acpi_nfit_notify, dev); > if (rc) > return rc; > > @@ -3475,11 +3477,11 @@ static const struct acpi_device_id acpi_nfit_ids[] = { > }; > MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); > > -static struct acpi_driver acpi_nfit_driver = { > - .name = KBUILD_MODNAME, > - .ids = acpi_nfit_ids, > - .ops = { > - .add = acpi_nfit_add, > +static struct platform_driver acpi_nfit_driver = { > + .probe = acpi_nfit_probe, > + .driver = { > + .name = KBUILD_MODNAME, > + .acpi_match_table = acpi_nfit_ids, > }, > }; > > @@ -3517,7 +3519,7 @@ static __init int nfit_init(void) > return -ENOMEM; > > nfit_mce_register(); > - ret = acpi_bus_register_driver(&acpi_nfit_driver); > + ret = platform_driver_register(&acpi_nfit_driver); > if (ret) { > nfit_mce_unregister(); > destroy_workqueue(nfit_wq); > @@ -3530,7 +3532,7 @@ static __init int nfit_init(void) > static __exit void nfit_exit(void) > { > nfit_mce_unregister(); > - acpi_bus_unregister_driver(&acpi_nfit_driver); > + platform_driver_unregister(&acpi_nfit_driver); > destroy_workqueue(nfit_wq); > WARN_ON(!list_empty(&acpi_descs)); > }
On Tue, Oct 17, 2023 at 12:45 PM Wilczynski, Michal <michal.wilczynski@intel.com> wrote: > > > On 10/6/2023 7:30 PM, Michal Wilczynski wrote: > > NFIT driver uses struct acpi_driver incorrectly to register itself. > > This is wrong as the instances of the ACPI devices are not meant > > to be literal devices, they're supposed to describe ACPI entry of a > > particular device. > > > > Use platform_driver instead of acpi_driver. In relevant places call > > platform devices instances pdev to make a distinction with ACPI > > devices instances. > > > > NFIT driver uses devm_*() family of functions extensively. This change > > has no impact on correct functioning of the whole devm_*() family of > > functions, since the lifecycle of the device stays the same. It is still > > being created during the enumeration, and destroyed on platform device > > removal. > > > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com> > > Hi Dan, > Rafael already reviewed this patch series and merged patches > that he likes. We're waiting on your input regarding two NFIT > commits in this series. I actually haven't looked at the NFIT patches in this series myself and this is not urgent at all IMV. Thanks!
On Fri, Oct 6, 2023 at 8:33 PM Michal Wilczynski <michal.wilczynski@intel.com> wrote: > > NFIT driver uses struct acpi_driver incorrectly to register itself. > This is wrong as the instances of the ACPI devices are not meant > to be literal devices, they're supposed to describe ACPI entry of a > particular device. > > Use platform_driver instead of acpi_driver. In relevant places call > platform devices instances pdev to make a distinction with ACPI > devices instances. > > NFIT driver uses devm_*() family of functions extensively. This change > has no impact on correct functioning of the whole devm_*() family of > functions, since the lifecycle of the device stays the same. It is still > being created during the enumeration, and destroyed on platform device > removal. > > Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com> > --- > drivers/acpi/nfit/core.c | 34 ++++++++++++++++++---------------- > 1 file changed, 18 insertions(+), 16 deletions(-) > > diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c > index 942b84d94078..fb0bc16fa186 100644 > --- a/drivers/acpi/nfit/core.c > +++ b/drivers/acpi/nfit/core.c > @@ -15,6 +15,7 @@ > #include <linux/sort.h> > #include <linux/io.h> > #include <linux/nd.h> > +#include <linux/platform_device.h> > #include <asm/cacheflush.h> > #include <acpi/nfit.h> > #include "intel.h" > @@ -98,7 +99,7 @@ static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) > || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) > return NULL; > > - return to_acpi_device(acpi_desc->dev); > + return ACPI_COMPANION(acpi_desc->dev); > } > > static int xlat_bus_status(void *buf, unsigned int cmd, u32 status) > @@ -3284,11 +3285,11 @@ static void acpi_nfit_put_table(void *table) > > static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data) > { > - struct acpi_device *adev = data; > + struct device *dev = data; > > - device_lock(&adev->dev); > - __acpi_nfit_notify(&adev->dev, handle, event); > - device_unlock(&adev->dev); > + device_lock(dev); > + __acpi_nfit_notify(dev, handle, event); > + device_unlock(dev); Careful here. The ACPI device locking is changed to platform device locking without a word of explanation in the changelog. Do you actually know what the role of the locking around __acpi_nfit_notify() is and whether or not it can be replaced with platform device locking safely? > } > > static void acpi_nfit_remove_notify_handler(void *data) > @@ -3329,11 +3330,12 @@ void acpi_nfit_shutdown(void *data) > } > EXPORT_SYMBOL_GPL(acpi_nfit_shutdown); > > -static int acpi_nfit_add(struct acpi_device *adev) > +static int acpi_nfit_probe(struct platform_device *pdev) > { > struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; > struct acpi_nfit_desc *acpi_desc; > - struct device *dev = &adev->dev; > + struct device *dev = &pdev->dev; > + struct acpi_device *adev = ACPI_COMPANION(dev); > struct acpi_table_header *tbl; > acpi_status status = AE_OK; > acpi_size sz; > @@ -3360,7 +3362,7 @@ static int acpi_nfit_add(struct acpi_device *adev) > acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); > if (!acpi_desc) > return -ENOMEM; > - acpi_nfit_desc_init(acpi_desc, &adev->dev); > + acpi_nfit_desc_init(acpi_desc, dev); You seem to think that replacing adev->dev with pdev->dev everywhere in this driver will work, Have you verified that in any way? If so, then how? > > /* Save the acpi header for exporting the revision via sysfs */ > acpi_desc->acpi_header = *tbl; > @@ -3391,7 +3393,7 @@ static int acpi_nfit_add(struct acpi_device *adev) > return rc; > > rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, > - acpi_nfit_notify, adev); > + acpi_nfit_notify, dev); > if (rc) > return rc; > > @@ -3475,11 +3477,11 @@ static const struct acpi_device_id acpi_nfit_ids[] = { > }; > MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); > > -static struct acpi_driver acpi_nfit_driver = { > - .name = KBUILD_MODNAME, > - .ids = acpi_nfit_ids, > - .ops = { > - .add = acpi_nfit_add, > +static struct platform_driver acpi_nfit_driver = { > + .probe = acpi_nfit_probe, > + .driver = { > + .name = KBUILD_MODNAME, > + .acpi_match_table = acpi_nfit_ids, > }, > }; > > @@ -3517,7 +3519,7 @@ static __init int nfit_init(void) > return -ENOMEM; > > nfit_mce_register(); > - ret = acpi_bus_register_driver(&acpi_nfit_driver); > + ret = platform_driver_register(&acpi_nfit_driver); > if (ret) { > nfit_mce_unregister(); > destroy_workqueue(nfit_wq); > @@ -3530,7 +3532,7 @@ static __init int nfit_init(void) > static __exit void nfit_exit(void) > { > nfit_mce_unregister(); > - acpi_bus_unregister_driver(&acpi_nfit_driver); > + platform_driver_unregister(&acpi_nfit_driver); > destroy_workqueue(nfit_wq); > WARN_ON(!list_empty(&acpi_descs)); > } > --
Michal Wilczynski wrote: > NFIT driver uses struct acpi_driver incorrectly to register itself. > This is wrong as the instances of the ACPI devices are not meant > to be literal devices, they're supposed to describe ACPI entry of a > particular device. > > Use platform_driver instead of acpi_driver. In relevant places call > platform devices instances pdev to make a distinction with ACPI > devices instances. > > NFIT driver uses devm_*() family of functions extensively. This change > has no impact on correct functioning of the whole devm_*() family of > functions, since the lifecycle of the device stays the same. It is still > being created during the enumeration, and destroyed on platform device > removal. I notice this verbiage has the same fundamental misunderstanding of devm allocation lifetime as the acpi_nfit_init_interleave_set() discussion. The devm allocation lifetime typically starts in driver->probe() and ends either with driver->probe() failure, or the driver->remove() call. Note that the driver->remove() call is invoked not only for platform-device removal, but also driver "unbind" events. So the "destroyed on platform device removal" is the least likely way that these allocations are torn down given ACPI0012 devices are never removed. Outside of that, my main concern about this patch is that I expect it breaks unit tests. The infrastructure in tools/testing/nvdimm/test/nfit.c emulates an ACPI0012 device that allows for deeper regression testing given hardware is difficult to come by, and because QEMU does not implement some of the tricky corner cases that the unit tests cover. This needs to pass tests, but fair warning, tools/testing/nvdimm/test/nfit.c does some non-idiomatic + "strange" things to achieve deeper test coverage. So I expect that if this breaks tests as I expect the effort needed to fix the emulation could be significant. If you want to give running the tests a try the easiest would be to use "run_qemu.sh" with --nfit-test option [1], or you can try to setup an environment manually using the ndctl instructions [2]. [1]: https://github.com/pmem/run_qemu [2]: https://github.com/pmem/ndctl#readme
On 10/17/2023 8:24 PM, Dan Williams wrote: > Michal Wilczynski wrote: >> NFIT driver uses struct acpi_driver incorrectly to register itself. >> This is wrong as the instances of the ACPI devices are not meant >> to be literal devices, they're supposed to describe ACPI entry of a >> particular device. >> >> Use platform_driver instead of acpi_driver. In relevant places call >> platform devices instances pdev to make a distinction with ACPI >> devices instances. >> >> NFIT driver uses devm_*() family of functions extensively. This change >> has no impact on correct functioning of the whole devm_*() family of >> functions, since the lifecycle of the device stays the same. It is still >> being created during the enumeration, and destroyed on platform device >> removal. > I notice this verbiage has the same fundamental misunderstanding of devm > allocation lifetime as the acpi_nfit_init_interleave_set() discussion. > The devm allocation lifetime typically starts in driver->probe() and > ends either with driver->probe() failure, or the driver->remove() call. > Note that the driver->remove() call is invoked not only for > platform-device removal, but also driver "unbind" events. So the > "destroyed on platform device removal" is the least likely way that > these allocations are torn down given ACPI0012 devices are never > removed. > > Outside of that, my main concern about this patch is that I expect it > breaks unit tests. The infrastructure in > tools/testing/nvdimm/test/nfit.c emulates an ACPI0012 device that allows > for deeper regression testing given hardware is difficult to come by, > and because QEMU does not implement some of the tricky corner cases that > the unit tests cover. > > This needs to pass tests, but fair warning, > tools/testing/nvdimm/test/nfit.c does some non-idiomatic + "strange" > things to achieve deeper test coverage. So I expect that if this breaks > tests as I expect the effort needed to fix the emulation could be > significant. > > If you want to give running the tests a try the easiest would be to use > "run_qemu.sh" with --nfit-test option [1], or you can try to setup an > environment manually using the ndctl instructions [2]. > > [1]: https://github.com/pmem/run_qemu > [2]: https://github.com/pmem/ndctl#readme Thanks a lot ! I will run qemu tests and fix the verbiage, Michał
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 942b84d94078..fb0bc16fa186 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -15,6 +15,7 @@ #include <linux/sort.h> #include <linux/io.h> #include <linux/nd.h> +#include <linux/platform_device.h> #include <asm/cacheflush.h> #include <acpi/nfit.h> #include "intel.h" @@ -98,7 +99,7 @@ static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) return NULL; - return to_acpi_device(acpi_desc->dev); + return ACPI_COMPANION(acpi_desc->dev); } static int xlat_bus_status(void *buf, unsigned int cmd, u32 status) @@ -3284,11 +3285,11 @@ static void acpi_nfit_put_table(void *table) static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_device *adev = data; + struct device *dev = data; - device_lock(&adev->dev); - __acpi_nfit_notify(&adev->dev, handle, event); - device_unlock(&adev->dev); + device_lock(dev); + __acpi_nfit_notify(dev, handle, event); + device_unlock(dev); } static void acpi_nfit_remove_notify_handler(void *data) @@ -3329,11 +3330,12 @@ void acpi_nfit_shutdown(void *data) } EXPORT_SYMBOL_GPL(acpi_nfit_shutdown); -static int acpi_nfit_add(struct acpi_device *adev) +static int acpi_nfit_probe(struct platform_device *pdev) { struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_nfit_desc *acpi_desc; - struct device *dev = &adev->dev; + struct device *dev = &pdev->dev; + struct acpi_device *adev = ACPI_COMPANION(dev); struct acpi_table_header *tbl; acpi_status status = AE_OK; acpi_size sz; @@ -3360,7 +3362,7 @@ static int acpi_nfit_add(struct acpi_device *adev) acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); if (!acpi_desc) return -ENOMEM; - acpi_nfit_desc_init(acpi_desc, &adev->dev); + acpi_nfit_desc_init(acpi_desc, dev); /* Save the acpi header for exporting the revision via sysfs */ acpi_desc->acpi_header = *tbl; @@ -3391,7 +3393,7 @@ static int acpi_nfit_add(struct acpi_device *adev) return rc; rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, - acpi_nfit_notify, adev); + acpi_nfit_notify, dev); if (rc) return rc; @@ -3475,11 +3477,11 @@ static const struct acpi_device_id acpi_nfit_ids[] = { }; MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); -static struct acpi_driver acpi_nfit_driver = { - .name = KBUILD_MODNAME, - .ids = acpi_nfit_ids, - .ops = { - .add = acpi_nfit_add, +static struct platform_driver acpi_nfit_driver = { + .probe = acpi_nfit_probe, + .driver = { + .name = KBUILD_MODNAME, + .acpi_match_table = acpi_nfit_ids, }, }; @@ -3517,7 +3519,7 @@ static __init int nfit_init(void) return -ENOMEM; nfit_mce_register(); - ret = acpi_bus_register_driver(&acpi_nfit_driver); + ret = platform_driver_register(&acpi_nfit_driver); if (ret) { nfit_mce_unregister(); destroy_workqueue(nfit_wq); @@ -3530,7 +3532,7 @@ static __init int nfit_init(void) static __exit void nfit_exit(void) { nfit_mce_unregister(); - acpi_bus_unregister_driver(&acpi_nfit_driver); + platform_driver_unregister(&acpi_nfit_driver); destroy_workqueue(nfit_wq); WARN_ON(!list_empty(&acpi_descs)); }