From patchwork Wed Dec 10 04:15:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42086 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B70D5260BE for ; Wed, 10 Dec 2014 04:16:29 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf1709256wid.3 for ; Tue, 09 Dec 2014 20:16:29 -0800 (PST) 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=BjeXbtBKkAyqSNj+Vpqc8fayWm7QCHEBQuQR/4qQGJ8=; b=J1YnyYKfTMzhTnUdUxlvh4O+XRqRA+D26T6ltRC3Ap6OADFhlnU61zXRp3aBOx2bnt TcmLViurIxS90IyuuWjuv2YNlk8YLL7Sn5MF2G88e93DPU2xN43kFnvlVN2MPxhpHC0h aaNM46nXR7dAslJU0HS2cv2I021zR8UyY8JYbpoFHmBVyTmvGzbOixj9qCpX3MFOxcoP UQK1TmtDxMgq7FOO327DxjixPMfysx4aJ+1fJSybIx9n1wl9rn4WakE9YDqomXU4ySf8 nOjlkaLYqV0LGKzTDrgvd32LyPdffwTxwlmXcBapnOg+fPZspnY/5PnsBXJn84youJGN g0Wg== X-Gm-Message-State: ALoCoQl1fqR540+AEjXkkKpBoymBULdSe1mGPTQwpV7N10kSXux4MY30RK3rCfLP8yXGhHirz9CI X-Received: by 10.180.108.101 with SMTP id hj5mr1136043wib.3.1418184989041; Tue, 09 Dec 2014 20:16:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.169 with SMTP id l9ls124064lal.101.gmail; Tue, 09 Dec 2014 20:16:28 -0800 (PST) X-Received: by 10.152.27.41 with SMTP id q9mr1796119lag.69.1418184988623; Tue, 09 Dec 2014 20:16:28 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id bb5si1324307lab.36.2014.12.09.20.16.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 20:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id pv20so1716877lab.27 for ; Tue, 09 Dec 2014 20:16:28 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr1853608lbb.80.1418184988497; Tue, 09 Dec 2014 20:16:28 -0800 (PST) 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.184.201 with SMTP id ew9csp834714lbc; Tue, 9 Dec 2014 20:16:27 -0800 (PST) X-Received: by 10.68.238.6 with SMTP id vg6mr3099447pbc.109.1418184986916; Tue, 09 Dec 2014 20:16:26 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ei12si4749825pdb.165.2014.12.09.20.16.26 for ; Tue, 09 Dec 2014 20:16:26 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755339AbaLJEQZ (ORCPT + 12 others); Tue, 9 Dec 2014 23:16:25 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:44613 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755310AbaLJEQZ (ORCPT ); Tue, 9 Dec 2014 23:16:25 -0500 Received: by mail-pa0-f47.google.com with SMTP id kq14so1958087pab.34 for ; Tue, 09 Dec 2014 20:16:24 -0800 (PST) X-Received: by 10.68.203.41 with SMTP id kn9mr3187275pbc.47.1418184984826; Tue, 09 Dec 2014 20:16:24 -0800 (PST) Received: from localhost ([122.166.92.172]) by mx.google.com with ESMTPSA id av8sm2762934pbd.80.2014.12.09.20.16.23 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 09 Dec 2014 20:16:24 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar Subject: [PATCH 5/5] opp: do error handling at the bottom of dev_pm_opp_add_dynamic() Date: Wed, 10 Dec 2014 09:45:35 +0530 Message-Id: <8af17569020172e735177b13fa088c34ab4e7619.1418184737.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.2.0 In-Reply-To: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> References: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> In-Reply-To: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> References: <0a31e317c90f601f77cc21b80455633928c70c96.1418184737.git.viresh.kumar@linaro.org> 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.54 as permitted sender) smtp.mail=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: , This makes it less error prone and moves common resource deallocation at a single place. Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 1150b9d2e012..d24dd614a0bd 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -413,6 +413,7 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, struct device_opp *dev_opp = NULL; struct dev_pm_opp *opp, *new_opp; struct list_head *head; + int ret; /* allocate new OPP node */ new_opp = kzalloc(sizeof(*new_opp), GFP_KERNEL); @@ -435,9 +436,8 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, if (IS_ERR(dev_opp)) { dev_opp = add_device_opp(dev); if (!dev_opp) { - mutex_unlock(&dev_opp_list_lock); - kfree(new_opp); - return -ENOMEM; + ret = -ENOMEM; + goto free_opp; } head = &dev_opp->opp_list; @@ -458,15 +458,13 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, /* Duplicate OPPs ? */ if (new_opp->rate == opp->rate) { - int ret = opp->available && new_opp->u_volt == opp->u_volt ? + ret = opp->available && new_opp->u_volt == opp->u_volt ? 0 : -EEXIST; dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", __func__, opp->rate, opp->u_volt, opp->available, new_opp->rate, new_opp->u_volt, new_opp->available); - mutex_unlock(&dev_opp_list_lock); - kfree(new_opp); - return ret; + goto free_opp; } list_add: @@ -480,6 +478,11 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, */ srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADD, new_opp); return 0; + +free_opp: + mutex_unlock(&dev_opp_list_lock); + kfree(new_opp); + return ret; } /**