From patchwork Sun Jun 1 11:33:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Strandqvist X-Patchwork-Id: 4277521 X-Patchwork-Delegate: rui.zhang@intel.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 8E8309F1D6 for ; Sun, 1 Jun 2014 11:33:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8865203AB for ; Sun, 1 Jun 2014 11:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1C8620397 for ; Sun, 1 Jun 2014 11:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751929AbaFALc7 (ORCPT ); Sun, 1 Jun 2014 07:32:59 -0400 Received: from mail-we0-f177.google.com ([74.125.82.177]:60968 "EHLO mail-we0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753005AbaFALc6 (ORCPT ); Sun, 1 Jun 2014 07:32:58 -0400 Received: by mail-we0-f177.google.com with SMTP id x48so3916271wes.36 for ; Sun, 01 Jun 2014 04:32:57 -0700 (PDT) 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; bh=sUhqpuRyeNl57P3METZAg/VAjnHFhq0vDWNUHAAmBWQ=; b=AwKS476YaRmYagXiwdEVkmGT1/8UMzVSrDVc2PQNdV2i9RTu654pWtkO4CICupEWHo 2I55KXEsMJZiKii82zc/QvaW5lRO+Gt4A2o/DtS9pf8nfZcRN6NOWKSmHOFxyKdnS3Sc z+/uytTmuZtKUWiM4cexq5rUXUrDJx6mQoFrEhhy3ZoD40Dh4uEhnyepPIsr6APzPONJ qOxgSSQuPNCPi9b3ibkaAyKjda4+a51mYi9+K24bjYQlFgC9V3sxUPjA/FlrAp+m5w0a NEKiDITdEbyIXkUrbbKaa2aOcWdwMc/oLr3wzkAE9Qe+Z+8zYjQ73ak+fzOLxkD/wYuX 1jbA== X-Gm-Message-State: ALoCoQlOZSH/GOzAQbw/IVvsIObBqq0XhVRpoKzDS3azYIh5jUUZTQB07PDNixXkqhEx+gZx67bi X-Received: by 10.194.186.210 with SMTP id fm18mr40275169wjc.67.1401622377574; Sun, 01 Jun 2014 04:32:57 -0700 (PDT) Received: from localhost.localdomain (h-245-62.a218.priv.bahnhof.se. [85.24.245.62]) by mx.google.com with ESMTPSA id z14sm22858354wiu.6.2014.06.01.04.32.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jun 2014 04:32:56 -0700 (PDT) From: Rickard Strandqvist To: Eduardo Valentin , Zhang Rui Cc: Rickard Strandqvist , Grant Likely , Rob Herring , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak Date: Sun, 1 Jun 2014 13:33:51 +0200 Message-Id: <1401622431-13554-1-git-send-email-rickard_strandqvist@spectrumdigital.se> X-Mailer: git-send-email 1.7.10.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 There is a risk for memory leak in when something unexpected happens and the function returns. This was largely found by using a static code analysis program called cppcheck. Signed-off-by: Rickard Strandqvist --- drivers/thermal/ti-soc-thermal/ti-bandgap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index 3ab12ee..8401d2e 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -1155,8 +1155,9 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) /* register shadow for context save and restore */ bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) * bgp->conf->sensor_count, GFP_KERNEL); - if (!bgp) { + if (!bgp->regval) { dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n"); + devm_kfree(&pdev->dev, bgp); return ERR_PTR(-ENOMEM); }