From patchwork Fri Nov 28 09:44:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 5402461 X-Patchwork-Delegate: eduardo.valentin@ti.com 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E69919F47A for ; Fri, 28 Nov 2014 09:45:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6A39820142 for ; Fri, 28 Nov 2014 09:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94C0F20123 for ; Fri, 28 Nov 2014 09:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751687AbaK1Jpe (ORCPT ); Fri, 28 Nov 2014 04:45:34 -0500 Received: from mail-pd0-f171.google.com ([209.85.192.171]:56127 "EHLO mail-pd0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293AbaK1Jpd (ORCPT ); Fri, 28 Nov 2014 04:45:33 -0500 Received: by mail-pd0-f171.google.com with SMTP id y13so6405472pdi.16 for ; Fri, 28 Nov 2014 01:45:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=HsjOEbMT2cvBqInSmi5wDBY2R1SqyohC11a+y07tLsg=; b=FUPDrWuNNW2WdRSAdFynp08+8VuD2Utb1Yk4o7qtxkYQHZWBwJUhrSGNjPxMKPrtP9 B2jc4YBQ4BMNDYbTOy9LOYVTvAQgzGwo8oAtICjwj57IU8HtTiVd//KKlHZtdGUUxfIl Fhw+MYcT2GDV+i/M3ZEBRXpQV3+kukSrd2LCqSbL1ULJrXkofY9IDpqpSFEAeT/lREn8 GlUfbKF8mZFDpzZuJs3LbV4Vg4CDPNmGRGN0iYj1oRfFCxm2xbuvQdzP9dNwUHaHnMJ0 2aNiLZ1/4U9eNz8hjt+zGLSmKnuFa7daUN8HXOltoJwRdGHbv/uXAF0bkQwyOGbtkF9c Ryjw== X-Gm-Message-State: ALoCoQlK2qt74G27VGx5T/EuYPTPRIXZmGT8yrSs/qAUTPGUlMl026qJEXHx804WIhLcOz80Z3jd X-Received: by 10.68.241.130 with SMTP id wi2mr70635388pbc.89.1417167933363; Fri, 28 Nov 2014 01:45:33 -0800 (PST) Received: from localhost ([122.167.111.40]) by mx.google.com with ESMTPSA id xg4sm9455004pab.8.2014.11.28.01.45.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:45:32 -0800 (PST) From: Viresh Kumar To: linux-pm@vger.kernel.org, edubezval@gmail.com Cc: linaro-kernel@lists.linaro.org, rui.zhang@intel.com, Viresh Kumar Subject: [PATCH 15/26] cpu_cooling: do error handling at the bottom in __cpufreq_cooling_register() Date: Fri, 28 Nov 2014 15:14:09 +0530 Message-Id: <01711a86da59f30b33e1c32aa29cc9b378d0c627.1417167599.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: 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, T_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 This makes life easy and bug free. And is scalable for future resource allocations. Signed-off-by: Viresh Kumar Acked-by: Javi Merino --- 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 41aa7d5..032cba3 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -440,8 +440,8 @@ __cpufreq_cooling_register(struct device_node *np, ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); if (ret) { - kfree(cpufreq_dev); - return ERR_PTR(cpufreq_dev->id); + cool_dev = ERR_PTR(cpufreq_dev->id); + goto free_cdev; } snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", @@ -449,11 +449,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); @@ -467,6 +465,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; } /**