From patchwork Thu Mar 20 09:20:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3863931 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0A3DBF540 for ; Thu, 20 Mar 2014 09:20:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E517A201FA for ; Thu, 20 Mar 2014 09:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A4D6201F4 for ; Thu, 20 Mar 2014 09:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751226AbaCTJU0 (ORCPT ); Thu, 20 Mar 2014 05:20:26 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:55391 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751224AbaCTJUY (ORCPT ); Thu, 20 Mar 2014 05:20:24 -0400 Received: by mail-pd0-f176.google.com with SMTP id r10so654562pdi.35 for ; Thu, 20 Mar 2014 02:20:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=NkQd/eCwjFYvRzYr+5FJB1fm/B4dpfniSaK+4QsdHww=; b=IQ/Au2ioljkbppTSInPgMlTkoIRY2wl3SEjb3L9rQx7mjF+CcWpn/wGL/m6HAf4Dzf nKObKPjmHXc/JMZC8VGa0oBBWWNpnf8qCh64tGrEOo0WVG8pN+1PaGFTIkpR2jpr6kl6 ebPDPkX6sSnei9GQWvLn8v920EMHihsClsDNDwkRJ2FuxvCnEXcb4sd81F0QGzGWXtJg 9GV23wgRXB+sjGXAg5LCZZzSatWkXJRtgRRMHpYWjqQYMel5SVfb0+EaMdgg2d9A7IdM s6/q++nz61lkqKd0STTAl9V8An1Gr2K0/cs39xGwzOesWCHF7+6NIs9obA/rCliqdETa Wv7A== X-Gm-Message-State: ALoCoQkcivEbssUQcari6KzOlvNqvVxs5o/YArAJcRHTfxoiSYtOxZn0CtSGar9pUNMYOnDID1rJ X-Received: by 10.68.102.34 with SMTP id fl2mr46483910pbb.2.1395307224080; Thu, 20 Mar 2014 02:20:24 -0700 (PDT) Received: from [192.168.0.102] (218-164-140-232.dynamic.hinet.net. [218.164.140.232]) by mx.google.com with ESMTPSA id jd5sm2668928pbb.18.2014.03.20.02.20.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:20:23 -0700 (PDT) Message-ID: <1395307217.9142.1.camel@phoenix> Subject: [PATCH] spi: fsl-lib: Fix memory leak of pinfo From: Axel Lin To: Mark Brown Cc: Stefan Roese , Andreas Larsson , linux-spi@vger.kernel.org Date: Thu, 20 Mar 2014 17:20:17 +0800 X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@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=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 of_mpc8xxx_spi_probe() allocates memory for pinfo but the memory is not freed anywhere. of_mpc8xxx_spi_probe() is called in .probe() and pinfo should be freed in .remove(), so convert kzalloc to devm_kzalloc to fix the memory leak. Signed-off-by: Axel Lin --- drivers/spi/spi-fsl-lib.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c index 0b75f26..e5d45fc 100644 --- a/drivers/spi/spi-fsl-lib.c +++ b/drivers/spi/spi-fsl-lib.c @@ -200,7 +200,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) const void *prop; int ret = -ENOMEM; - pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc(&ofdev->dev, sizeof(*pinfo), GFP_KERNEL); if (!pinfo) return -ENOMEM; @@ -215,15 +215,13 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) pdata->sysclk = get_brgfreq(); if (pdata->sysclk == -1) { pdata->sysclk = fsl_get_sys_freq(); - if (pdata->sysclk == -1) { - ret = -ENODEV; - goto err; - } + if (pdata->sysclk == -1) + return -ENODEV; } #else ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk); if (ret) - goto err; + return ret; #endif prop = of_get_property(np, "mode", NULL); @@ -237,8 +235,4 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) pdata->flags = SPI_CPM_MODE | SPI_CPM1; return 0; - -err: - kfree(pinfo); - return ret; }