From patchwork Mon Sep 12 19:08:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 9327711 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 77A606048B for ; Mon, 12 Sep 2016 19:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6151128E90 for ; Mon, 12 Sep 2016 19:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5346E28E94; Mon, 12 Sep 2016 19:09:09 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 ED86B28E90 for ; Mon, 12 Sep 2016 19:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753113AbcILTJH (ORCPT ); Mon, 12 Sep 2016 15:09:07 -0400 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:33284 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754813AbcILTJG (ORCPT ); Mon, 12 Sep 2016 15:09:06 -0400 Received: from debutante.sirena.org.uk ([2a01:348:6:8808:fab::3] helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bjWb9-0003D3-8w; Mon, 12 Sep 2016 19:08:57 +0000 Received: from broonie by debutante with local (Exim 4.87) (envelope-from ) id 1bjWb6-0002x7-IS; Mon, 12 Sep 2016 20:08:52 +0100 From: Mark Brown To: Heiner Kallweit Cc: Gabor Juhos , Felix Fietkau , Mark Brown , Mark Brown , "linux-spi@vger.kernel.org" , Gabor Juhos In-Reply-To: Message-Id: Date: Mon, 12 Sep 2016 20:08:52 +0100 X-SA-Exim-Connect-IP: 2a01:348:6:8808:fab::3 X-SA-Exim-Mail-From: broonie@sirena.org.uk Subject: Applied "spi: fsl-espi: pre-allocate message buffer" to the spi tree X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: No (on mezzanine.sirena.org.uk); Unknown failure 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 The patch spi: fsl-espi: pre-allocate message buffer has been applied to the spi tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 1423877b73ed5f4982eaba8bed359605b9918a2b Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Wed, 7 Sep 2016 22:50:22 +0200 Subject: [PATCH] spi: fsl-espi: pre-allocate message buffer Currently the driver allocates a 64kb buffer for each single message. On systems with little and fragmented memory this can result in memory allocation errors. Solve this by pre-allocating a buffer. This patch was developed in OpenWRT long ago, however it never made it upstream. I slightly modified the original patch to re-initialize the buffer at the beginning of each transfer. Signed-off-by: Gabor Juhos Signed-off-by: Felix Fietkau Signed-off-by: Heiner Kallweit Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-espi.c | 41 ++++++++++++++++++----------------------- drivers/spi/spi-fsl-lib.h | 1 + 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 16fff7237ab2..81d7416668b8 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -297,57 +297,44 @@ static void fsl_espi_do_trans(struct spi_message *m, 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; - u8 *local_buf; int i = 0; struct fsl_espi_transfer *espi_trans = trans; - local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL); - if (!local_buf) { - espi_trans->status = -ENOMEM; - return; - } - list_for_each_entry(t, &m->transfers, transfer_list) { if (t->tx_buf) { - memcpy(local_buf + i, t->tx_buf, t->len); + memcpy(mspi->local_buf + i, t->tx_buf, t->len); i += t->len; } } - espi_trans->tx_buf = local_buf; - espi_trans->rx_buf = local_buf; + espi_trans->tx_buf = mspi->local_buf; + espi_trans->rx_buf = mspi->local_buf; fsl_espi_do_trans(m, espi_trans); espi_trans->actual_length = espi_trans->len; - kfree(local_buf); } 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; - u8 *local_buf; unsigned int tx_only = 0; int i = 0; - local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL); - if (!local_buf) { - trans->status = -ENOMEM; - return; - } - list_for_each_entry(t, &m->transfers, transfer_list) { if (t->tx_buf) { - memcpy(local_buf + i, t->tx_buf, t->len); + memcpy(mspi->local_buf + i, t->tx_buf, t->len); i += t->len; if (!t->rx_buf) tx_only += t->len; } } - trans->tx_buf = local_buf; - trans->rx_buf = local_buf; + trans->tx_buf = mspi->local_buf; + trans->rx_buf = mspi->local_buf; fsl_espi_do_trans(m, trans); if (!trans->status) { @@ -357,18 +344,19 @@ static void fsl_espi_rw_trans(struct spi_message *m, trans->len - tx_only); trans->actual_length += trans->len; } - - kfree(local_buf); } 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; @@ -614,6 +602,13 @@ static struct spi_master * fsl_espi_probe(struct device *dev, mpc8xxx_spi = spi_master_get_devdata(master); + mpc8xxx_spi->local_buf = + devm_kmalloc(dev, SPCOM_TRANLEN_MAX, GFP_KERNEL); + if (!mpc8xxx_spi->local_buf) { + ret = -ENOMEM; + goto err_probe; + } + mpc8xxx_spi->reg_base = devm_ioremap_resource(dev, mem); if (IS_ERR(mpc8xxx_spi->reg_base)) { ret = PTR_ERR(mpc8xxx_spi->reg_base); diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h index 84f5dcb7a897..065b9db212cf 100644 --- a/drivers/spi/spi-fsl-lib.h +++ b/drivers/spi/spi-fsl-lib.h @@ -30,6 +30,7 @@ struct mpc8xxx_spi { void *rx; #if IS_ENABLED(CONFIG_SPI_FSL_ESPI) int len; + u8 *local_buf; #endif int subblock;