summaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-05-22 00:34:04 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2019-05-23 09:57:04 +0200
commit5d9954fdcee824be6a9163d1ffd99002558553bf (patch)
treed4797e958813988bafc26b15d28a4b5017d91e97 /drivers/usb
parent42724155da89da38af46b01592d20b007448e5db (diff)
downloadbarebox-5d9954fdcee824be6a9163d1ffd99002558553bf.tar.gz
barebox-5d9954fdcee824be6a9163d1ffd99002558553bf.tar.xz
usb: host: ehci: Simplify ehci_td_buffer()
Rework the code of ehci_td_buffer() with following trivial changes: * Switch to using dma_addr_t for 'delta' and 'next' * Convert while to for loop * Replace explicit magic number with dedicated contants derived via ARRAY_SIZE * Use ALIGN_DOWN to calculate 'next' * Return -ENOMEM instead of -1 when we ran out of buffers Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/host/ehci-hcd.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 9758e1ed73..6742a67de9 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -31,6 +31,7 @@
#include <of.h>
#include <usb/ehci.h>
#include <linux/err.h>
+#include <linux/sizes.h>
#include "ehci.h"
@@ -186,24 +187,23 @@ out:
static int ehci_td_buffer(struct qTD *td, dma_addr_t addr, size_t sz)
{
- uint32_t delta, next;
+ const size_t buffer_count = ARRAY_SIZE(td->qt_buffer);
+ dma_addr_t delta, next;
int idx;
- idx = 0;
- while (idx < 5) {
+ for (idx = 0; idx < buffer_count; idx++) {
td->qt_buffer[idx] = cpu_to_hc32(addr);
- next = (addr + 4096) & ~4095;
+ next = ALIGN_DOWN(addr + SZ_4K, SZ_4K);
delta = next - addr;
if (delta >= sz)
break;
sz -= delta;
addr = next;
- idx++;
}
- if (idx == 5) {
+ if (idx == buffer_count) {
pr_debug("out of buffer pointers (%u bytes left)\n", sz);
- return -1;
+ return -ENOMEM;
}
return 0;