From patchwork Fri Sep 2 20:03:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9311591 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 76F1760760 for ; Fri, 2 Sep 2016 20:03:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68A6B29858 for ; Fri, 2 Sep 2016 20:03:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DAD92985A; Fri, 2 Sep 2016 20:03:50 +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=-5.8 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 E763829858 for ; Fri, 2 Sep 2016 20:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932750AbcIBUDt (ORCPT ); Fri, 2 Sep 2016 16:03:49 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33608 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932403AbcIBUDs (ORCPT ); Fri, 2 Sep 2016 16:03:48 -0400 Received: by mail-wm0-f68.google.com with SMTP id w207so4164939wmw.0 for ; Fri, 02 Sep 2016 13:03:48 -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=nuz8gxf/CNU+T9G8e/b9xUn57tWO7vzpFxwWntADYwK3GBxSGgph/cBlMTadnANuP+ EV6leMkF1ewsFyEr+oonlmbo05SbI5F5qRoGcZt42KA2CVYtIzFZoxlzcm80OiZ3pxSv /g+yaBohs9yNZmdP72qw2i9IRyokNrCz5yjaiavQFFoZBDSR6nils0ydYKiG7Gu+hfJ4 dsoQKNFxGLBg5wipfEmhnSpp3eMMDaf10Y45QQKqA40I406IBcfjpIKvkTyn01VkP0cf ouqSalxz7wUIO6Pua2z9BDWCFIbzdoF0fPiy2WqniXm1bOngrQedREdcSCSrwupMUdt5 jFog== 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=Hf3e8QMq8sMhLdgbuPkxhRqzlfC6zh/D/WdQvi7nGyIP1syJQVchAinUU8ANj+eema xWSj/YZHVIug+GelehQR//kB0Vw0SmZF6GQ6r+RpvHkGd1sUXAbxqwCjNwHCJOd3/1vG GsA6IOS3+ZiP7pwnaM/LXAP0MIXSwO4PInIBF0IIK8EmqOYBo/R6VdOVEz/HjvtfuABm uiq/c79yragOTh0Ow5Wa4fVxeuZrPsu85MIfCZwqRmziLpt/iVgJ9/t+JuaE3rehFHgk lQ3hx7NKYgxdwAuN8LaBtazsRtaRQb7vI+JhZgTDWAt0F/42Q0H21Z++U1i4o0z9/q3d cBBg== X-Gm-Message-State: AE9vXwNldD63wJoWerf/BFAR1N9MiYnRtLhpsddVwkfmsmX/gb1aby6crmFCPSoLfQsUxQ== X-Received: by 10.28.27.143 with SMTP id b137mr4960640wmb.12.1472846627312; Fri, 02 Sep 2016 13:03:47 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:39ed:a1fb:9a43:e02d? (p200300625F43950039EDA1FB9A43E02D.dip0.t-ipconnect.de. [2003:62:5f43:9500:39ed:a1fb:9a43:e02d]) by smtp.googlemail.com with ESMTPSA id i129sm5126495wmg.5.2016.09.02.13.03.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 13:03:46 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 08/23] spi: fsl-espi: factor out filling the local buffer To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <75a01618-11f4-d54c-4cb7-21e1ed40951a@gmail.com> Date: Fri, 2 Sep 2016 22:03:28 +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;