From: Grant Likely <grant.likely@secretlab.ca>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: spi-devel-general@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: Re: [PATCH] spi: Remove SPI_BUFSIZ restriction on spi_write_then_read()
Date: Thu, 06 Dec 2012 00:00:26 +0000 [thread overview]
Message-ID: <20121206000026.A620D3E0E22@localhost> (raw)
In-Reply-To: <1354420465-29315-1-git-send-email-broonie@opensource.wolfsonmicro.com>
On Sun, 2 Dec 2012 12:54:25 +0900, Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:
> In order to avoid constantly allocating and deallocating there is a fixed
> buffer which spi_write_then_read() uses for transfers, with an early error
> check to ensure that the transfer fits within the buffer. This limits the
> size of transfers to this size, currently max(32, SMP_CACHE_BYTES).
>
> Since we can dynamically allocate and in fact already have a fallback
> to do so when there is contention for the fixed buffer remove this
> restriction and instead dynamically allocate a suitably sized buffer if
> the transfer won't fit.
>
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Looks good to me. Probably 3.9 material though.
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> drivers/spi/spi.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index c4f7d71..224b7bc 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1646,12 +1646,18 @@ int spi_write_then_read(struct spi_device *spi,
> struct spi_transfer x[2];
> u8 *local_buf;
>
> - /* Use preallocated DMA-safe buffer. We can't avoid copying here,
> - * (as a pure convenience thing), but we can keep heap costs
> - * out of the hot path ...
> + /* Use preallocated DMA-safe buffer if we can. We can't avoid
> + * copying here, (as a pure convenience thing), but we can
> + * keep heap costs out of the hot path unless someone else is
> + * using the pre-allocated buffer or the transfer is too large.
> */
> - if ((n_tx + n_rx) > SPI_BUFSIZ)
> - return -EINVAL;
> + if ((n_tx + n_rx) > SPI_BUFSIZ || !mutex_trylock(&lock)) {
> + local_buf = kmalloc(max(SPI_BUFSIZ, n_tx + n_rx), GFP_KERNEL);
> + if (!local_buf)
> + return -ENOMEM;
> + } else {
> + local_buf = buf;
> + }
>
> spi_message_init(&message);
> memset(x, 0, sizeof x);
> @@ -1664,14 +1670,6 @@ int spi_write_then_read(struct spi_device *spi,
> spi_message_add_tail(&x[1], &message);
> }
>
> - /* ... unless someone else is using the pre-allocated buffer */
> - if (!mutex_trylock(&lock)) {
> - local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
> - if (!local_buf)
> - return -ENOMEM;
> - } else
> - local_buf = buf;
> -
> memcpy(local_buf, txbuf, n_tx);
> x[0].tx_buf = local_buf;
> x[1].rx_buf = local_buf + n_tx;
> --
> 1.7.10.4
>
--
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
next prev parent reply other threads:[~2012-12-06 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-02 3:54 [PATCH] spi: Remove SPI_BUFSIZ restriction on spi_write_then_read() Mark Brown
2012-12-06 0:00 ` Grant Likely [this message]
2012-12-06 5:37 ` Mark Brown
[not found] ` <20121206053732.GD10867-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-12-06 14:04 ` Grant Likely
2012-12-06 14:04 ` Grant Likely
2012-12-07 3:41 ` Mark Brown
[not found] ` <20121207034140.GB26070-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-12-07 14:04 ` Grant Likely
2012-12-07 14:04 ` Grant Likely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121206000026.A620D3E0E22@localhost \
--to=grant.likely@secretlab.ca \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=spi-devel-general@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.