summaryrefslogtreecommitdiff
path: root/drivers/serial/usbtty.c
diff options
context:
space:
mode:
authorTom Rini <trini@ti.com>2011-12-15 08:40:51 -0700
committerRemy Bohmer <linux@bohmer.net>2011-12-16 21:37:17 +0100
commitb2fb47f1873ae812ce33129996a22b11a36d0aa9 (patch)
tree8afeef2bce3d0ca0aa44ed59956086f6dae2767c /drivers/serial/usbtty.c
parentddc7e541ae62f29d85b35cdf8d12c7322d353d51 (diff)
downloadu-boot-imx-b2fb47f1873ae812ce33129996a22b11a36d0aa9.zip
u-boot-imx-b2fb47f1873ae812ce33129996a22b11a36d0aa9.tar.gz
u-boot-imx-b2fb47f1873ae812ce33129996a22b11a36d0aa9.tar.bz2
USB: Use (get|put)_unaligned for accessing wMaxPacketSize
In 9792987721c7980453fe6447c3fa6593b44f8458 Stefan describes a usecase where the previous behavior of leaving wMaxPacketSize be unaligned caused fatal problems. The initial fix for this problem was incomplete however as it showed another cases of non-aligned access that previously worked implicitly. This switches to making sure that all access of wMaxPacketSize are done via (get|put)_unaligned. In order to maintain a level of readability to the code in some cases we now use a variable for the value of wMaxPacketSize and in others, a macro. Cc: Minkyu Kang <mk7.kang@samsung.com> Cc: Remy Bohmer <linux@bohmer.net> OpenRISC: Tested-by: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi> Beagleboard xM, Pandaboard run-tested, s5p_goni build-tested. Signed-off-by: Tom Rini <trini@ti.com>
Diffstat (limited to 'drivers/serial/usbtty.c')
-rw-r--r--drivers/serial/usbtty.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
index e2e87fe..a263b2c 100644
--- a/drivers/serial/usbtty.c
+++ b/drivers/serial/usbtty.c
@@ -25,6 +25,7 @@
#include <config.h>
#include <circbuf.h>
#include <stdio_dev.h>
+#include <asm/unaligned.h>
#include "usbtty.h"
#include "usb_cdc_acm.h"
#include "usbdescriptors.h"
@@ -626,6 +627,9 @@ static void usbtty_init_strings (void)
usb_strings = usbtty_string_table;
}
+#define init_wMaxPacketSize(x) le16_to_cpu(get_unaligned(\
+ &ep_descriptor_ptrs[(x) - 1]->wMaxPacketSize));
+
static void usbtty_init_instances (void)
{
int i;
@@ -688,14 +692,12 @@ static void usbtty_init_instances (void)
endpoint_instance[i].rcv_attributes =
ep_descriptor_ptrs[i - 1]->bmAttributes;
- endpoint_instance[i].rcv_packetSize =
- le16_to_cpu(ep_descriptor_ptrs[i - 1]->wMaxPacketSize);
+ endpoint_instance[i].rcv_packetSize = init_wMaxPacketSize(i);
endpoint_instance[i].tx_attributes =
ep_descriptor_ptrs[i - 1]->bmAttributes;
- endpoint_instance[i].tx_packetSize =
- le16_to_cpu(ep_descriptor_ptrs[i - 1]->wMaxPacketSize);
+ endpoint_instance[i].tx_packetSize = init_wMaxPacketSize(i);
endpoint_instance[i].tx_attributes =
ep_descriptor_ptrs[i - 1]->bmAttributes;