Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1271311 > unrolled thread
| Started by | Joshua Clayton <stillcompiling@gmail.com> |
|---|---|
| First post | 2015-11-17 16:30 +0100 |
| Last post | 2015-11-17 20:00 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Joshua Clayton <stillcompiling@gmail.com> - 2015-11-17 16:30 +0100
Re: [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Mark Brown <broonie@kernel.org> - 2015-11-17 18:50 +0100
Re: [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer Joshua Clayton <stillcompiling@gmail.com> - 2015-11-17 20:00 +0100
| From | Joshua Clayton <stillcompiling@gmail.com> |
|---|---|
| Date | 2015-11-17 16:30 +0100 |
| Subject | [PATCH 1/8] Documentation/spi/spidev_test.c: use one rx buffer |
| Message-ID | <qvQmJ-6NX-5@gated-at.bofh.it> |
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Mark Brown <broonie@kernel.org> |
|---|---|
| Date | 2015-11-17 18:50 +0100 |
| Message-ID | <qvSyf-8a9-17@gated-at.bofh.it> |
| In reply to | #1271311 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Nov 17, 2015 at 07:24:21AM -0800, Joshua Clayton wrote: > default_rx and rx are needlessly different. > Use one buffer, local to transmit() Why? This isn't what I'd expect from black boxing the API, from a userspace point of view the transfer is atomic and in an ideal world we'd be able to do direct to/from memory transfers rather than memcpy() into kernel space which means that userspace should assume the transfers are going on simultaneously even if they don't currently.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Clayton <stillcompiling@gmail.com> |
|---|---|
| Date | 2015-11-17 20:00 +0100 |
| Message-ID | <qvTDX-m1-1@gated-at.bofh.it> |
| In reply to | #1271491 |
On Tuesday, November 17, 2015 05:41:56 PM Mark Brown wrote: > On Tue, Nov 17, 2015 at 07:24:21AM -0800, Joshua Clayton wrote: > > > default_rx and rx are needlessly different. > > Use one buffer, local to transmit() > > Why? This isn't what I'd expect from black boxing the API, from a > userspace point of view the transfer is atomic and in an ideal world > we'd be able to do direct to/from memory transfers rather than memcpy() > into kernel space which means that userspace should assume the transfers > are going on simultaneously even if they don't currently. The important thing here was to get rid of the default_rx buffer. I just noticed that the output can be set up completely within the scope of the transmit function, since the operands are global. But I would be just as happy to set it up at the top level. I'll change this in V2 -- ~Joshua Clayton -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web