From patchwork Sun Mar 30 08:43:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3909711 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 42EA2BF540 for ; Sun, 30 Mar 2014 08:43:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7545920386 for ; Sun, 30 Mar 2014 08:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F49320384 for ; Sun, 30 Mar 2014 08:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752612AbaC3Ini (ORCPT ); Sun, 30 Mar 2014 04:43:38 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:46059 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752005AbaC3Inh (ORCPT ); Sun, 30 Mar 2014 04:43:37 -0400 Received: by mail-pd0-f182.google.com with SMTP id y10so6728531pdj.27 for ; Sun, 30 Mar 2014 01:43: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=clZn6yysWS9Thwd/STv/ybKkjOdZtY1MQVG3SnjSmAY=; b=XvzdRJ7PUGdalovUw7AfkOYsHGswvuSJfJRESOaFFBARHDyX7gQfs+FqpS4j2G8znO /2g7QH4FwAWan/tq7U5a/L+y9wkgzuvEP78oiqVwn8S6oagzj19glQYZYlifz7ROexud n8xX6ZMk0dj3v0F4CzP88A5P50MYBM7SwaYWNE/upbbabtAPC2WBGI4xybqqsUThwDY9 ZYZze9LOHTBgQudpMBQ+WP3fv80nvb68yheUdbh6QLEUROrFZFptSC2iiZzsu9P4YoI0 Gs89FTJMVi7q0Ec6lECgF1yR0acW4/uLF9qSpRnbL9rOYBi5385dZVPha7zu73O3Ic3I yU4g== X-Gm-Message-State: ALoCoQnVeT/KVUzAB7IGEFYmVAH97bFj+7qi4jp8qshK9artkeIRN/HoWT5WUm4q8ERipqDcqU11 X-Received: by 10.68.194.38 with SMTP id ht6mr755334pbc.120.1396169017030; Sun, 30 Mar 2014 01:43:37 -0700 (PDT) Received: from [192.168.0.119] (59-115-21-222.dynamic.hinet.net. [59.115.21.222]) by mx.google.com with ESMTPSA id ac5sm35911243pbc.37.2014.03.30.01.43.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 30 Mar 2014 01:43:36 -0700 (PDT) Message-ID: <1396169003.21905.7.camel@phoenix> Subject: [PATCH] spi: fsl: Kill mpc8xxx_spi_cleanup and convert fsl_espi_setup to use devm_kzalloc From: Axel Lin To: Mark Brown Cc: Stefan Roese , Andreas Larsson , linux-spi@vger.kernel.org Date: Sun, 30 Mar 2014 16:43:23 +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=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 In current code, master->cleanup and master->setup are not set in the same function. This makes it hard to read and not good for code maintain. One example is in fsl-spi.c, master->cleanup is overrided in mpc8xxx_spi_probe() which leads to a memory leak. This patch removes mpc8xxx_spi_cleanup() and converts fsl_espi_setup to use devm_kzalloc so we don't need to take care of freeing memory. Signed-off-by: Axel Lin --- drivers/spi/spi-fsl-espi.c | 2 +- drivers/spi/spi-fsl-lib.c | 6 ------ drivers/spi/spi-fsl-lib.h | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 6fb2b75..2cbd596 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -457,7 +457,7 @@ static int fsl_espi_setup(struct spi_device *spi) return -EINVAL; if (!cs) { - cs = kzalloc(sizeof *cs, GFP_KERNEL); + cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL); if (!cs) return -ENOMEM; spi->controller_state = cs; diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c index e5d45fc..95212ea 100644 --- a/drivers/spi/spi-fsl-lib.c +++ b/drivers/spi/spi-fsl-lib.c @@ -99,11 +99,6 @@ int mpc8xxx_spi_transfer(struct spi_device *spi, return 0; } -void mpc8xxx_spi_cleanup(struct spi_device *spi) -{ - kfree(spi->controller_state); -} - const char *mpc8xxx_spi_strmode(unsigned int flags) { if (flags & SPI_QE_CPU_MODE) { @@ -134,7 +129,6 @@ int mpc8xxx_spi_probe(struct device *dev, struct resource *mem, | SPI_LSB_FIRST | SPI_LOOP; master->transfer = mpc8xxx_spi_transfer; - master->cleanup = mpc8xxx_spi_cleanup; master->dev.of_node = dev->of_node; mpc8xxx_spi = spi_master_get_devdata(master); diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h index 52db693..2fcbfd0 100644 --- a/drivers/spi/spi-fsl-lib.h +++ b/drivers/spi/spi-fsl-lib.h @@ -124,7 +124,6 @@ extern struct mpc8xxx_spi_probe_info *to_of_pinfo( extern int mpc8xxx_spi_bufs(struct mpc8xxx_spi *mspi, struct spi_transfer *t, unsigned int len); extern int mpc8xxx_spi_transfer(struct spi_device *spi, struct spi_message *m); -extern void mpc8xxx_spi_cleanup(struct spi_device *spi); extern const char *mpc8xxx_spi_strmode(unsigned int flags); extern int mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq);