PM / domains: Fix up domain-idle-states OF parsing
authorUlf Hansson <ulf.hansson@linaro.org>
Tue, 23 Jan 2018 20:43:08 +0000 (21:43 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 7 Feb 2018 11:02:01 +0000 (12:02 +0100)
commita3381e3a65cbaf612c8f584906c4dba27e84267c
tree2fb763468bf084673a35b23fc00dc5e0d9f1b206
parent7f3fdd40a7dfaa7405185250974b0fabd08c1f8b
PM / domains: Fix up domain-idle-states OF parsing

Commit b539cc82d493 (PM / Domains: Ignore domain-idle-states that are
not compatible), made it possible to ignore non-compatible
domain-idle-states OF nodes. However, in case that happens while doing
the OF parsing, the number of elements in the allocated array would
exceed the numbers actually needed, thus wasting memory.

Fix this by pre-iterating the genpd OF node and counting the number of
compatible domain-idle-states nodes, before doing the allocation. While
doing this, it makes sense to rework the code a bit to avoid open coding,
of parts responsible for the OF node iteration.

Let's also take the opportunity to clarify the function header for
of_genpd_parse_idle_states(), about what is being returned in case of
errors.

Fixes: b539cc82d493 (PM / Domains: Ignore domain-idle-states that are not compatible)
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Lina Iyer <ilina@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/domain.c