linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thara Gopinath <thara.gopinath@linaro.org>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Zhang Rui <rui.zhang@intel.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Andy Gross <agross@kernel.org>, Rob Herring <robh@kernel.org>,
	Amit Kucheria <amit.kucheria@verdurent.com>,
	Mark Rutland <mark.rutland@arm.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux PM <linux-pm@vger.kernel.org>,
	DTML <devicetree@vger.kernel.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [Patch v5 3/6] thermal: Add generic power domain warming device driver.
Date: Wed, 25 Mar 2020 10:35:31 -0400	[thread overview]
Message-ID: <31aba776-28ee-3aac-08eb-6f39f8279bfe@linaro.org> (raw)
In-Reply-To: <CAPDyKFqn0E=-sNZy=09tLZn=6VxEfiXL-vUNwb9HK8+WLDBiPw@mail.gmail.com>

Hi Ulf,
Thanks for the review!

On 3/23/20 11:57 AM, Ulf Hansson wrote:

--snip
>> +
>> +static void pd_warming_release(struct device *dev)
>> +{
>> +       kfree(dev);
> 
> This is wrong, you should free a "struct pd_warming_device *". Use the
> "container of" macro to get it from 'dev'.

Will fix this.
> 
>> +}
>> +
>> +struct thermal_cooling_device *
>> +of_pd_warming_register(struct device *parent, int pd_id)
>> +{
>> +       struct pd_warming_device *pd_wdev;
>> +       struct of_phandle_args pd_args;
>> +       char cdev_name[THERMAL_NAME_LENGTH];
>> +       int ret;
>> +
>> +       pd_wdev = kzalloc(sizeof(*pd_wdev), GFP_KERNEL);
>> +       if (!pd_wdev)
>> +               return ERR_PTR(-ENOMEM);
>> +
>> +       dev_set_name(&pd_wdev->dev, "%s_%d_warming_dev",
>> +                    dev_name(parent), pd_id);
>> +       pd_wdev->dev.parent = parent;
>> +       pd_wdev->dev.release = pd_warming_release;
>> +
>> +       ret = device_register(&pd_wdev->dev);
>> +       if (ret) {
>> +               put_device(&pd_wdev->dev);
>> +               goto free_pd_wdev;
>> +       }
>> +
>> +       ret = ida_simple_get(&pd_ida, 0, 0, GFP_KERNEL);
>> +       if (ret < 0)
>> +               goto unregister_device;
> 
> If you use and ida, you might as well use it as a part of the
> dev_set_name() above.
> 
> That should give you a unique name, similar to how you use it for the
> cdev_name below.

dev_set_name above already has a unique name with the power controller 
name and the power domain id. cdev on the other hand creates a virtual 
thermal device and needs a unique name.

> 
>> +
>> +       pd_wdev->id = ret;
>> +
>> +       pd_args.np = parent->of_node;
>> +       pd_args.args[0] = pd_id;
>> +       pd_args.args_count = 1;
>> +
>> +       ret = of_genpd_add_device(&pd_args, &pd_wdev->dev);
>> +
>> +       if (ret)
>> +               goto remove_ida;
>> +
>> +       ret = dev_pm_genpd_performance_state_count(&pd_wdev->dev);
>> +       if (ret < 0)
>> +               goto out_genpd;
>> +
>> +       pd_wdev->max_state = ret - 1;
>> +       pm_runtime_enable(&pd_wdev->dev);
>> +       pd_wdev->runtime_resumed = false;
>> +
>> +       snprintf(cdev_name, sizeof(cdev_name), "thermal-pd-%d", pd_wdev->id);
>> +       pd_wdev->cdev = thermal_of_cooling_device_register
>> +                                       (NULL, cdev_name, pd_wdev,
>> +                                        &pd_warming_device_ops);
>> +       if (IS_ERR(pd_wdev->cdev)) {
>> +               pr_err("unable to register %s cooling device\n", cdev_name);
>> +               ret = PTR_ERR(pd_wdev->cdev);
>> +               goto out_runtime_disable;
>> +       }
>> +
>> +       return pd_wdev->cdev;
>> +
>> +out_runtime_disable:
>> +       pm_runtime_disable(&pd_wdev->dev);
>> +out_genpd:
>> +       pm_genpd_remove_device(&pd_wdev->dev);
>> +remove_ida:
>> +       ida_simple_remove(&pd_ida, pd_wdev->id);
>> +unregister_device:
>> +       device_unregister(&pd_wdev->dev);
>> +       pd_warming_release(&pd_wdev->dev);
> 
> This is wrong, drop this.

Oops . sorry . Will do. Will fix rest of the comments below as well.

> 
>> +free_pd_wdev:
>> +       kfree(pd_wdev);
> 
> Since you should free this from the ->release() callback, there is no
> need to do this here.
> 
>> +       return ERR_PTR(ret);
>> +}
>> +EXPORT_SYMBOL_GPL(of_pd_warming_register);
>> +
>> +void pd_warming_unregister(struct thermal_cooling_device *cdev)
>> +{
>> +       struct pd_warming_device *pd_wdev = cdev->devdata;
>> +       struct device *dev = &pd_wdev->dev;
>> +
>> +       if (pd_wdev->runtime_resumed) {
>> +               dev_pm_genpd_set_performance_state(dev, 0);
>> +               pm_runtime_put(dev);
>> +               pd_wdev->runtime_resumed = false;
>> +       }
>> +       pm_runtime_disable(dev);
>> +       pm_genpd_remove_device(dev);
>> +       ida_simple_remove(&pd_ida, pd_wdev->id);
>> +       thermal_cooling_device_unregister(cdev);
>> +       kfree(pd_wdev);
> 
> Don't use kfree here, but instead device_unregister(dev);
> 
>> +}
>> +EXPORT_SYMBOL_GPL(pd_warming_unregister);
>> diff --git a/include/linux/pd_warming.h b/include/linux/pd_warming.h
>> new file mode 100644
>> index 000000000000..550a5683b56d
>> --- /dev/null
>> +++ b/include/linux/pd_warming.h
>> @@ -0,0 +1,29 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (c) 2019, Linaro Ltd.
>> + */
>> +#ifndef __PWR_DOMAIN_WARMING_H__
>> +#define __PWR_DOMAIN_WARMING_H__
>> +
>> +#include <linux/pm_domain.h>
>> +#include <linux/thermal.h>
>> +
>> +#ifdef CONFIG_PWR_DOMAIN_WARMING_THERMAL
>> +struct thermal_cooling_device *
>> +of_pd_warming_register(struct device *parent, int pd_id);
>> +
>> +void pd_warming_unregister(struct thermal_cooling_device *cdev);
>> +
>> +#else
>> +static inline struct thermal_cooling_device *
>> +of_pd_warming_register(struct device *parent, int pd_id)
>> +{
>> +       return ERR_PTR(-ENOSYS);
>> +}
>> +
>> +static inline void
>> +pd_warming_unregister(struct thermal_cooling_device *cdev)
>> +{
>> +}
>> +#endif /* CONFIG_PWR_DOMAIN_WARMING_THERMAL */
>> +#endif /* __PWR_DOMAIN_WARMING_H__ */
>> --
>> 2.20.1
>>
> 
> Besides the few things above, this looks good to me.
> 
> Kind regards
> Uffe
> 

-- 
Warm Regards
Thara

  reply	other threads:[~2020-03-25 14:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20  1:41 [Patch v5 0/6] Introduce Power domain based warming device driver Thara Gopinath
2020-03-20  1:41 ` [Patch v5 1/6] PM/Domains: Add support for retrieving genpd performance states information Thara Gopinath
2020-03-27 22:33   ` Bjorn Andersson
2020-03-20  1:41 ` [Patch v5 2/6] soc: qcom: rpmhpd: Introduce function to retrieve power domain performance state count Thara Gopinath
2020-03-27 22:15   ` Bjorn Andersson
2020-03-30 14:41     ` Thara Gopinath
2020-03-20  1:41 ` [Patch v5 3/6] thermal: Add generic power domain warming device driver Thara Gopinath
2020-03-23 15:57   ` Ulf Hansson
2020-03-25 14:35     ` Thara Gopinath [this message]
2020-03-20  1:41 ` [Patch v5 4/6] soc: qcom: Extend RPMh power controller driver to register warming devices Thara Gopinath
2020-03-27 22:53   ` Bjorn Andersson
2020-03-30 14:53     ` Thara Gopinath
2020-03-30 22:29       ` Bjorn Andersson
2020-03-20  1:41 ` [Patch v5 5/6] dt-bindings: power: Extend RPMh power controller binding to describe thermal warming device Thara Gopinath
2020-03-20 22:56   ` Rob Herring
2020-03-20  1:41 ` [Patch v5 6/6] arm64: dts: qcom: Indicate rpmhpd hosts a power domain that can be used as a " Thara Gopinath
2020-03-27 22:54   ` Bjorn Andersson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31aba776-28ee-3aac-08eb-6f39f8279bfe@linaro.org \
    --to=thara.gopinath@linaro.org \
    --cc=agross@kernel.org \
    --cc=amit.kucheria@verdurent.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).