mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joshua Clayton <stillcompiling@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Adrian Remonda <adrianremonda@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-spi@vger.kernel.org,
	Joshua Clayton <stillcompiling@gmail.com>
Subject: [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer
Date: Tue, 17 Nov 2015 07:24:21 -0800	[thread overview]
Message-ID: <2f17ae29e75967b4522b080c275b907622e1d353.1447773299.git.stillcompiling@gmail.com> (raw)
In-Reply-To: <cover.1447773299.git.stillcompiling@gmail.com>
In-Reply-To: <cover.1447773299.git.stillcompiling@gmail.com>

default_rx and rx are needlessly different.
Use one buffer, local to transmit()

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 Documentation/spi/spidev_test.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c
index 135b3f5..dfe8f47 100644
--- a/Documentation/spi/spidev_test.c
+++ b/Documentation/spi/spidev_test.c
@@ -46,7 +46,6 @@ uint8_t default_tx[] = {
 	0xF0, 0x0D,
 };
 
-uint8_t default_rx[ARRAY_SIZE(default_tx)] = {0, };
 char *input_tx;
 
 static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix)
@@ -100,10 +99,10 @@ static int unescape(char *_dst, char *_src, size_t len)
 	return ret;
 }
 
-static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
+static void transfer(int fd, uint8_t const *tx, size_t len)
 {
 	int ret;
-
+	uint8_t *rx = malloc(len);
 	struct spi_ioc_transfer tr = {
 		.tx_buf = (unsigned long)tx,
 		.rx_buf = (unsigned long)rx,
@@ -135,6 +134,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
 	if (verbose)
 		hex_dump(tx, len, 32, "TX");
 	hex_dump(rx, len, 32, "RX");
+	free(rx);
 }
 
 static void print_usage(const char *prog)
@@ -254,7 +254,6 @@ int main(int argc, char *argv[])
 	int ret = 0;
 	int fd;
 	uint8_t *tx;
-	uint8_t *rx;
 	int size;
 
 	parse_opts(argc, argv);
@@ -303,13 +302,11 @@ int main(int argc, char *argv[])
 	if (input_tx) {
 		size = strlen(input_tx+1);
 		tx = malloc(size);
-		rx = malloc(size);
 		size = unescape((char *)tx, input_tx, size);
-		transfer(fd, tx, rx, size);
-		free(rx);
+		transfer(fd, tx, size);
 		free(tx);
 	} else {
-		transfer(fd, default_tx, default_rx, sizeof(default_tx));
+		transfer(fd, default_tx, sizeof(default_tx));
 	}
 
 	close(fd);
-- 
2.5.0


  reply	other threads:[~2015-11-17 15:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17 15:24 [PATCH 0/8] spi: Add file i/o to spidev_test Joshua Clayton
2015-11-17 15:24 ` Joshua Clayton [this message]
2015-11-17 17:41   ` [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Mark Brown
2015-11-17 18:58     ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 2/8] Documentation/spi/spidev_test.c: clean up input_tx Joshua Clayton
2015-11-17 17:43   ` Mark Brown
2015-11-17 19:21     ` Joshua Clayton
2015-11-17 22:52       ` Mark Brown
2015-11-17 15:24 ` [PATCH 3/8] Documentation/spi/spidev_test.c: accept input from a file Joshua Clayton
2015-11-17 18:26   ` Anton Bondarenko
2015-11-17 18:46     ` Mark Brown
2015-11-17 19:28     ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 4/8] Documentation/spi/spidev_test.c: output to " Joshua Clayton
2015-11-17 15:24 ` [PATCH 5/8] Documentation/spi/spidev_test.c: check error Joshua Clayton
2015-11-17 15:24 ` [PATCH 6/8] Documentation/spi/spidev_test.c: fix whitespace Joshua Clayton
2015-11-17 15:24 ` [PATCH 7/8] tools/Makefile: minor whitespace cleanup Joshua Clayton
2015-11-17 18:09   ` Mark Brown
2015-11-17 19:41     ` Joshua Clayton
2015-11-17 15:24 ` [PATCH 8/8] spi: Move spi code from Documentation to tools Joshua Clayton
2015-11-17 18:11   ` Mark Brown
2015-11-17 15:37 ` [PATCH 0/8] spi: Add file i/o to spidev_test Mark Brown
2015-11-17 16:15   ` Joshua Clayton
2015-11-17 16:53     ` Mark Brown
2015-11-18 22:30     ` [PATCH v2 0/6] " Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 1/6] spi: Move spi code from Documentation to tools Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 2/6] spi: spidev_test: transfer_escaped_string function Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 3/6] spi: spidev_test: accept input from a file Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 4/6] spi: spidev_test: output to " Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 5/6] spi: spidev_test: check error Joshua Clayton
2015-11-18 22:30       ` [PATCH v2 6/6] spi: spidev_test: fix whitespace Joshua Clayton

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=2f17ae29e75967b4522b080c275b907622e1d353.1447773299.git.stillcompiling@gmail.com \
    --to=stillcompiling@gmail.com \
    --cc=adrianremonda@gmail.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®