diff mbox series

[v2,03/19] cpuidle: move to use bus_get_dev_root()

Message ID 20230322090557.2943479-1-gregkh@linuxfoundation.org
State Accepted
Commit bf6479dbe743ca343fa122aaffbe9dcb1de80a51
Headers show
Series None | expand

Commit Message

Greg Kroah-Hartman March 22, 2023, 9:05 a.m. UTC
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" <rafael@kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2: - reworked cpuidle_add_interface() to exit early if dev_root is not
      valid based on review from Rafael.

 drivers/cpuidle/cpuidle.c |  2 +-
 drivers/cpuidle/cpuidle.h |  2 +-
 drivers/cpuidle/sysfs.c   | 13 ++++++++++---
 3 files changed, 12 insertions(+), 5 deletions(-)

Comments

Rafael J. Wysocki March 22, 2023, 2:27 p.m. UTC | #1
On Wed, Mar 22, 2023 at 10:06 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> 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.
>
> 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" <rafael@kernel.org>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: linux-pm@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

> ---
> v2: - reworked cpuidle_add_interface() to exit early if dev_root is not
>       valid based on review from Rafael.
>
>  drivers/cpuidle/cpuidle.c |  2 +-
>  drivers/cpuidle/cpuidle.h |  2 +-
>  drivers/cpuidle/sysfs.c   | 13 ++++++++++---
>  3 files changed, 12 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..d6f5da61cb7d 100644
> --- a/drivers/cpuidle/sysfs.c
> +++ b/drivers/cpuidle/sysfs.c
> @@ -119,11 +119,18 @@ 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;
> +
> +       if (!dev_root)
> +               return -EINVAL;
> +
> +       retval = sysfs_create_group(&dev_root->kobj, &cpuidle_attr_group);
> +       put_device(dev_root);
> +       return retval;
>  }
>
>  /**
> --
> 2.40.0
>
Greg Kroah-Hartman March 24, 2023, 8:56 a.m. UTC | #2
On Wed, Mar 22, 2023 at 03:27:45PM +0100, Rafael J. Wysocki wrote:
> On Wed, Mar 22, 2023 at 10:06 AM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> 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.
> >
> > 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" <rafael@kernel.org>
> > Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> > Cc: linux-pm@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Acked-by: Rafael J. Wysocki <rafael@kernel.org>

Great, thanks for the quick reviews!

greg k-h
diff mbox series

Patch

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..d6f5da61cb7d 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -119,11 +119,18 @@  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;
+
+	if (!dev_root)
+		return -EINVAL;
+
+	retval = sysfs_create_group(&dev_root->kobj, &cpuidle_attr_group);
+	put_device(dev_root);
+	return retval;
 }
 
 /**