From patchwork Wed Aug 12 11:00:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52343 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id EAB3A2031F for ; Wed, 12 Aug 2015 11:00:56 +0000 (UTC) Received: by lagz9 with SMTP id z9sf4650825lag.3 for ; Wed, 12 Aug 2015 04:00: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=/xGe1oUx4xLh7lF11XF2DqQlHj/6SHR6ZyRQfTuajNw=; b=ElxGWQ5iAWsQXdXxKD5RHi0Hh9RBMWe2W40KUzbte9AtKzA4WKlo+TurpgpNPHpcZA nBMmo06VShEY+MCPNsXaGKA1A9Okpc6Qa2rYw7Ts78C1d9EspfCfjjHvnSW2bzGH1MNJ Ns9TbHiP/WUEn7JWQ7y7ERrly5p3EjUQismdsso0F3E934s0IxCBfk7sFcYT6S9LURKj GCosuDk+mM0itOSsJkT6YJVUv/ltqKYyNUV343FTzeNllYfsM2kXHfUd1A2VHp9CwDRv ly5I+U4v9YhWVgaR64zk6MYZ71Xho1S6OQb6YM0vh3Ntqu0ud5sC4hMiK5QklboNpJuQ g9Qw== X-Gm-Message-State: ALoCoQkfvmph4etGIrFThCFEb5KJM0eCvgBMieeqFfq/i07+kL7s/hiR4PY0JBgilegKzyRxX0wZ X-Received: by 10.112.227.105 with SMTP id rz9mr2692522lbc.8.1439377255923; Wed, 12 Aug 2015 04:00:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.242.131 with SMTP id wq3ls24417lac.106.gmail; Wed, 12 Aug 2015 04:00:55 -0700 (PDT) X-Received: by 10.152.42.170 with SMTP id p10mr31117247lal.39.1439377255606; Wed, 12 Aug 2015 04:00:55 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id lf12si3875644lac.122.2015.08.12.04.00.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2015 04:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lalv9 with SMTP id v9so6991902lal.0 for ; Wed, 12 Aug 2015 04:00:55 -0700 (PDT) X-Received: by 10.112.160.42 with SMTP id xh10mr31473828lbb.88.1439377255471; Wed, 12 Aug 2015 04:00:55 -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 l6csp249933lba; Wed, 12 Aug 2015 04:00:54 -0700 (PDT) X-Received: by 10.70.54.196 with SMTP id l4mr66418953pdp.42.1439377253374; Wed, 12 Aug 2015 04:00:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si8941910pdk.80.2015.08.12.04.00.52; Wed, 12 Aug 2015 04:00:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 S934012AbbHLLAv (ORCPT + 28 others); Wed, 12 Aug 2015 07:00:51 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:36413 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933290AbbHLLAt (ORCPT ); Wed, 12 Aug 2015 07:00:49 -0400 Received: by pacrr5 with SMTP id rr5so12427856pac.3 for ; Wed, 12 Aug 2015 04:00:48 -0700 (PDT) X-Received: by 10.68.241.230 with SMTP id wl6mr66131404pbc.32.1439377248754; Wed, 12 Aug 2015 04:00:48 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id m2sm6031316pdp.4.2015.08.12.04.00.42 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Aug 2015 04:00:48 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, dan.carpenter@oracle.com, nm@ti.com, sboyd@codeaurora.org, Viresh Kumar , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH V3 1/2] PM / OPP: Free resources and properly return error on failure Date: Wed, 12 Aug 2015 16:30:18 +0530 Message-Id: X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.51 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. Reported-by: Dan Carpenter Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 204c6c945168..4d6c4576f7ae 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -1323,28 +1323,30 @@ 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"); + + of_node_put(opp_np); + return 0; + +free_table: + of_free_opp_table(dev); put_opp_np: of_node_put(opp_np);