From patchwork Sat Mar 29 13:37:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3908341 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 CBEA49F369 for ; Sat, 29 Mar 2014 13:37:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02FDC2037B for ; Sat, 29 Mar 2014 13:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EF3820382 for ; Sat, 29 Mar 2014 13:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751591AbaC2Nhv (ORCPT ); Sat, 29 Mar 2014 09:37:51 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:52434 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751545AbaC2Nhv (ORCPT ); Sat, 29 Mar 2014 09:37:51 -0400 Received: by mail-pd0-f177.google.com with SMTP id y10so6008420pdj.22 for ; Sat, 29 Mar 2014 06:37:50 -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=/Ke7/6S4PUSEhY9K9VA2wxL+NTAsoTkfoYqVvDeqqYE=; b=LeGihXxG8nyXGcLUsBkqISszfCNsFyUgjyd9SdzGuC31aCe3E4uED8i1wx2tKni4so HdjwQ0UYBVExeBFlMiCyF7BmrB7+8z2UokrbWhIhM2OMb8q10YE/vszqJcZBsa97ixBP puMHyA27lwf8G2eey2+WX4pGIbpmDd8VfXd+SB79D/INknokIt237Pu8r7ioqnRzrJXM g8uMb3P0OQaj2ylgHw6QPw2QSt8OFRwwbOcJGbA9nBRcaIlnAeO3Krb+0aLOfPu4JpZD wEJ6Hm96C+2qp+TLfyYf5jwzn/oA+NgaBWsCmfcn3DPyXNtGF0xBA2Uue8DEphoi6YtU iLWg== X-Gm-Message-State: ALoCoQlblNNiC9nR0WScjk0vZXM1kN0pmBbk+ZvWKDMiTlBnJ3Yci05pVDe9WS1Gk9evYgeUI7qN X-Received: by 10.67.2.34 with SMTP id bl2mr14394002pad.58.1396100270663; Sat, 29 Mar 2014 06:37:50 -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 vb7sm31572285pbc.13.2014.03.29.06.37.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 29 Mar 2014 06:37:49 -0700 (PDT) Message-ID: <1396100264.10175.1.camel@phoenix> Subject: [PATCH] spi: omap2-mcspi: Convert to use devm_kcalloc From: Axel Lin To: Mark Brown Cc: Illia Smyrnov , linux-spi@vger.kernel.org Date: Sat, 29 Mar 2014 21:37:44 +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.3 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 This saves a few unwind code and return proper error if devm_kcalloc fails. Signed-off-by: Axel Lin --- drivers/spi/spi-omap2-mcspi.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 2941c5b..4dc77df 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -1379,12 +1379,13 @@ static int omap2_mcspi_probe(struct platform_device *pdev) INIT_LIST_HEAD(&mcspi->ctx.cs); - mcspi->dma_channels = kcalloc(master->num_chipselect, - sizeof(struct omap2_mcspi_dma), - GFP_KERNEL); - - if (mcspi->dma_channels == NULL) + mcspi->dma_channels = devm_kcalloc(&pdev->dev, master->num_chipselect, + sizeof(struct omap2_mcspi_dma), + GFP_KERNEL); + if (mcspi->dma_channels == NULL) { + status = -ENOMEM; goto free_master; + } for (i = 0; i < master->num_chipselect; i++) { char *dma_rx_ch_name = mcspi->dma_channels[i].dma_rx_ch_name; @@ -1426,7 +1427,7 @@ static int omap2_mcspi_probe(struct platform_device *pdev) } if (status < 0) - goto dma_chnl_free; + goto free_master; pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); @@ -1444,8 +1445,6 @@ static int omap2_mcspi_probe(struct platform_device *pdev) disable_pm: pm_runtime_disable(&pdev->dev); -dma_chnl_free: - kfree(mcspi->dma_channels); free_master: spi_master_put(master); return status; @@ -1453,19 +1452,12 @@ free_master: static int omap2_mcspi_remove(struct platform_device *pdev) { - struct spi_master *master; - struct omap2_mcspi *mcspi; - struct omap2_mcspi_dma *dma_channels; - - master = platform_get_drvdata(pdev); - mcspi = spi_master_get_devdata(master); - dma_channels = mcspi->dma_channels; + struct spi_master *master = platform_get_drvdata(pdev); + struct omap2_mcspi *mcspi = spi_master_get_devdata(master); pm_runtime_put_sync(mcspi->dev); pm_runtime_disable(&pdev->dev); - kfree(dma_channels); - return 0; }