linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: sudeep.holla@arm.com (Sudeep Holla)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] firmware: arm_scpi: pre-populate dvfs info in scpi_probe
Date: Mon, 2 Oct 2017 12:17:49 +0100	[thread overview]
Message-ID: <d6578a58-b7ab-9770-d78d-1971d1e702d4@arm.com> (raw)
In-Reply-To: <c8c0ff86-de14-f157-68e0-9df005defffa@gmail.com>



On 29/09/17 22:44, Heiner Kallweit wrote:
> Pre-populating the dvfs info data in scpi_probe allows to make all
> memory allocations device-managed. This helps to simplify scpi_remove
> and eventually to get rid of scpi_remove completely.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/firmware/arm_scpi.c | 57 ++++++++++++++++++++++++++++-----------------
>  1 file changed, 35 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
> index d80d11ae..fd79adb5 100644
> --- a/drivers/firmware/arm_scpi.c
> +++ b/drivers/firmware/arm_scpi.c
> @@ -644,35 +644,35 @@ static int opp_cmp_func(const void *opp1, const void *opp2)
>  }
>  
>  static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)
> +{
> +	if (domain >= MAX_DVFS_DOMAINS)
> +		return ERR_PTR(-EINVAL);
> +
> +	return scpi_info->dvfs[domain] ?: ERR_PTR(-EINVAL);
> +}
> +
> +static int scpi_dvfs_populate_info(struct device *dev, u8 domain)
>  {
>  	struct scpi_dvfs_info *info;
>  	struct scpi_opp *opp;
>  	struct dvfs_info buf;
>  	int ret, i;
>  
> -	if (domain >= MAX_DVFS_DOMAINS)
> -		return ERR_PTR(-EINVAL);
> -
> -	if (scpi_info->dvfs[domain])	/* data already populated */
> -		return scpi_info->dvfs[domain];
> -
>  	ret = scpi_send_message(CMD_GET_DVFS_INFO, &domain, sizeof(domain),
>  				&buf, sizeof(buf));
>  	if (ret)
> -		return ERR_PTR(ret);
> +		return ret;
>  
> -	info = kmalloc(sizeof(*info), GFP_KERNEL);
> +	info = devm_kmalloc(dev, sizeof(*info), GFP_KERNEL);
>  	if (!info)
> -		return ERR_PTR(-ENOMEM);
> +		return -ENOMEM;
>  
>  	info->count = DVFS_OPP_COUNT(buf.header);
>  	info->latency = DVFS_LATENCY(buf.header) * 1000; /* uS to nS */
>  
> -	info->opps = kcalloc(info->count, sizeof(*opp), GFP_KERNEL);
> -	if (!info->opps) {
> -		kfree(info);
> -		return ERR_PTR(-ENOMEM);
> -	}
> +	info->opps = devm_kcalloc(dev, info->count, sizeof(*opp), GFP_KERNEL);
> +	if (!info->opps)
> +		return -ENOMEM;
>  
>  	for (i = 0, opp = info->opps; i < info->count; i++, opp++) {
>  		opp->freq = le32_to_cpu(buf.opps[i].freq);
> @@ -682,7 +682,20 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)
>  	sort(info->opps, info->count, sizeof(*opp), opp_cmp_func, NULL);
>  
>  	scpi_info->dvfs[domain] = info;
> -	return info;
> +	return 0;
> +}
> +
> +static int scpi_dvfs_populate(struct device *dev)
> +{
> +	int ret, i;
> +
> +	for (i = 0; i < MAX_DVFS_DOMAINS; i++) {
> +		ret = scpi_dvfs_populate_info(dev, i);
> +		if (ret)
> +			break;

Does it make sense to continue to complete all MAX_DVFS_DOMAINS ?
Just wondering if there will be any firmware that returns errors for
few domains(e.g. not supported in initial versions of firmware).
I don't want to stop probing due to that. Let me know what you think.

-- 
Regards,
Sudeep

  reply	other threads:[~2017-10-02 11:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-29 21:25 [PATCH 0/5] firmware: arm_scpi: series with smaller improvements Heiner Kallweit
2017-09-29 21:43 ` [PATCH 1/5] firmware: arm_scpi: remove usage of drvdata and don't reset scpi_info to null Heiner Kallweit
2017-10-02 11:08   ` Sudeep Holla
2017-09-29 21:44 ` [PATCH 2/5] firmware: arm_scpi: remove two unneeded devm_kfree's in scpi_remove Heiner Kallweit
2017-09-29 21:44 ` [PATCH 3/5] firmware: arm_scpi: pre-populate dvfs info in scpi_probe Heiner Kallweit
2017-10-02 11:17   ` Sudeep Holla [this message]
2017-10-02 22:07     ` Heiner Kallweit
2017-10-03 10:57       ` Sudeep Holla
2017-10-03 16:00         ` Heiner Kallweit
2017-10-03 16:18           ` Sudeep Holla
2017-10-03 18:19             ` Heiner Kallweit
2017-10-04 10:10               ` Sudeep Holla
2017-10-04 18:50                 ` Heiner Kallweit
2017-09-29 21:44 ` [PATCH 4/5] firmware: arm_scpi: make freeing mbox channels device-managed Heiner Kallweit
2017-10-02 11:20   ` Sudeep Holla
2017-09-29 21:44 ` [PATCH 5/5] firmware: arm_scpi: remove scpi_remove Heiner Kallweit
2017-10-02 11:25 ` [PATCH 0/5] firmware: arm_scpi: series with smaller improvements Sudeep Holla
2017-10-02 22:10   ` Heiner Kallweit
2017-10-03 10:16     ` Sudeep Holla

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=d6578a58-b7ab-9770-d78d-1971d1e702d4@arm.com \
    --to=sudeep.holla@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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).