Re: [PATCH V2 1/6] PM / OPP: Free resources and properly return error on failure

From: Viresh Kumar
Date: Wed Aug 12 2015 - 04:23:22 EST

On 12-08-15, 11:11, Dan Carpenter wrote:
> If it doesn't WARN() then it's not buggy, but it's still ugly. We
> should not call of_free_opp_table() because we *tried* to add an OPP, we
> should only call it if we *succeeded*.

This is done in order to write lesser code. Otherwise we need
something like this:

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index bcbd92c3b717..650e92e2f2f0 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -1317,14 +1317,15 @@ static int _of_init_opp_table_v2(struct device *dev,

/* We have opp-list node now, iterate over it and add OPPs */
for_each_available_child_of_node(opp_np, np) {
- count++;
ret = _opp_add_static_v2(dev, np);
if (ret) {
dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
+ if (!count)
+ goto put_opp_np;
goto free_table;
+ count++;

/* There should be one of more OPP defined */

To some people, this will look even more *ugly*. And so I just called
free_table() on error.

> The way the code is written and from your emails I was afraid that if
> you tried to call _opp_add_static_v2() and it fails then it leaves
> artifacts lying around that need to be cleaned up by the caller.

No. The problem is that we are trying to add OPPs in a while loop and
on failure we need to free all we added earlier.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at