) On Mon, Jun 24, 2019 at 3:17 PM Daniel Lezcano <daniel.lezcano@xxxxxxxxxx> wrote: > > Currently the function cpufreq_cooling_register() returns a cooling > device pointer which is used back as a pointer to call the function > cpufreq_cooling_unregister(). Even if it is correct, it would make > sense to not leak the structure inside a cpufreq driver and keep the > code thermal code self-encapsulate. Moreover, that forces to add an > extra variable in each driver using this function. [cut] > @@ -667,9 +667,9 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) > np = of_get_cpu_node(data->policy->cpu, NULL); > > if (!np || !of_find_property(np, "#cooling-cells", NULL)) { > - data->cdev = cpufreq_cooling_register(data->policy); > - if (IS_ERR(data->cdev)) { > - ret = PTR_ERR(data->cdev); > + cdev = cpufreq_cooling_register(data->policy); It looks like after the changes in this patch the only reason for returning (struct thermal_cooling_device *) from cpufreq_cooling_register() is error checking, but it would be much more straightforward to return int for this purpose. Moreover, that would prevent the callers of it from doing incorrect things with the returned pointers (like using it to unregister the cooling device). > + if (IS_ERR(cdev)) { > + ret = PTR_ERR(cdev); > cpufreq_cpu_put(data->policy); > return ret; > }