From patchwork Mon Sep 25 14:48:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 727172 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AE791B26E for ; Mon, 25 Sep 2023 14:49:19 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA61103; Mon, 25 Sep 2023 07:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653357; x=1727189357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EOpMdyO7SSMZsEAVB9fj7jJCWOYh0eXeQ8klAvIERWQ=; b=MwJ030Bha82rB/OPDz5iQg9yN5Ub1zDpOn45B8SbyeRZc1zkgUdita0x 40ijouFxZ0lH+2aLgShEB6NEWJ6Pekoi2d8fA5pVw+Mey6lize9ATVjFb B9jC/Ga1z2qIB3lER3ZhXIQdYbKKwF1sbfdxRPehzhCDxy8LUkh5ZeI72 DRUf0CQ/s6t1arImyFh2DUgiLv+0wEn65qiMx0J59k37wPEzprJmKayTo KHJRf13BReubkQTTCvnU9pcGBpSBhU/QMp6rZ5K3+36ss/zKrxQHgUm2X V0tV0vnly6kamYadBFydq9GuqOhvVQJk4wZLD/z3VIBQabhv9eMujV55i w==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378547975" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378547975" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409421" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409421" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:14 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski , Andy Shevchenko Subject: [PATCH v1 1/9] ACPI: bus: Make notify wrappers more generic Date: Mon, 25 Sep 2023 17:48:34 +0300 Message-ID: <20230925144842.586829-2-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 acpi_dev_install_notify_handler() and acpi_dev_remove_notify_handler() are wrappers around ACPICA installers. They are meant to save some duplicated code from drivers. However as we're moving towards drivers operating on platform_device they become a bit inconvenient to use as inside the driver code we mostly want to use driver data of platform device instead of ACPI device. Make notify handlers installer wrappers more generic, while still saving some code that would be duplicated otherwise. Reviewed-by: Andy Shevchenko Signed-off-by: Michal Wilczynski Signed-off-by: Michal Wilczynski Signed-off-by: Rafael J. Wysocki --- Notes: So one solution could be to just replace acpi_device with platform_device as an argument in those functions. However I don't believe this is a correct solution, as it is very often the case that drivers declare their own private structures which gets allocated during the .probe() callback, and become the heart of the driver. When drivers do that it makes much more sense to just pass the private structure to the notify handler instead of forcing user to dance with the platform_device or acpi_device. drivers/acpi/ac.c | 6 +++--- drivers/acpi/acpi_video.c | 6 +++--- drivers/acpi/battery.c | 6 +++--- drivers/acpi/bus.c | 14 ++++++-------- drivers/acpi/hed.c | 6 +++--- drivers/acpi/nfit/core.c | 6 +++--- drivers/acpi/thermal.c | 6 +++--- include/acpi/acpi_bus.h | 9 ++++----- 8 files changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 225dc6818751..0b245f9f7ec8 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -256,8 +256,8 @@ static int acpi_ac_add(struct acpi_device *device) ac->battery_nb.notifier_call = acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); - result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY, - acpi_ac_notify); + result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY, + acpi_ac_notify, device); if (result) goto err_unregister; @@ -306,7 +306,7 @@ static void acpi_ac_remove(struct acpi_device *device) ac = acpi_driver_data(device); - acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, + acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, acpi_ac_notify); power_supply_unregister(ac->charger); unregister_acpi_notifier(&ac->battery_nb); diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 948e31f7ce6e..025c17890127 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -2059,8 +2059,8 @@ static int acpi_video_bus_add(struct acpi_device *device) acpi_video_bus_add_notify_handler(video); - error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, - acpi_video_bus_notify); + error = acpi_dev_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_video_bus_notify, device); if (error) goto err_remove; @@ -2092,7 +2092,7 @@ static void acpi_video_bus_remove(struct acpi_device *device) video = acpi_driver_data(device); - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, + acpi_dev_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_video_bus_notify); mutex_lock(&video_list_lock); diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 969bf81e8d54..45dae32a8646 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1213,8 +1213,8 @@ static int acpi_battery_add(struct acpi_device *device) device_init_wakeup(&device->dev, 1); - result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY, - acpi_battery_notify); + result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY, + acpi_battery_notify, device); if (result) goto fail_pm; @@ -1241,7 +1241,7 @@ static void acpi_battery_remove(struct acpi_device *device) battery = acpi_driver_data(device); - acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, + acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, acpi_battery_notify); device_init_wakeup(&device->dev, 0); diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index f41dda2d3493..479fe888d629 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -554,14 +554,13 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device, acpi_os_wait_events_complete(); } -int acpi_dev_install_notify_handler(struct acpi_device *adev, - u32 handler_type, - acpi_notify_handler handler) +int acpi_dev_install_notify_handler(acpi_handle handle, u32 handler_type, + acpi_notify_handler handler, void *context) { acpi_status status; - status = acpi_install_notify_handler(adev->handle, handler_type, - handler, adev); + status = acpi_install_notify_handler(handle, handler_type, + handler, context); if (ACPI_FAILURE(status)) return -ENODEV; @@ -569,11 +568,10 @@ int acpi_dev_install_notify_handler(struct acpi_device *adev, } EXPORT_SYMBOL_GPL(acpi_dev_install_notify_handler); -void acpi_dev_remove_notify_handler(struct acpi_device *adev, - u32 handler_type, +void acpi_dev_remove_notify_handler(acpi_handle handle, u32 handler_type, acpi_notify_handler handler) { - acpi_remove_notify_handler(adev->handle, handler_type, handler); + acpi_remove_notify_handler(handle, handler_type, handler); acpi_os_wait_events_complete(); } EXPORT_SYMBOL_GPL(acpi_dev_remove_notify_handler); diff --git a/drivers/acpi/hed.c b/drivers/acpi/hed.c index 46c6f8c35b43..e7e274c5cc9e 100644 --- a/drivers/acpi/hed.c +++ b/drivers/acpi/hed.c @@ -56,8 +56,8 @@ static int acpi_hed_add(struct acpi_device *device) return -EINVAL; hed_handle = device->handle; - err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, - acpi_hed_notify); + err = acpi_dev_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_hed_notify, device); if (err) hed_handle = NULL; @@ -66,7 +66,7 @@ static int acpi_hed_add(struct acpi_device *device) static void acpi_hed_remove(struct acpi_device *device) { - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, + acpi_dev_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_hed_notify); hed_handle = NULL; } diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index f0e6738ae3c9..821870f57862 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -3295,7 +3295,7 @@ static void acpi_nfit_remove_notify_handler(void *data) { struct acpi_device *adev = data; - acpi_dev_remove_notify_handler(adev, ACPI_DEVICE_NOTIFY, + acpi_dev_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, acpi_nfit_notify); } @@ -3390,8 +3390,8 @@ static int acpi_nfit_add(struct acpi_device *adev) if (rc) return rc; - rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, - acpi_nfit_notify); + rc = acpi_dev_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, + acpi_nfit_notify, adev); if (rc) return rc; diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 10720a038846..0218c34c16b9 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -978,8 +978,8 @@ static int acpi_thermal_add(struct acpi_device *device) pr_info("%s [%s] (%ld C)\n", acpi_device_name(device), acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); - result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, - acpi_thermal_notify); + result = acpi_dev_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_thermal_notify, device); if (result) goto flush_wq; @@ -1005,7 +1005,7 @@ static void acpi_thermal_remove(struct acpi_device *device) tz = acpi_driver_data(device); - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, + acpi_dev_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_thermal_notify); flush_workqueue(acpi_thermal_pm_queue); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 254685085c82..95d5193f236f 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -515,11 +515,10 @@ void acpi_bus_private_data_handler(acpi_handle, void *); int acpi_bus_get_private_data(acpi_handle, void **); int acpi_bus_attach_private_data(acpi_handle, void *); void acpi_bus_detach_private_data(acpi_handle); -int acpi_dev_install_notify_handler(struct acpi_device *adev, - u32 handler_type, - acpi_notify_handler handler); -void acpi_dev_remove_notify_handler(struct acpi_device *adev, - u32 handler_type, +int acpi_dev_install_notify_handler(acpi_handle handle, u32 handler_type, + acpi_notify_handler handler, + void *context); +void acpi_dev_remove_notify_handler(acpi_handle handle, u32 handler_type, acpi_notify_handler handler); extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32); extern int register_acpi_notifier(struct notifier_block *); From patchwork Mon Sep 25 14:48:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 726091 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD5621B26E for ; Mon, 25 Sep 2023 14:49:21 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9DE410D; Mon, 25 Sep 2023 07:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653360; x=1727189360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kKM0C1N1K+zAFPffptjtDRXafSmi9wPq9IOl4rSEZ+w=; b=KU7oTXe589HSPT7zJQNqxkMYszEiWVPVwB3Ob9lQJeP2teERWklZmlKK BbpTAIA8nQPi3RMDrja5G3Y53A41uLYcfL35dqkfr2aSMmN9AFYtxfedX YORFQpdbhlw6Rm8bYgf1iyNST45NOgTM/FBNyb6l/fqXbiiIyQP1rkJs3 22YFkdUIanBMjGGSAxEcrSo6RAAoNRE6v+jPCUTglXIw83Vpd3SFKQasG pbLV4I71ZlpsZFFvDYI09CygX7Bat/LHJT5mXHEMnwsP6TeRICVLGZx4j 9ffGpeOooFxyVVpLhbcyDbtbvFuF35k8+ngqThQzctUWH2/SzAs2w6a7S g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378547987" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378547987" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409451" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409451" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:17 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski , Elena Reshetova Subject: [PATCH v1 2/9] docs: firmware-guide: ACPI: Clarify ACPI bus concepts Date: Mon, 25 Sep 2023 17:48:35 +0300 Message-ID: <20230925144842.586829-3-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Some devices implement ACPI driver as a way to manage devices enumerated by the ACPI. This might be confusing as a preferred way to implement a driver for devices not connected to any bus is a platform driver, as stated in the documentation. Clarify relationships between ACPI device, platform device and ACPI entries. Suggested-by: Elena Reshetova Signed-off-by: Michal Wilczynski Signed-off-by: Michal Wilczynski Signed-off-by: Rafael J. Wysocki --- Documentation/firmware-guide/acpi/enumeration.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/firmware-guide/acpi/enumeration.rst b/Documentation/firmware-guide/acpi/enumeration.rst index 56d9913a3370..f56cc79a9e83 100644 --- a/Documentation/firmware-guide/acpi/enumeration.rst +++ b/Documentation/firmware-guide/acpi/enumeration.rst @@ -64,6 +64,19 @@ If the driver needs to perform more complex initialization like getting and configuring GPIOs it can get its ACPI handle and extract this information from ACPI tables. +ACPI bus +==================== + +Historically some devices not connected to any bus were represented as ACPI +devices, and had to implement ACPI driver. This is not a preferred way for new +drivers. As explained above devices not connected to any bus should implement +platform driver. ACPI device would be created during enumeration nonetheless, +and would be accessible through ACPI_COMPANION() macro, and the ACPI handle would +be accessible through ACPI_HANDLE() macro. ACPI device is meant to describe +information related to ACPI entry e.g. handle of the ACPI entry. Think - +ACPI device interfaces with the FW, and the platform device with the rest of +the system. + DMA support =========== From patchwork Mon Sep 25 14:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 727171 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8418B1C295 for ; Mon, 25 Sep 2023 14:49:25 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A394103; Mon, 25 Sep 2023 07:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653364; x=1727189364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q+/woL1SUetoYx4WHnjb+jA28q5j/h55czCXRHM5v18=; b=EVi4jwC78Q1kyaVDxLOHzLEeZDGfnBCaQC5dthhyBxUmQ34rkB4u6e9r gmFQT2EcKdcqYtGagkSC59CveZKxXn2h6koVUbyd37cNkVrTtg4pfpoyo DOkVf0Uk2U4+emLvjtCRUzxWooTyihQq0n5gCIRATNbZadLCxYVksb/XB loyy79sN03mC6Mr330R9Fqhe+Px9f1fllLNUAJsnIR1vCZQxN9spafy7+ cgnY+X4knkUYGiyuf38lZFAgYvQvlF2HLDQZACEOSVVTN44UqMTHVromg 3rrtTOwSU7FDMsF1ZCIiIH9fo2bVOAyxIq7j608hoJYoXO220zdZsr/ad A==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548004" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548004" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409465" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409465" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:20 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski Subject: [PATCH v1 3/9] ACPI: AC: Remove unnecessary checks Date: Mon, 25 Sep 2023 17:48:36 +0300 Message-ID: <20230925144842.586829-4-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Remove unnecessary checks for NULL for variables that can't be NULL at the point they're checked for it. Defensive programming is discouraged in the kernel. Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 0b245f9f7ec8..dd04809a787c 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -131,9 +131,6 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) struct acpi_device *device = data; struct acpi_ac *ac = acpi_driver_data(device); - if (!ac) - return; - switch (event) { default: acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", @@ -216,12 +213,8 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { static int acpi_ac_add(struct acpi_device *device) { struct power_supply_config psy_cfg = {}; - int result = 0; - struct acpi_ac *ac = NULL; - - - if (!device) - return -EINVAL; + struct acpi_ac *ac; + int result; ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); if (!ac) @@ -275,16 +268,9 @@ static int acpi_ac_add(struct acpi_device *device) #ifdef CONFIG_PM_SLEEP static int acpi_ac_resume(struct device *dev) { - struct acpi_ac *ac; + struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev)); unsigned int old_state; - if (!dev) - return -EINVAL; - - ac = acpi_driver_data(to_acpi_device(dev)); - if (!ac) - return -EINVAL; - old_state = ac->state; if (acpi_ac_get_state(ac)) return 0; @@ -299,12 +285,7 @@ static int acpi_ac_resume(struct device *dev) static void acpi_ac_remove(struct acpi_device *device) { - struct acpi_ac *ac = NULL; - - if (!device || !acpi_driver_data(device)) - return; - - ac = acpi_driver_data(device); + struct acpi_ac *ac = acpi_driver_data(device); acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, acpi_ac_notify); From patchwork Mon Sep 25 14:48:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 726090 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 740CF1C292 for ; Mon, 25 Sep 2023 14:49:28 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E70410A; Mon, 25 Sep 2023 07:49: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=1695653367; x=1727189367; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xZAL9mmtzBPLoZZSRbfxi5bVlGrr6Q3oM+Pk6Zg20eI=; b=UgJil9CmSO2JpnhC5hj8HoAKXqtY+uWCRB+TgpJEKj/8CeufrVA6xI3u Al7aVokcbCw74VvC4puHBy9PD46od19ZxjWxzNnlQuRHDvWVRYvTVWSAH INLHX/yzVYicwO8k1H41Ju7EQftBIdTxXOno90ozmHQXsCCBcYAXDtwI6 mu0BGBcAXme1aKv3MJiPW1q3kELLTM8VAutGgqhtxQypnnVi031Cm9Uq+ hwhpbrrJNUsg/6uPuU32LUjVIrO1nfYVm3/3E7Pp+X+MMwiiSuyrzJh2L 8M8gRwhHe+2Dk67gSF22YKAf8lx/EV2TeiThY5JEgKq5pat3q/H55/sad Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548032" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548032" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409476" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409476" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:24 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski , Andy Shevchenko Subject: [PATCH v1 4/9] ACPI: AC: Use string_choices API instead of ternary operator Date: Mon, 25 Sep 2023 17:48:37 +0300 Message-ID: <20230925144842.586829-5-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Use modern string_choices API instead of manually determining the output using ternary operator. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index dd04809a787c..fd8b392c19f4 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -243,8 +244,8 @@ static int acpi_ac_add(struct acpi_device *device) goto err_release_ac; } - pr_info("%s [%s] (%s)\n", acpi_device_name(device), - acpi_device_bid(device), ac->state ? "on-line" : "off-line"); + pr_info("%s [%s] (%s-line)\n", acpi_device_name(device), + acpi_device_bid(device), str_on_off(ac->state)); ac->battery_nb.notifier_call = acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); From patchwork Mon Sep 25 14:48:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 727170 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF17F1C290 for ; Mon, 25 Sep 2023 14:49:32 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EAF1115; Mon, 25 Sep 2023 07:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653371; x=1727189371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=udNVWtN1gsWM7DD6E00ZbxnbAjYrIGT/BzPOH3ZhiRo=; b=GO1gFzNFI0U4XW/tjGCm7tqbvUj771rkCZ8li1VEzXDiHlwZQtITX089 T+2I2OajF8Spl7AQGG1Y8eNfnmLC5maFnxP3g/M4XPb+FYxvNjRBWjtZM dP1UqBNVL1JGLpcbs8qfCTDYwH+PIBos+GlskCyspVq/loz1SdYiXd8Zr POY5d+u2w3npX7HzDcqeY6sAoiwLpFCOoGGBLUr44lkir49Qe6LD+6OII kNjy4Qu2AMLmCbVWPL4Np2Z3tCGUJ4/dbQ48RPTZlTt/CVCvp+AshcH9q yQ5pljCFvbc9W68JLx6CeWmGcuVWYP3GWVPQcnqyY94G+74SM60yqllRL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548072" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548072" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409490" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409490" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:27 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski Subject: [PATCH v1 5/9] ACPI: AC: Replace acpi_driver with platform_driver Date: Mon, 25 Sep 2023 17:48:38 +0300 Message-ID: <20230925144842.586829-6-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 AC 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. Drop unnecessary casts from acpi_bus_generate_netlink_event() and acpi_notifier_call_chain(). Add a blank line to distinguish pdev API vs local ACPI notify function. Suggested-by: Rafael J. Wysocki Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 70 +++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index fd8b392c19f4..78e53d0fdece 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -33,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh"); MODULE_DESCRIPTION("ACPI AC Adapter Driver"); MODULE_LICENSE("GPL"); -static int acpi_ac_add(struct acpi_device *device); -static void acpi_ac_remove(struct acpi_device *device); +static int acpi_ac_probe(struct platform_device *pdev); +static void acpi_ac_remove(struct platform_device *pdev); + static void acpi_ac_notify(acpi_handle handle, u32 event, void *data); static const struct acpi_device_id ac_device_ids[] = { @@ -51,21 +52,10 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume); static int ac_sleep_before_get_state_ms; static int ac_only; -static struct acpi_driver acpi_ac_driver = { - .name = "ac", - .class = ACPI_AC_CLASS, - .ids = ac_device_ids, - .ops = { - .add = acpi_ac_add, - .remove = acpi_ac_remove, - }, - .drv.pm = &acpi_ac_pm, -}; - struct acpi_ac { struct power_supply *charger; struct power_supply_desc charger_desc; - struct acpi_device *device; + struct device *dev; unsigned long long state; struct notifier_block battery_nb; }; @@ -85,10 +75,10 @@ static int acpi_ac_get_state(struct acpi_ac *ac) return 0; } - status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, + status = acpi_evaluate_integer(ACPI_HANDLE(ac->dev), "_PSR", NULL, &ac->state); if (ACPI_FAILURE(status)) { - acpi_handle_info(ac->device->handle, + acpi_handle_info(ACPI_HANDLE(ac->dev), "Error reading AC Adapter state: %s\n", acpi_format_exception(status)); ac->state = ACPI_AC_STATUS_UNKNOWN; @@ -129,12 +119,12 @@ static enum power_supply_property ac_props[] = { /* Driver Model */ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_device *device = data; - struct acpi_ac *ac = acpi_driver_data(device); + struct acpi_ac *ac = data; + struct acpi_device *device = ACPI_COMPANION(ac->dev); switch (event) { default: - acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", + acpi_handle_debug(ACPI_HANDLE(ac->dev), "Unsupported event [0x%x]\n", event); fallthrough; case ACPI_AC_NOTIFY_STATUS: @@ -152,9 +142,10 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) acpi_ac_get_state(ac); acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, - (u32) ac->state); - acpi_notifier_call_chain(device, event, (u32) ac->state); + dev_name(ac->dev), + event, + ac->state); + acpi_notifier_call_chain(device, event, ac->state); kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE); } } @@ -211,8 +202,9 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { {}, }; -static int acpi_ac_add(struct acpi_device *device) +static int acpi_ac_probe(struct platform_device *pdev) { + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct power_supply_config psy_cfg = {}; struct acpi_ac *ac; int result; @@ -221,10 +213,11 @@ static int acpi_ac_add(struct acpi_device *device) if (!ac) return -ENOMEM; - ac->device = device; + ac->dev = &pdev->dev; strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_AC_CLASS); - device->driver_data = ac; + + platform_set_drvdata(pdev, ac); result = acpi_ac_get_state(ac); if (result) @@ -237,7 +230,7 @@ static int acpi_ac_add(struct acpi_device *device) ac->charger_desc.properties = ac_props; ac->charger_desc.num_properties = ARRAY_SIZE(ac_props); ac->charger_desc.get_property = get_ac_property; - ac->charger = power_supply_register(&ac->device->dev, + ac->charger = power_supply_register(&pdev->dev, &ac->charger_desc, &psy_cfg); if (IS_ERR(ac->charger)) { result = PTR_ERR(ac->charger); @@ -251,7 +244,7 @@ static int acpi_ac_add(struct acpi_device *device) register_acpi_notifier(&ac->battery_nb); result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY, - acpi_ac_notify, device); + acpi_ac_notify, ac); if (result) goto err_unregister; @@ -269,7 +262,7 @@ static int acpi_ac_add(struct acpi_device *device) #ifdef CONFIG_PM_SLEEP static int acpi_ac_resume(struct device *dev) { - struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev)); + struct acpi_ac *ac = dev_get_drvdata(dev); unsigned int old_state; old_state = ac->state; @@ -284,11 +277,12 @@ static int acpi_ac_resume(struct device *dev) #define acpi_ac_resume NULL #endif -static void acpi_ac_remove(struct acpi_device *device) +static void acpi_ac_remove(struct platform_device *pdev) { - struct acpi_ac *ac = acpi_driver_data(device); + struct acpi_ac *ac = platform_get_drvdata(pdev); - acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, + acpi_dev_remove_notify_handler(ACPI_HANDLE(ac->dev), + ACPI_ALL_NOTIFY, acpi_ac_notify); power_supply_unregister(ac->charger); unregister_acpi_notifier(&ac->battery_nb); @@ -296,6 +290,16 @@ static void acpi_ac_remove(struct acpi_device *device) kfree(ac); } +static struct platform_driver acpi_ac_driver = { + .probe = acpi_ac_probe, + .remove_new = acpi_ac_remove, + .driver = { + .name = "ac", + .acpi_match_table = ac_device_ids, + .pm = &acpi_ac_pm, + }, +}; + static int __init acpi_ac_init(void) { int result; @@ -308,7 +312,7 @@ static int __init acpi_ac_init(void) dmi_check_system(ac_dmi_table); - result = acpi_bus_register_driver(&acpi_ac_driver); + result = platform_driver_register(&acpi_ac_driver); if (result < 0) return -ENODEV; @@ -317,7 +321,7 @@ static int __init acpi_ac_init(void) static void __exit acpi_ac_exit(void) { - acpi_bus_unregister_driver(&acpi_ac_driver); + platform_driver_unregister(&acpi_ac_driver); } module_init(acpi_ac_init); module_exit(acpi_ac_exit); From patchwork Mon Sep 25 14:48:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 726089 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F67A1C290 for ; Mon, 25 Sep 2023 14:49:35 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AEDD11F; Mon, 25 Sep 2023 07:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653374; x=1727189374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mYPynKrPz0jMpTI6VpPGiWDqPkes4HHVCp3jJnlrK8c=; b=DaxDdZaaxX+RQlUY+pmUI5BpufhTY9g4g0f7n6/lR2cPdPI4uptG74zv 9OMpo+u5y9na+O4zyq+oRFTeMgG2psfmZS1UvNK1bNIOtKtDYvqEZey0x YN6AGJbn4uQDzob8xJ7IxX9I40Ri8IL2+QTk6n37V1VNBQrwXcCXq5mJV NnPVj437WplTKdt/QlANxPMMAUcNrm7IUkOzBNbfoFRSiOOvVemQjp0k0 P8gOooFUQ0xxYnT1CGB16BkPTzniehEJPv8+Kg3ed0rYsLyABHdtWvjNS EWbqd5lEDK04Yg5+4HtBR1wBBFsfArrK5pvHSbqVkaLJGUP+nu113bnWA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548078" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548078" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409503" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409503" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:31 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski Subject: [PATCH v1 6/9] ACPI: AC: Rename ACPI device from device to adev Date: Mon, 25 Sep 2023 17:48:39 +0300 Message-ID: <20230925144842.586829-7-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Since transformation from ACPI driver to platform driver there are two devices on which the driver operates - ACPI device and platform device. For the sake of reader this calls for the distinction in their naming, to avoid confusion. Rename device to adev, as corresponding platform device is called pdev. Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 78e53d0fdece..270a6919ec12 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -120,7 +120,7 @@ static enum power_supply_property ac_props[] = { static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) { struct acpi_ac *ac = data; - struct acpi_device *device = ACPI_COMPANION(ac->dev); + struct acpi_device *adev = ACPI_COMPANION(ac->dev); switch (event) { default: @@ -141,11 +141,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) msleep(ac_sleep_before_get_state_ms); acpi_ac_get_state(ac); - acpi_bus_generate_netlink_event(device->pnp.device_class, + acpi_bus_generate_netlink_event(adev->pnp.device_class, dev_name(ac->dev), event, ac->state); - acpi_notifier_call_chain(device, event, ac->state); + acpi_notifier_call_chain(adev, event, ac->state); kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE); } } @@ -204,7 +204,7 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { static int acpi_ac_probe(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); struct power_supply_config psy_cfg = {}; struct acpi_ac *ac; int result; @@ -214,8 +214,8 @@ static int acpi_ac_probe(struct platform_device *pdev) return -ENOMEM; ac->dev = &pdev->dev; - strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); - strcpy(acpi_device_class(device), ACPI_AC_CLASS); + strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME); + strcpy(acpi_device_class(adev), ACPI_AC_CLASS); platform_set_drvdata(pdev, ac); @@ -225,7 +225,7 @@ static int acpi_ac_probe(struct platform_device *pdev) psy_cfg.drv_data = ac; - ac->charger_desc.name = acpi_device_bid(device); + ac->charger_desc.name = acpi_device_bid(adev); ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS; ac->charger_desc.properties = ac_props; ac->charger_desc.num_properties = ARRAY_SIZE(ac_props); @@ -237,13 +237,13 @@ static int acpi_ac_probe(struct platform_device *pdev) goto err_release_ac; } - pr_info("%s [%s] (%s-line)\n", acpi_device_name(device), - acpi_device_bid(device), str_on_off(ac->state)); + pr_info("%s [%s] (%s-line)\n", acpi_device_name(adev), + acpi_device_bid(adev), str_on_off(ac->state)); ac->battery_nb.notifier_call = acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); - result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY, + result = acpi_dev_install_notify_handler(adev->handle, ACPI_ALL_NOTIFY, acpi_ac_notify, ac); if (result) goto err_unregister; From patchwork Mon Sep 25 14:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 727169 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B8FB1C295 for ; Mon, 25 Sep 2023 14:49:40 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C3510F; Mon, 25 Sep 2023 07:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653378; x=1727189378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8mnjbIMRHs3Br7O5LAy7rYDYZ+KkPj/05DV8Q4PK/as=; b=Ngxp6iN4bf6PUispXDUCiaHVWJQZHi9XTfdLu0z5q5FUs3NQmSM9PZls o+8eHiayszqWXS22HSvXCaUA8h1C6PdBsynWfmtLQ4BC8epEhQ0B3V2nh Bm219VCyYPEUZQg118Zri6Uirmvg49im/VL/uHqLO+qghKKUyRZI6O9Cr U8uXEhwGQXx8WDNnDw0+Usx5p+kpdGMr4jePh46UKgZUPbLfLQmxcGUY5 yUtgsurfiLPJW9KspZPSuohPmo0y8571/29MZoPWcnrQ3e6lujdeJ8K/O wTsXlcAAXlknkqsDQHVJ/P5j2GHRSnvr/KE7Qt/2sniS6ardTkokuCnGQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548090" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548090" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409527" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409527" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:34 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski Subject: [PATCH v1 7/9] ACPI: NFIT: Replace acpi_driver with platform_driver Date: Mon, 25 Sep 2023 17:48:40 +0300 Message-ID: <20230925144842.586829-8-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 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 Signed-off-by: Michal Wilczynski --- 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 821870f57862..2e50b1334a69 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #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->handle, 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)); } From patchwork Mon Sep 25 14:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 726088 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25BF71C295 for ; Mon, 25 Sep 2023 14:49:42 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D52101; Mon, 25 Sep 2023 07:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653381; x=1727189381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jbGtAhlIOf5ZMHSV2QC6o312WQ2sCWdKpbJB2MYMJ8Q=; b=beq2tsCw0FGjtofiWfAKbPEGGyPBjX3mQimvD2+vUyNlzA0kDouDnKaY DFLRCtSlBSOifTEU4YlQWQxCHQLnDST5OEhr+P1PcMqeBIS78ywFyLDMI H01trsy+TudV5qifkiWJZWFTPMEb/Oxk4xFWxhTatgpYV3fbaInHjNPlY RZQIfxpr1FnY2x2z3AhMOP8DO80/2mdRgJc2IoZWX/MwQWpihrWqpHb1y NfbN2wfzy1To3+6yWiCDR8mLDR5papHgTEo0tgoWNAPZgUvi3WOIXmbSO l+LGsp/KbjcbLM4AaiVxz5LniQiiu/BgMsgCtZJQgd/kDb5oGoMVGd8So Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548098" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548098" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409547" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409547" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:37 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski , Andy Shevchenko Subject: [PATCH v1 8/9] ACPI: NFIT: Remove redundant call to to_acpi_dev() Date: Mon, 25 Sep 2023 17:48:41 +0300 Message-ID: <20230925144842.586829-9-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 In acpi_nfit_ctl() ACPI handle is extracted using to_acpi_dev() function and accessing handle field in ACPI device. After transformation from ACPI driver to platform driver this is not optimal anymore. To get a handle it's enough to just use ACPI_HANDLE() macro to extract the handle. Suggested-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- drivers/acpi/nfit/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 2e50b1334a69..f09530d2520a 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -475,8 +475,6 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, guid = to_nfit_uuid(nfit_mem->family); handle = adev->handle; } else { - struct acpi_device *adev = to_acpi_dev(acpi_desc); - cmd_name = nvdimm_bus_cmd_name(cmd); cmd_mask = nd_desc->cmd_mask; if (cmd == ND_CMD_CALL && call_pkg->nd_family) { @@ -493,7 +491,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, guid = to_nfit_uuid(NFIT_DEV_BUS); } desc = nd_cmd_bus_desc(cmd); - handle = adev->handle; + handle = ACPI_HANDLE(dev); dimm_name = "bus"; } From patchwork Mon Sep 25 14:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wilczynski X-Patchwork-Id: 727168 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976A31C287 for ; Mon, 25 Sep 2023 14:49:52 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E9B180; Mon, 25 Sep 2023 07:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695653391; x=1727189391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=84m75FsmmCxHAs5Vy3y5UlBCIG1MzYs7Y5oMZFaEZNo=; b=PPliPTRYiWutXQRnH+SS2qS0dz3S0dZF04BfpK+qpTXcK778PhJuiUxN /+cWRoELWJdKYvtiT0Gy1NhmOyO1yJyMbjh0drpewkWM+/uo6d0jxmU2Q WwBWB3f48NWweQ1j0xx9/UuTCgEd2SnmolDr6S5xzzralceNHSzmwtuIi dYapuildU1x1FwLvG6cf4AbKMWgnPivaVBKuh4I02QpIBAtFcAJkKcKus b+WoRcavklTnjeMoDXW3dHWboqiLQ3d/6nyVhe3RCkACXpx6J4/Ws41sR 7nzjl6GVXIP1qfB6m6Ig84evbZ2eqoiIqVsIADZBYnNCBu98SpSltzzGZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="378548124" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="378548124" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="995409563" X-IronPort-AV: E=Sophos;i="6.03,175,1694761200"; d="scan'208";a="995409563" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 07:49:41 -0700 From: Michal Wilczynski 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, rui.zhang@intel.com, Michal Wilczynski , Andy Shevchenko Subject: [PATCH v1 9/9] ACPI: NFIT: Don't use KBUILD_MODNAME for driver name Date: Mon, 25 Sep 2023 17:48:42 +0300 Message-ID: <20230925144842.586829-10-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230925144842.586829-1-michal.wilczynski@intel.com> References: <20230925144842.586829-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Driver name is part of the ABI, so it should be hard-coded, as ABI should be always kept backward compatible. Prevent ABI from changing accidentally in case KBUILD_MODNAME change. Suggested-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- drivers/acpi/nfit/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index f09530d2520a..987eb5567036 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -3478,7 +3478,7 @@ MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); static struct platform_driver acpi_nfit_driver = { .probe = acpi_nfit_probe, .driver = { - .name = KBUILD_MODNAME, + .name = "nfit", .acpi_match_table = acpi_nfit_ids, }, };