Re: [PATCH V2 3/4] thermal/drivers/cpu_cooling: Introduce the cpu idle cooling driver

From: Viresh Kumar
Date: Tue Dec 03 2019 - 03:14:37 EST


On 02-12-19, 21:28, Daniel Lezcano wrote:
> +/**
> + * cpuidle_of_cooling_register - Idle cooling device initialization function
> + * @drv: a cpuidle driver structure pointer

@np missing here.

> + *
> + * This function is in charge of creating a cooling device per cpuidle
> + * driver and register it to thermal framework.
> + *
> + * Returns a valid pointer to a thermal cooling device, a PTR_ERR

s/, a/, or a/ ?

> + * corresponding to the error detected in the underlying subsystems.
> + */
> +struct thermal_cooling_device *
> +__init cpuidle_of_cooling_register(struct device_node *np,
> + struct cpuidle_driver *drv)
> +{
> + struct idle_inject_device *ii_dev;
> + struct cpuidle_cooling_device *idle_cdev;
> + struct thermal_cooling_device *cdev;
> + char dev_name[THERMAL_NAME_LENGTH];
> + int id, ret;
> +
> + idle_cdev = kzalloc(sizeof(*idle_cdev), GFP_KERNEL);
> + if (!idle_cdev) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + id = ida_simple_get(&cpuidle_ida, 0, 0, GFP_KERNEL);
> + if (id < 0) {
> + ret = id;
> + goto out_kfree;
> + }
> +
> + ii_dev = idle_inject_register(drv->cpumask);
> + if (IS_ERR(ii_dev)) {
> + ret = PTR_ERR(ii_dev);
> + goto out_id;
> + }
> +
> + idle_inject_set_duration(ii_dev, 0, TICK_USEC);
> +
> + idle_cdev->ii_dev = ii_dev;
> +
> + snprintf(dev_name, sizeof(dev_name), "thermal-idle-%d", id);
> +
> + cdev = thermal_of_cooling_device_register(np, dev_name, idle_cdev,
> + &cpuidle_cooling_ops);
> + if (IS_ERR(cdev)) {
> + ret = PTR_ERR(cdev);
> + goto out_unregister;
> + }
> +
> + return cdev;
> +
> +out_unregister:
> + idle_inject_unregister(ii_dev);
> +out_id:
> + ida_simple_remove(&cpuidle_ida, id);
> +out_kfree:
> + kfree(idle_cdev);
> +out:
> + return ERR_PTR(ret);
> +}
> +
> +/**
> + * cpuidle_cooling_register - Idle cooling device initialization function
> + * @drv: a cpuidle driver structure pointer
> + *
> + * This function is in charge of creating a cooling device per cpuidle
> + * driver and register it to thermal framework.
> + *
> + * Returns a valid pointer to a thermal cooling device, a PTR_ERR
> + * corresponding to the error detected in the underlying subsystems.
> + */
> +struct thermal_cooling_device *
> +__init cpuidle_cooling_register(struct cpuidle_driver *drv)
> +{
> + return cpuidle_of_cooling_register(NULL, drv);
> +}
> diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h
> index 3cdd85f987d7..da0970183d1f 100644
> --- a/include/linux/cpu_cooling.h
> +++ b/include/linux/cpu_cooling.h
> @@ -60,4 +60,26 @@ of_cpufreq_cooling_register(struct cpufreq_policy *policy)
> }
> #endif /* CONFIG_CPU_FREQ_THERMAL */
>
> +struct cpuidle_driver;
> +
> +#ifdef CONFIG_CPU_IDLE_THERMAL
> +extern struct thermal_cooling_device *
> +__init cpuidle_cooling_register(struct cpuidle_driver *drv);
> +extern struct thermal_cooling_device *
> +__init cpuidle_of_cooling_register(struct device_node *np,
> + struct cpuidle_driver *drv);

Maybe just drop the "extern" thing here as it is redundant really.

> +#else /* CONFIG_CPU_IDLE_THERMAL */
> +static inline struct thermal_cooling_device *
> +__init cpuidle_cooling_register(struct cpuidle_driver *drv)
> +{
> + return ERR_PTR(-EINVAL);
> +}
> +static inline struct thermal_cooling_device *
> +__init cpuidle_of_cooling_register(struct device_node *np,
> + struct cpuidle_driver *drv)
> +{
> + return ERR_PTR(-EINVAL);
> +}
> +#endif /* CONFIG_CPU_IDLE_THERMAL */
> +
> #endif /* __CPU_COOLING_H__ */

Acked-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>

--
viresh