From patchwork Wed Sep 7 20:50:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9319897 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 924D4607D3 for ; Wed, 7 Sep 2016 20:55:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E75529427 for ; Wed, 7 Sep 2016 20:55:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EE7629429; Wed, 7 Sep 2016 20:55:40 +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 E06DC29427 for ; Wed, 7 Sep 2016 20:55:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbcIGUzj (ORCPT ); Wed, 7 Sep 2016 16:55:39 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35744 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751810AbcIGUzi (ORCPT ); Wed, 7 Sep 2016 16:55:38 -0400 Received: by mail-wm0-f68.google.com with SMTP id a6so4858465wmc.2 for ; Wed, 07 Sep 2016 13:55:37 -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=GmO7bxlJ8mTbbv863OcQizNHVqTqcqDY1zqHljZSlao=; b=dIakLGwi51sJkPrRKNFQ5fWj8AysVy6U88pbr3OH8wcJeHTFSwpBRYdxpUcEbUni8p aHZ8P1LGNO9Oy8IAvFnmGGeaf+sCCQSqzbGfOy1ZF6ZNHINWXSp2/yb1JViVGRxInzmZ hddg+ptFDDWThdaw7TpRiCotdzW/yf68DaOLFv9AVzqLPfBLN0wUHiofDtJXgj/0abBb pQwI5xY3dSXI+Sr1VXoeWZGwVWPv7L7i8kLYwLJh0mgU92So8E+Efhu1RqpDPN8M2OZU jkdkCK+wrmOSRO5UuiuQ2x31zt6wvq2jChLhvwECeH8nqM3NC+r2T5IZ08K9O08NKbcq Za2A== 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=GmO7bxlJ8mTbbv863OcQizNHVqTqcqDY1zqHljZSlao=; b=DtIOGzSS/iq9tMUlAV84cwXiMFDVlCDXHc5Lolc1Ii7pQDKDVVhyysVBtO3tGhPij7 vkydu9pFtU/1oiPExsuzcAJGfCOk1q/kMVwXryuwXw3b/zil02WPbj3tkqY+JTetOedh RxeT8UQmWVzdEK2dSuRYCaXzuePAM9XzEDLBS09keVwYygMB0ku/gOfrbbUcjzhb2aAv dNBmuROC/6NDiw+kPSga8uE0cLKjFN+6gZqvgvfY4pNbXoI2oyVZHm+MUNJU7I3XH6ls xXQqC8Fea7u2v7geV5GvmMTWm6DcMNotUaEH73bJHnPfuPGAQMNkuF05cKEOmyYeinhA OdPA== X-Gm-Message-State: AE9vXwPcGs5Wr5VRbltPBcXG+iNJaIBcLAqfEkCzeaJMe7Vi2FLqt0BN+uqCSNh4Kjrnpg== X-Received: by 10.28.142.2 with SMTP id q2mr5419725wmd.119.1473281737188; Wed, 07 Sep 2016 13:55:37 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:6565:4488:ad4:60db? (p200300625F439500656544880AD460DB.dip0.t-ipconnect.de. [2003:62:5f43:9500:6565:4488:ad4:60db]) by smtp.googlemail.com with ESMTPSA id o5sm6037168wmg.16.2016.09.07.13.55.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Sep 2016 13:55:36 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v3 02/15] spi: fsl-espi: factor out filling the local buffer To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <5639514c-cfd6-212d-fbce-c2d6ab420696@gmail.com> Date: Wed, 7 Sep 2016 22:50:53 +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 v3: - new numbering --- 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;