From patchwork Wed Aug 12 08:23:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 6997891 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3950D9F39D for ; Wed, 12 Aug 2015 08:24:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 452832070E for ; Wed, 12 Aug 2015 08:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70C1C2070A for ; Wed, 12 Aug 2015 08:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934063AbbHLIXM (ORCPT ); Wed, 12 Aug 2015 04:23:12 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:36006 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934034AbbHLIXH (ORCPT ); Wed, 12 Aug 2015 04:23:07 -0400 Received: by pacrr5 with SMTP id rr5so9741767pac.3 for ; Wed, 12 Aug 2015 01:23:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=T5QUKc8LIVOAbhJcNRIjqmeG2KVf8SqNSAx/93rhAQc=; b=eiGlFEKBq7sq5eiUcrqbM/pjXDA0XwMLIxjfJ9qmI+ywJx4TTAOVqBtSytN/nKaS3N 0oabd7Ux+KAd/KWG2mUFwB1Hk27kTtAsAC9Rb+/L9iHRX4winL0WSwkPMsoWO7ALRqh8 egCpYGyiRipQSwyUE6rWSOE6I7sP81QS1Y91N/xKZHJxo9PL96yYFywE0OK5a3J4juEe pklh4lWAbsJv0+6ZVjELfUwEBinJ1dyprlv7MufijIrvkyx/BZUInJ7p+TlgaGTE6QL1 Y3UUltrDmPZMSWnebmfFJTBca5fImSe3T9iyA8WAmTPYvSqNazd4CUI4AO7gsmo21RSn nHrA== X-Gm-Message-State: ALoCoQl5I2zCLeEHK24L+pgMY+3AwEEn4TFITLEw297fid5Jz21zuxVtuZzE/WtlFSIFLxauJMpC X-Received: by 10.66.63.9 with SMTP id c9mr64945820pas.40.1439367786963; Wed, 12 Aug 2015 01:23:06 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id f10sm4680968pdk.20.2015.08.12.01.23.05 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Aug 2015 01:23:06 -0700 (PDT) Date: Wed, 12 Aug 2015 13:53:02 +0530 From: Viresh Kumar To: Dan Carpenter Cc: Rafael Wysocki , nm@ti.com, sboyd@codeaurora.org, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, khilman@linaro.org, Greg Kroah-Hartman , Len Brown , open list , Pavel Machek Subject: Re: [PATCH V2 1/6] PM / OPP: Free resources and properly return error on failure Message-ID: <20150812082302.GD16445@linux> References: <334a9052264630b9157fa9bfc3d4efe945054c34.1439288881.git.viresh.kumar@linaro.org> <20150811144345.GN5180@mwanda> <20150811145938.GA32049@linux> <20150811171132.GA25166@mwanda> <20150812064309.GL32049@linux> <20150812081113.GC32040@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150812081113.GC32040@mwanda> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: 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. 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__, ret); + if (!count) + goto put_opp_np; goto free_table; } + count++; } /* There should be one of more OPP defined */