From patchwork Tue Aug 11 10:34:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52296 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 1404C22FEC for ; Tue, 11 Aug 2015 10:34:56 +0000 (UTC) Received: by labth1 with SMTP id th1sf71109381lab.2 for ; Tue, 11 Aug 2015 03:34:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=ilZuX6DOevU18E00pN5yxiAgPtVCludtwfIkqTXsrsM=; b=gFL5uO38BgW9TSOSziPSILmYeMtGzfavyhVHEeZCQmTxYO7a5vC6ivj6BW/Z2Utlqb jh2LmLJ9VLxdQQ///0oqNg5ygVZUR4ERk/j4jfatt0ugkgfACFjZnPdSL50tDhBypQgH +hoHuuq/5Ornimu1bASpuxii0I71YoII6dhcOMvpunwG7eVrm2+QiCognlJBeFf0uM8A iV+m0jz9K3rp0XuWm45i9Iu9QU0GanlUMQVNbUNn2JqABANLp2V7yIh/6OE4Y92V9llf SBTmq+5DknWzWhYGb5JNt728U5JxxkLFhiHf8ERiYWD2O3tZxu8rK0fklSpqzFsZVvXg VsBQ== X-Gm-Message-State: ALoCoQktWAcblDUuWv0jVzIN4qn7Okg/TUH03ONfpFo6tLnJ0kn4+Z785B0uwoOpaJSJgvC5TEsw X-Received: by 10.112.26.5 with SMTP id h5mr7757777lbg.4.1439289295025; Tue, 11 Aug 2015 03:34:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.100 with SMTP id a4ls844736lah.52.gmail; Tue, 11 Aug 2015 03:34:54 -0700 (PDT) X-Received: by 10.112.36.165 with SMTP id r5mr25555002lbj.3.1439289294873; Tue, 11 Aug 2015 03:34:54 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id an8si1024606lbd.172.2015.08.11.03.34.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 03:34:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lalv9 with SMTP id v9so25722016lal.0 for ; Tue, 11 Aug 2015 03:34:54 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr23370436lbb.76.1439289294598; Tue, 11 Aug 2015 03:34:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2434056lba; Tue, 11 Aug 2015 03:34:53 -0700 (PDT) X-Received: by 10.68.184.197 with SMTP id ew5mr55110464pbc.145.1439289292636; Tue, 11 Aug 2015 03:34:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dq1si2754135pdb.69.2015.08.11.03.34.51; Tue, 11 Aug 2015 03:34:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934336AbbHKKev (ORCPT + 12 others); Tue, 11 Aug 2015 06:34:51 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35665 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934095AbbHKKeu (ORCPT ); Tue, 11 Aug 2015 06:34:50 -0400 Received: by pacgr6 with SMTP id gr6so48250228pac.2 for ; Tue, 11 Aug 2015 03:34:49 -0700 (PDT) X-Received: by 10.68.129.226 with SMTP id nz2mr54816112pbb.47.1439289289661; Tue, 11 Aug 2015 03:34:49 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id qn7sm2120910pab.14.2015.08.11.03.34.48 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 11 Aug 2015 03:34:49 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , nm@ti.com, sboyd@codeaurora.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, khilman@linaro.org, Viresh Kumar , Dan Carpenter , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH V2 1/6] PM / OPP: Free resources and properly return error on failure Date: Tue, 11 Aug 2015 16:04:34 +0530 Message-Id: <334a9052264630b9157fa9bfc3d4efe945054c34.1439288881.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , _of_init_opp_table_v2() isn't freeing up resources on some errors and the error values returned are also not correct always. This fixes following problems: - Return -ENOENT, if no entries are found in the table. - Use IS_ERR() to properly check return value of _find_device_opp(). - Return error value with PTR_ERR() in above case. - Free table if _find_device_opp() fails. Fixes: 274659029c9d ("PM / OPP: Add support to parse operating-points-v2" bindings") Reported-by: Dan Carpenter Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 204c6c945168..bcbd92c3b717 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -1323,28 +1323,29 @@ static int _of_init_opp_table_v2(struct device *dev, if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); - break; + goto free_table; } } /* There should be one of more OPP defined */ - if (WARN_ON(!count)) + if (WARN_ON(!count)) { + ret = -ENOENT; goto put_opp_np; + } - if (!ret) { - if (!dev_opp) { - dev_opp = _find_device_opp(dev); - if (WARN_ON(!dev_opp)) - goto put_opp_np; - } - - dev_opp->np = opp_np; - dev_opp->shared_opp = of_property_read_bool(opp_np, - "opp-shared"); - } else { - of_free_opp_table(dev); + dev_opp = _find_device_opp(dev); + if (WARN_ON(IS_ERR(dev_opp))) { + ret = PTR_ERR(dev_opp); + goto free_table; } + dev_opp->np = opp_np; + dev_opp->shared_opp = of_property_read_bool(opp_np, "opp-shared"); + + goto put_opp_np; + +free_table: + of_free_opp_table(dev); put_opp_np: of_node_put(opp_np);