From patchwork Mon Mar 13 18:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 662919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92257C6FD19 for ; Mon, 13 Mar 2023 18:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231379AbjCMScj (ORCPT ); Mon, 13 Mar 2023 14:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbjCMScC (ORCPT ); Mon, 13 Mar 2023 14:32:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3DB84F64; Mon, 13 Mar 2023 11:31:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D9C33B811DA; Mon, 13 Mar 2023 18:29:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 530E2C433D2; Mon, 13 Mar 2023 18:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678732196; bh=Gw4rh6R98Knq0Cq2eoi4WmQjdtPb9YzLDaUDTvYSyIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MXQiJ/sOvMKEbSllYfbGFpuz/RgUg5CL/sD49Lh4spZhIDmKdLEASRxJu6F9OEWo0 RgzpjuRpFz58tWFPvKUPt4XvmamKX1LQkc1r8RsUMfD5lBfDacU34gNkrwlaT2YVp6 aHyiZWw6EZxnraqJjj3f8guM0QKdDU5EReUhzjm0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Viresh Kumar , Srinivas Pandruvada , Len Brown , linux-pm@vger.kernel.org Subject: [PATCH 03/36] cpufreq: move to use bus_get_dev_root() Date: Mon, 13 Mar 2023 19:28:45 +0100 Message-Id: <20230313182918.1312597-3-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313182918.1312597-1-gregkh@linuxfoundation.org> References: <20230313182918.1312597-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2441; i=gregkh@linuxfoundation.org; h=from:subject; bh=Gw4rh6R98Knq0Cq2eoi4WmQjdtPb9YzLDaUDTvYSyIs=; b=owGbwMvMwCRo6H6F97bub03G02pJDCn82aUPCutMtKUNNhs9LOG6X3qh53xLZZPN5WkBnW9v2 0jrfvjZEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABNpqWeYH8otv4JPk5/ZeF3G 1QuTZM/qX97jxLBg1nPrCtdFvUvuvBAtKcluuPdCf8oEAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Direct access to the struct bus_type dev_root pointer is going away soon so replace that with a call to bus_get_dev_root() instead, which is what it is there for. Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: Srinivas Pandruvada Cc: Len Brown Cc: linux-pm@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki --- Note, this is a patch that is a prepatory cleanup as part of a larger series of patches that is working on resolving some old driver core design mistakes. It will build and apply cleanly on top of 6.3-rc2 on its own, but I'd prefer if I could take it through my driver-core tree so that the driver core changes can be taken through there for 6.4-rc1. drivers/cpufreq/cpufreq.c | 7 ++++++- drivers/cpufreq/intel_pstate.c | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 6d8fd3b8dcb5..6ad3119b8e15 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2932,11 +2932,16 @@ EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); static int __init cpufreq_core_init(void) { struct cpufreq_governor *gov = cpufreq_default_governor(); + struct device *dev_root; if (cpufreq_disabled()) return -ENODEV; - cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); + dev_root = bus_get_dev_root(&cpu_subsys); + if (dev_root) { + cpufreq_global_kobject = kobject_create_and_add("cpufreq", &dev_root->kobj); + put_device(dev_root); + } BUG_ON(!cpufreq_global_kobject); if (!strlen(default_governor)) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 48a4613cef1e..102cf7f0ac63 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -1473,10 +1473,13 @@ static struct kobject *intel_pstate_kobject; static void __init intel_pstate_sysfs_expose_params(void) { + struct device *dev_root = bus_get_dev_root(&cpu_subsys); int rc; - intel_pstate_kobject = kobject_create_and_add("intel_pstate", - &cpu_subsys.dev_root->kobj); + if (dev_root) { + intel_pstate_kobject = kobject_create_and_add("intel_pstate", &dev_root->kobj); + put_device(dev_root); + } if (WARN_ON(!intel_pstate_kobject)) return; From patchwork Mon Mar 13 18:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 663931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4337C61DA4 for ; Mon, 13 Mar 2023 18:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbjCMSbR (ORCPT ); Mon, 13 Mar 2023 14:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjCMSar (ORCPT ); Mon, 13 Mar 2023 14:30:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76DEE15179; Mon, 13 Mar 2023 11:30:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F21CF6147D; Mon, 13 Mar 2023 18:30:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14EE6C4339C; Mon, 13 Mar 2023 18:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678732207; bh=hXLKonMm2sNxAWG39959mWWF++bz6QKPSxDIBNJCa+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ab6OR33cN0NvU+6g9zXWYvinHqjfhlr0RvqZqfI7FeYbPnSOY27hkdBPgdUe7B7pe hd3L1GyUMfQf2/hLNWmByUFkExGLumyWwXoqB7zn5mDFlXVYvHv/lI2ebq2gej16Sc FyBvyj89uQPe6Xjp317pH+/OcPBdcZCQFKy4TKTU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Daniel Lezcano , linux-pm@vger.kernel.org Subject: [PATCH 06/36] cpuidle: move to use bus_get_dev_root() Date: Mon, 13 Mar 2023 19:28:48 +0100 Message-Id: <20230313182918.1312597-6-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313182918.1312597-1-gregkh@linuxfoundation.org> References: <20230313182918.1312597-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2943; i=gregkh@linuxfoundation.org; h=from:subject; bh=hXLKonMm2sNxAWG39959mWWF++bz6QKPSxDIBNJCa+k=; b=owGbwMvMwCRo6H6F97bub03G02pJDCn82WVLjjRum3e46v65hebO/hNqY6eZsRx/8JQt6IFe5 pKdzu+LO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi7p0MC5beqH1Sx1G8to+5 UepNkvmyoEc3vzEs6Epd4rBanU9C4mzqmtvV/lPeGarnAgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Direct access to the struct bus_type dev_root pointer is going away soon so replace that with a call to bus_get_dev_root() instead, which is what it is there for. This allows us to clean up the cpuidle_add_interface() call a bit as it was only called in one place, with the same argument so just put that into the function itself. Note that cpuidle_remove_interface() should also probably be removed in the future as there are no callers of it for some reason. Cc: "Rafael J. Wysocki" Cc: Daniel Lezcano Cc: linux-pm@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- Note, this is a patch that is a prepatory cleanup as part of a larger series of patches that is working on resolving some old driver core design mistakes. It will build and apply cleanly on top of 6.3-rc2 on its own, but I'd prefer if I could take it through my driver-core tree so that the driver core changes can be taken through there for 6.4-rc1. drivers/cpuidle/cpuidle.c | 2 +- drivers/cpuidle/cpuidle.h | 2 +- drivers/cpuidle/sysfs.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 0b00f21cefe3..8e929f6602ce 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -808,7 +808,7 @@ static int __init cpuidle_init(void) if (cpuidle_disabled()) return -ENODEV; - return cpuidle_add_interface(cpu_subsys.dev_root); + return cpuidle_add_interface(); } module_param(off, int, 0444); diff --git a/drivers/cpuidle/cpuidle.h b/drivers/cpuidle/cpuidle.h index 9f336af17fa6..52701d9588f1 100644 --- a/drivers/cpuidle/cpuidle.h +++ b/drivers/cpuidle/cpuidle.h @@ -30,7 +30,7 @@ extern int cpuidle_switch_governor(struct cpuidle_governor *gov); struct device; -extern int cpuidle_add_interface(struct device *dev); +extern int cpuidle_add_interface(void); extern void cpuidle_remove_interface(struct device *dev); extern int cpuidle_add_device_sysfs(struct cpuidle_device *device); extern void cpuidle_remove_device_sysfs(struct cpuidle_device *device); diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index 48948b171749..84e4946f1072 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -119,11 +119,17 @@ static struct attribute_group cpuidle_attr_group = { /** * cpuidle_add_interface - add CPU global sysfs attributes - * @dev: the target device */ -int cpuidle_add_interface(struct device *dev) +int cpuidle_add_interface(void) { - return sysfs_create_group(&dev->kobj, &cpuidle_attr_group); + struct device *dev_root = bus_get_dev_root(&cpu_subsys); + int retval = -EINVAL; + + if (dev_root) { + retval = sysfs_create_group(&dev_root->kobj, &cpuidle_attr_group); + put_device(dev_root); + } + return retval; } /** From patchwork Mon Mar 13 18:29:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 662920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8065C6FD19 for ; Mon, 13 Mar 2023 18:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbjCMSaz (ORCPT ); Mon, 13 Mar 2023 14:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231204AbjCMSao (ORCPT ); Mon, 13 Mar 2023 14:30:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 003C683156; Mon, 13 Mar 2023 11:30:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A62DB61468; Mon, 13 Mar 2023 18:29:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC821C433D2; Mon, 13 Mar 2023 18:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678732194; bh=t8dfYO0KLvBwnDTabEC6Q8qADtWU+S9Nx/DV5qsE0XE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGioplhrdEI2WqXg6RyaSAemRoVq2lTQmz+O74akI8S9P9KQkkWd6rr7lyXz9TOWu 93VPXul7gBSXKunekt9nTj5YFJm9jkFMULQsNkcyklppo3VhpDzmKOlM4ECFCWBc/0 EJdkJ0YcrmkEerZiECNBOO1bcKrZigw0DW5ReISg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Huang Rui , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH 20/36] cpufreq: amd-pstate: move to use bus_get_dev_root() Date: Mon, 13 Mar 2023 19:29:02 +0100 Message-Id: <20230313182918.1312597-20-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313182918.1312597-1-gregkh@linuxfoundation.org> References: <20230313182918.1312597-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3145; i=gregkh@linuxfoundation.org; h=from:subject; bh=t8dfYO0KLvBwnDTabEC6Q8qADtWU+S9Nx/DV5qsE0XE=; b=owGbwMvMwCRo6H6F97bub03G02pJDCn82ZXXBZRtTAvFnk1yaP1WWbM0JFjTKdUxcNbZcksJO Qub2vqOWBYGQSYGWTFFli/beI7urzik6GVoexpmDisTyBAGLk4BmMgWYYb5kfuLXv/YzP60ZLu+ eUv93CrDthfdDPMse++sO3xneoxO/u2AP5HT/y86oMkJAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Direct access to the struct bus_type dev_root pointer is going away soon so replace that with a call to bus_get_dev_root() instead, which is what it is there for. In doing so, remove the unneded kobject structure that was only being created to cause a subdirectory for the attributes. The name of the attribute group is the correct way to do this, saving code and complexity as well as allowing the attributes to properly show up to userspace tools (the raw kobject would not allow that.) Cc: Huang Rui Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: linux-pm@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Acked-by: Huang Rui --- Note, this is a patch that is a prepatory cleanup as part of a larger series of patches that is working on resolving some old driver core design mistakes. It will build and apply cleanly on top of 6.3-rc2 on its own, but I'd prefer if I could take it through my driver-core tree so that the driver core changes can be taken through there for 6.4-rc1. drivers/cpufreq/amd-pstate.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 73c7643b2697..b92454c50118 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -63,7 +63,6 @@ static struct cpufreq_driver *current_pstate_driver; static struct cpufreq_driver amd_pstate_driver; static struct cpufreq_driver amd_pstate_epp_driver; static int cppc_state = AMD_PSTATE_DISABLE; -struct kobject *amd_pstate_kobj; /* * AMD Energy Preference Performance (EPP) @@ -932,6 +931,7 @@ static struct attribute *pstate_global_attributes[] = { }; static const struct attribute_group amd_pstate_global_attr_group = { + .name = "amd_pstate", .attrs = pstate_global_attributes, }; @@ -1253,6 +1253,7 @@ static struct cpufreq_driver amd_pstate_epp_driver = { static int __init amd_pstate_init(void) { + struct device *dev_root; int ret; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) @@ -1299,24 +1300,19 @@ static int __init amd_pstate_init(void) if (ret) pr_err("failed to register with return %d\n", ret); - amd_pstate_kobj = kobject_create_and_add("amd_pstate", &cpu_subsys.dev_root->kobj); - if (!amd_pstate_kobj) { - ret = -EINVAL; - pr_err("global sysfs registration failed.\n"); - goto kobject_free; - } - - ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group); - if (ret) { - pr_err("sysfs attribute export failed with error %d.\n", ret); - goto global_attr_free; + dev_root = bus_get_dev_root(&cpu_subsys); + if (dev_root) { + ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group); + put_device(dev_root); + if (ret) { + pr_err("sysfs attribute export failed with error %d.\n", ret); + goto global_attr_free; + } } return ret; global_attr_free: - kobject_put(amd_pstate_kobj); -kobject_free: cpufreq_unregister_driver(current_pstate_driver); return ret; }