From patchwork Tue Mar 25 01:19:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3885061 Return-Path: X-Original-To: patchwork-linux-spi@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 2B2789F334 for ; Tue, 25 Mar 2014 01:25:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32B3520270 for ; Tue, 25 Mar 2014 01:25:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 550E62026D for ; Tue, 25 Mar 2014 01:25:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751192AbaCYBZp (ORCPT ); Mon, 24 Mar 2014 21:25:45 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:55950 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751232AbaCYBZh (ORCPT ); Mon, 24 Mar 2014 21:25:37 -0400 Received: by mail-pa0-f49.google.com with SMTP id lj1so6209881pab.22 for ; Mon, 24 Mar 2014 18:25:37 -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=+If6jRNHldzao6rAi47+a9QE6XEs11bZK5o4lRiB0aE=; b=MO2AIwIW+cIbfqsrYTyWO+PK4WFKU3zhqjq2EsFEFchw1mcef7LqPP8zqMTRyJ+ieG V0AFt5+qbVSxQ4kMAiZ4zApPMuuMlsJhyJhc0mN6E/08PesXxjD/yiTUmtMU87cyMjwY aP5SFfcVXmSIk+EKpnG/8z5UoYr5Kmwcyhu0c9Ptxc+GnBLUxBMh+8rcqxjLGbo29yOX Ym0J1BtWjJEMoY7ZmjB6rnS3b8D1Mg1iGH9AafUaFmbKBh+Lf/wvHnkcbmwt53wYJM+h ixY4ecPMGTwT1nXAn3ek9CRNz8WvVKRRSrbffSVNO8PigiWgFWR2gwBiwAEbeEsm+7T8 PBHw== X-Gm-Message-State: ALoCoQknk/jkbQ+xAP4b1csRAIOxUzgqH4hNVwxBsVYFmuh8PqFf1s91H0bHlfvHXEQIdpFLv2X5 X-Received: by 10.68.71.131 with SMTP id v3mr75484608pbu.68.1395710351252; Mon, 24 Mar 2014 18:19:11 -0700 (PDT) Received: from [192.168.0.102] (36-239-218-97.dynamic-ip.hinet.net. [36.239.218.97]) by mx.google.com with ESMTPSA id db3sm37127954pbb.10.2014.03.24.18.19.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 24 Mar 2014 18:19:10 -0700 (PDT) Message-ID: <1395710345.29281.1.camel@phoenix> Subject: [PATCH] spi: fsl-dspi: Fix memory leak From: Axel Lin To: Mark Brown Cc: Chao Fu , Alison Wang , linux-spi@vger.kernel.org Date: Tue, 25 Mar 2014 09:19:05 +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=-7.4 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 The memory allocated for chip is not freed anywhere. Convert to use devm_kzalloc to fix the memory leak. Signed-off-by: Axel Lin --- drivers/spi/spi-fsl-dspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 2249cb7..d565eee 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -342,7 +342,8 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) /* Only alloc on first setup */ chip = spi_get_ctldata(spi); if (chip == NULL) { - chip = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL); + chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data), + GFP_KERNEL); if (!chip) return -ENOMEM; } @@ -353,7 +354,6 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) fmsz = spi->bits_per_word - 1; } else { pr_err("Invalid wordsize\n"); - kfree(chip); return -ENODEV; }