From patchwork Sun Sep 4 07:58:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9312409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7AA9600CA for ; Sun, 4 Sep 2016 08:07:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8E22287DA for ; Sun, 4 Sep 2016 08:07:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C395288F0; Sun, 4 Sep 2016 08:07:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F740287DA for ; Sun, 4 Sep 2016 08:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138AbcIDIHd (ORCPT ); Sun, 4 Sep 2016 04:07:33 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36468 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751524AbcIDIHa (ORCPT ); Sun, 4 Sep 2016 04:07:30 -0400 Received: by mail-wm0-f66.google.com with SMTP id l65so895518wmf.3 for ; Sun, 04 Sep 2016 01:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=bPC7TiDWsQegNmotGob2cE1yxlfD6Yh1mI6RkKh4BTw=; b=q45+BkBb4O3dGR3MDPoZYjwSjXH4oYWv8OK1GKPO3kAEDBezA7W28+PW8q19xqq3qu +u9ezmdKNz2S3zYiPy1+axV42eccdlkbpKRUt6U/5QTJbBTYeEwSq3gf+Md4q/57M1Lx 6M1mtU5s25cZdlc1OkpSP869s5wEJlKJmKMRrKKUSn2zOixbARxELkba7S3nNdL2H5cL kVAreo+GowC0uML5ehMX1YBvGo+XzTQr9UGfaGdHN+tGp4QR1tU6JkQ//2HXdNAdZGxY dIiCRS8U08F6Dde5I2tGvcAmunRRT1Ddb9eJoiS9+GLme5AyTujTt7dbq7brNJu/cgxH bBGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=bPC7TiDWsQegNmotGob2cE1yxlfD6Yh1mI6RkKh4BTw=; b=m8/2W3WbDG3BSvy3W+rgmPGuHJqW52FXvkzX+V9qKwzFgk/t2x/oZlV9gX47HwQe0e LCKpmqh59Owo3m6j7DuWFNFyzPnG01YOjdkaLVvUPkQ1T2uhaLWVPHNB+JuAxnxlM3f2 e6xqyXJfj49O0WVxhedjsczIU5+a5bu/n94SKDbYLfVtJHLLVMfaWZjOgsPF4pi5urSF Sh/hagXDVL+Jst5IK0+lMH6FKgXUOOwgMoZn2jnWyHeJdS0nVsXuY6uj/cDWtBwa7waQ zo8kyr+vJsAkmXNC+Ahp/Oy9o8/bltxqVAnFcN60cybYDG/p4Dg7x693sQ65ERLm4LoA xZwA== X-Gm-Message-State: AE9vXwPI3qLlIfA0iy0cUAXVglETkCc2z7QASOGnYAbVpH+d8hn+LqT+zRxpAqyV1AeGOQ== X-Received: by 10.28.58.7 with SMTP id h7mr10526954wma.35.1472976449030; Sun, 04 Sep 2016 01:07:29 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:c1f5:c528:a3d:f8c4? (p200300625F439500C1F5C5280A3DF8C4.dip0.t-ipconnect.de. [2003:62:5f43:9500:c1f5:c528:a3d:f8c4]) by smtp.googlemail.com with ESMTPSA id 3sm13047655wms.1.2016.09.04.01.07.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Sep 2016 01:07:28 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 05/18] spi: fsl-espi: factor out filling the local buffer To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: Date: Sun, 4 Sep 2016 09:58:18 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Better structure the code by factoring out filling the local buffer. In addition don't initialize the complete local buffer at the beginning of fsl_espi_do_one_msg. Instead move initialization of those parts of the local buffer to be used for transfers w/o tx_buf to fsl_espi_copy_to_buf. Signed-off-by: Heiner Kallweit --- v2: - fixed coding style issue - improved commit message --- drivers/spi/spi-fsl-espi.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index a3a75ae..c0023c0 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -85,6 +85,27 @@ struct fsl_espi_transfer { #define AUTOSUSPEND_TIMEOUT 2000 +static unsigned int fsl_espi_copy_to_buf(struct spi_message *m, + struct mpc8xxx_spi *mspi) +{ + unsigned int tx_only = 0; + struct spi_transfer *t; + u8 *buf = mspi->local_buf; + + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->tx_buf) { + memcpy(buf, t->tx_buf, t->len); + if (!t->rx_buf) + tx_only += t->len; + } else { + memset(buf, 0, t->len); + } + buf += t->len; + } + + return tx_only; +} + static void fsl_espi_change_mode(struct spi_device *spi) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master); @@ -301,16 +322,9 @@ static void fsl_espi_cmd_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - struct spi_transfer *t; - int i = 0; struct fsl_espi_transfer *espi_trans = trans; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(mspi->local_buf + i, t->tx_buf, t->len); - i += t->len; - } - } + fsl_espi_copy_to_buf(m, mspi); espi_trans->tx_buf = mspi->local_buf; espi_trans->rx_buf = mspi->local_buf; @@ -323,18 +337,9 @@ static void fsl_espi_rw_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - struct spi_transfer *t; - unsigned int tx_only = 0; - int i = 0; + unsigned int tx_only; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(mspi->local_buf + i, t->tx_buf, t->len); - i += t->len; - if (!t->rx_buf) - tx_only += t->len; - } - } + tx_only = fsl_espi_copy_to_buf(m, mspi); trans->tx_buf = mspi->local_buf; trans->rx_buf = mspi->local_buf; @@ -352,14 +357,11 @@ static void fsl_espi_rw_trans(struct spi_message *m, static int fsl_espi_do_one_msg(struct spi_master *master, struct spi_message *m) { - struct mpc8xxx_spi *mspi = spi_master_get_devdata(master); struct spi_transfer *t; u8 *rx_buf = NULL; unsigned int xfer_len = 0; struct fsl_espi_transfer espi_trans; - memset(mspi->local_buf, 0, SPCOM_TRANLEN_MAX); - list_for_each_entry(t, &m->transfers, transfer_list) { if (t->rx_buf) rx_buf = t->rx_buf;