From patchwork Thu Dec 4 04:11:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 41900 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 51B4125E88 for ; Thu, 4 Dec 2014 04:13:52 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf10498718eek.5 for ; Wed, 03 Dec 2014 20:13:51 -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=BKQQEGTZEL7XH59hiQWECrZ4Juf3TjEHimZASFOYVvU=; b=aK+s1qPiozgRqEtZrzrPU7e61ldbImtkAs4o96a3+Q4fj1I4gWubDtNOi9mFtiPi7H ZAGC0EkNQU1aF2hIROG8sPzfr6Lr1B0rbABun1DuTbEQWMiXrJuGz9imKltp4Bo6BvB/ tuI0OxZXtc/Pq4njX9CXDBpLj/woXpFwhwLbjwNa2reEd/8U6SXJMB5uFabGgkh0ZpPH MQXLVWryPxdf1z1bb0Xi/NW7++Xr5B3yp3WHZ+76HMba9QdPCd35KU3LFT/DSujWuiZ0 1PUCOfN4eQB6PgTCiulDXwHHOTS+19v+AgRtn57YGgTNfk52k3fZa8fVSdoPF+dTUCtd qC5A== X-Gm-Message-State: ALoCoQnKDK1YojOWKzM4SL4J2fVU4Q/UgUw38GPDRFUHKBHuVRuM9HAQNFa5M/FYUIOxmxEV/ifr X-Received: by 10.112.72.106 with SMTP id c10mr8763lbv.15.1417666431561; Wed, 03 Dec 2014 20:13:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.39 with SMTP id b7ls200519lae.38.gmail; Wed, 03 Dec 2014 20:13:50 -0800 (PST) X-Received: by 10.112.138.9 with SMTP id qm9mr7435242lbb.62.1417666430708; Wed, 03 Dec 2014 20:13:50 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id wg10si24602028lbb.118.2014.12.03.20.13.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 20:13:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so14753735lbj.13 for ; Wed, 03 Dec 2014 20:13:50 -0800 (PST) X-Received: by 10.112.38.4 with SMTP id c4mr7348227lbk.46.1417666430621; Wed, 03 Dec 2014 20:13:50 -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 ew9csp781075lbc; Wed, 3 Dec 2014 20:13:49 -0800 (PST) X-Received: by 10.68.226.6 with SMTP id ro6mr21927875pbc.31.1417666428833; Wed, 03 Dec 2014 20:13:48 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df1si18139882pdb.237.2014.12.03.20.13.48 for ; Wed, 03 Dec 2014 20:13:48 -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 S1753011AbaLDENr (ORCPT + 12 others); Wed, 3 Dec 2014 23:13:47 -0500 Received: from mail-pd0-f180.google.com ([209.85.192.180]:34673 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002AbaLDENr (ORCPT ); Wed, 3 Dec 2014 23:13:47 -0500 Received: by mail-pd0-f180.google.com with SMTP id p10so16872358pdj.11 for ; Wed, 03 Dec 2014 20:13:46 -0800 (PST) X-Received: by 10.70.129.81 with SMTP id nu17mr15223068pdb.54.1417666426751; Wed, 03 Dec 2014 20:13:46 -0800 (PST) Received: from localhost ([122.166.92.172]) by mx.google.com with ESMTPSA id cf4sm24439813pbb.3.2014.12.03.20.13.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 20:13:46 -0800 (PST) From: Viresh Kumar To: linux-pm@vger.kernel.org, edubezval@gmail.com Cc: linaro-kernel@lists.linaro.org, rui.zhang@intel.com, amit.daniel@samsung.com, javi.merino@arm.com, Viresh Kumar Subject: [PATCH V2 16/26] thermal: cpu_cooling: do error handling at the bottom in __cpufreq_cooling_register() Date: Thu, 4 Dec 2014 09:41:58 +0530 Message-Id: <9597eda04a6c679cbf8cdcb18ee423bbb7ac833a.1417664938.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.0.3.693.g996b0fd 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.217.182 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 life easy and bug free. And is scalable for future resource allocations. Acked-by: Javi Merino Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 1dd4cc4..491d90a 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -448,8 +448,8 @@ __cpufreq_cooling_register(struct device_node *np, ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); if (ret) { - kfree(cpufreq_dev); - return ERR_PTR(ret); + cool_dev = ERR_PTR(ret); + goto free_cdev; } snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", @@ -457,11 +457,9 @@ __cpufreq_cooling_register(struct device_node *np, cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, &cpufreq_cooling_ops); - if (IS_ERR(cool_dev)) { - release_idr(&cpufreq_idr, cpufreq_dev->id); - kfree(cpufreq_dev); - return cool_dev; - } + if (IS_ERR(cool_dev)) + goto remove_idr; + cpufreq_dev->cool_dev = cool_dev; mutex_lock(&cooling_cpufreq_lock); @@ -476,6 +474,13 @@ __cpufreq_cooling_register(struct device_node *np, mutex_unlock(&cooling_cpufreq_lock); return cool_dev; + +remove_idr: + release_idr(&cpufreq_idr, cpufreq_dev->id); +free_cdev: + kfree(cpufreq_dev); + + return cool_dev; } /**