Thread (4 messages) flat view 4 messages, 3 authors, 2012-08-06

Re: [PATCH v2 2/4] PM / OPP: Initialize OPP table from device tree

From: Shawn Guo <hidden>
Date: 2012-08-06 05:23:02
Also in: linux-arm-kernel

On Sun, Aug 05, 2012 at 11:43:04PM -0500, Rob Herring wrote:
On 08/05/2012 10:19 PM, Shawn Guo wrote:
quoted
On Sun, Aug 05, 2012 at 09:50:32PM -0500, Rob Herring wrote:
quoted
I think this whole function can be written more concisely. Just iterate
over the property and avoid the intermediate array allocation.
I'm not sure about that, since directly iterating over the property
means we have to take care of all these sanity checks done in API
of_property_read_u32_array().
This won't work?:
It should work.  But I rewrote the function like below after I find
the sanity check is simple enough to take care of it on our own.

The code does look more concise and still easy to read.

Regards,
Shawn

int of_init_opp_table(struct device *dev)
{
        const struct property *prop;
        const __be32 *val;
        int nr;

        prop = of_find_property(dev->of_node, "operating-points", NULL);
        if (!prop)
                return -ENODEV;
        if (!prop->value)
                return -ENODATA;

        /*
         * Each OPP is a set of tuples consisting of frequency and
         * voltage like <freq-kHz vol-uV>.
         */
        nr = prop->length / sizeof(u32);
        if (nr % 2) {
                dev_err(dev, "%s: Invalid OPP list\n", __func__);
                return -EINVAL;
        }

        val = prop->value;
        while (nr) {
                unsigned long freq = be32_to_cpup(val++) * 1000;
                unsigned long volt = be32_to_cpup(val++);

                if (opp_add(dev, freq, volt)) {
                        dev_warn(dev, "%s: Failed to add OPP %ld\n",
                                 __func__, freq);
                        continue;
                }
                nr -= 2;
        }

        return 0;
}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help