linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-pm@vger.kernel.org
Subject: Re: thermal: cpu_cooling: Use cpufreq_dev->freq_table for finding level/freq
Date: Thu, 11 Jun 2015 08:35:42 +0530	[thread overview]
Message-ID: <20150611030542.GM24662@linux> (raw)
In-Reply-To: <20150610150211.GA30208@mwanda>

Hi Dan,

On 10-06-15, 18:02, Dan Carpenter wrote:
> The documentation is very clear that this loop is correct.  It also
> turns out that it used consistently almost throughout.

Right.

> But when I see
> these unusual limits, I know it is often difficult to be 100%
> consistent so I kept looking.  It turns out there is off by one mistake
> when we allocate the buffer.
> 
>         cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) *
>                                           cpufreq_dev->max_level, GFP_KERNEL);
> 
> It should be allocating:
> 
> 	sizeof(*cpufreq_dev->freq_table) * (cpufreq_dev->max_level + 1)

Not really. This is how the code looks:

	/* Find max levels */
	cpufreq_for_each_valid_entry(pos, table)
		cpufreq_dev->max_level++;

	cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) *
					  cpufreq_dev->max_level, GFP_KERNEL);
	if (!cpufreq_dev->freq_table) {
		cool_dev = ERR_PTR(-ENOMEM);
		goto free_cdev;
	}

	/* max_level is an index, not a counter */
	cpufreq_dev->max_level--;


So when the block was allocated, max_level was total number of levels
and was reduced later only.

> We could just change the allocation, but really this kind of unusual
> limit is just going to cause more headaches in the future...

I understand your concern, but it all happened because of the way
thermal layer expects the state. It wants state to be the index or
level of the cooling state. And that corresponds to the index in
cpufreq table. And so was kept this way.

-- 
viresh

  reply	other threads:[~2015-06-11  3:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 15:02 thermal: cpu_cooling: Use cpufreq_dev->freq_table for finding level/freq Dan Carpenter
2015-06-11  3:05 ` Viresh Kumar [this message]
2015-06-11  7:14   ` Dan Carpenter

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=20150611030542.GM24662@linux \
    --to=viresh.kumar@linaro.org \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-pm@vger.kernel.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).