2023-03-13 18:31:00

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 20/36] cpufreq: amd-pstate: move to use bus_get_dev_root()

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 <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
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;
}
--
2.39.2



2023-03-14 06:04:39

by Huang Rui

[permalink] [raw]
Subject: Re: [PATCH 20/36] cpufreq: amd-pstate: move to use bus_get_dev_root()

On Tue, Mar 14, 2023 at 02:29:02AM +0800, Greg Kroah-Hartman wrote:
> 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 <[email protected]>
> Cc: "Rafael J. Wysocki" <[email protected]>
> Cc: Viresh Kumar <[email protected]>
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> 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.

Thanks Greg.

Acked-by: Huang Rui <[email protected]>

>
> 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;
> }
> --
> 2.39.2
>