提交 3eef3668 编写于 作者: J Jussi Kivilinna 提交者: David S. Miller

rndis_host: cleanup: byteswap data from device instead of RNDIS_* defines

All other values from device provided buffer are byteswapped, so it seems
more logical to do same for these.
Signed-off-by: NJussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 d5543206
...@@ -77,16 +77,17 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg, ...@@ -77,16 +77,17 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg,
if (dev->driver_info->indication) { if (dev->driver_info->indication) {
dev->driver_info->indication(dev, msg, buflen); dev->driver_info->indication(dev, msg, buflen);
} else { } else {
switch (msg->status) { u32 status = le32_to_cpu(msg->status);
case cpu_to_le32(RNDIS_STATUS_MEDIA_CONNECT):
switch (status) {
case RNDIS_STATUS_MEDIA_CONNECT:
dev_info(udev, "rndis media connect\n"); dev_info(udev, "rndis media connect\n");
break; break;
case cpu_to_le32(RNDIS_STATUS_MEDIA_DISCONNECT): case RNDIS_STATUS_MEDIA_DISCONNECT:
dev_info(udev, "rndis media disconnect\n"); dev_info(udev, "rndis media disconnect\n");
break; break;
default: default:
dev_info(udev, "rndis indication: 0x%08x\n", dev_info(udev, "rndis indication: 0x%08x\n", status);
le32_to_cpu(msg->status));
} }
} }
} }
...@@ -109,16 +110,17 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) ...@@ -109,16 +110,17 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
int retval; int retval;
int partial; int partial;
unsigned count; unsigned count;
__le32 rsp; u32 xid = 0, msg_len, request_id, msg_type, rsp,
u32 xid = 0, msg_len, request_id; status;
/* REVISIT when this gets called from contexts other than probe() or /* REVISIT when this gets called from contexts other than probe() or
* disconnect(): either serialize, or dispatch responses on xid * disconnect(): either serialize, or dispatch responses on xid
*/ */
msg_type = le32_to_cpu(buf->msg_type);
/* Issue the request; xid is unique, don't bother byteswapping it */ /* Issue the request; xid is unique, don't bother byteswapping it */
if (likely(buf->msg_type != cpu_to_le32(RNDIS_MSG_HALT) && if (likely(msg_type != RNDIS_MSG_HALT && msg_type != RNDIS_MSG_RESET)) {
buf->msg_type != cpu_to_le32(RNDIS_MSG_RESET))) {
xid = dev->xid++; xid = dev->xid++;
if (!xid) if (!xid)
xid = dev->xid++; xid = dev->xid++;
...@@ -149,7 +151,7 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) ...@@ -149,7 +151,7 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
} }
/* Poll the control channel; the request probably completed immediately */ /* Poll the control channel; the request probably completed immediately */
rsp = buf->msg_type | cpu_to_le32(RNDIS_MSG_COMPLETION); rsp = le32_to_cpu(buf->msg_type) | RNDIS_MSG_COMPLETION;
for (count = 0; count < 10; count++) { for (count = 0; count < 10; count++) {
memset(buf, 0, CONTROL_BUFFER_SIZE); memset(buf, 0, CONTROL_BUFFER_SIZE);
retval = usb_control_msg(dev->udev, retval = usb_control_msg(dev->udev,
...@@ -160,30 +162,31 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) ...@@ -160,30 +162,31 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
buf, buflen, buf, buflen,
RNDIS_CONTROL_TIMEOUT_MS); RNDIS_CONTROL_TIMEOUT_MS);
if (likely(retval >= 8)) { if (likely(retval >= 8)) {
msg_type = le32_to_cpu(buf->msg_type);
msg_len = le32_to_cpu(buf->msg_len); msg_len = le32_to_cpu(buf->msg_len);
status = le32_to_cpu(buf->status);
request_id = (__force u32) buf->request_id; request_id = (__force u32) buf->request_id;
if (likely(buf->msg_type == rsp)) { if (likely(msg_type == rsp)) {
if (likely(request_id == xid)) { if (likely(request_id == xid)) {
if (unlikely(rsp == if (unlikely(rsp == RNDIS_MSG_RESET_C))
cpu_to_le32(RNDIS_MSG_RESET_C)))
return 0; return 0;
if (likely(cpu_to_le32(RNDIS_STATUS_SUCCESS) if (likely(RNDIS_STATUS_SUCCESS ==
== buf->status)) status))
return 0; return 0;
dev_dbg(&info->control->dev, dev_dbg(&info->control->dev,
"rndis reply status %08x\n", "rndis reply status %08x\n",
le32_to_cpu(buf->status)); status);
return -EL3RST; return -EL3RST;
} }
dev_dbg(&info->control->dev, dev_dbg(&info->control->dev,
"rndis reply id %d expected %d\n", "rndis reply id %d expected %d\n",
request_id, xid); request_id, xid);
/* then likely retry */ /* then likely retry */
} else switch (buf->msg_type) { } else switch (msg_type) {
case cpu_to_le32(RNDIS_MSG_INDICATE): /* fault/event */ case RNDIS_MSG_INDICATE: /* fault/event */
rndis_msg_indicate(dev, (void *)buf, buflen); rndis_msg_indicate(dev, (void *)buf, buflen);
break; break;
case cpu_to_le32(RNDIS_MSG_KEEPALIVE): { /* ping */ case RNDIS_MSG_KEEPALIVE: { /* ping */
struct rndis_keepalive_c *msg = (void *)buf; struct rndis_keepalive_c *msg = (void *)buf;
msg->msg_type = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C); msg->msg_type = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
...@@ -404,14 +407,14 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags) ...@@ -404,14 +407,14 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags)
phym = &phym_unspec; phym = &phym_unspec;
} }
if ((flags & FLAG_RNDIS_PHYM_WIRELESS) && if ((flags & FLAG_RNDIS_PHYM_WIRELESS) &&
*phym != cpu_to_le32(RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN)) { le32_to_cpup(phym) != RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
netif_dbg(dev, probe, dev->net, netif_dbg(dev, probe, dev->net,
"driver requires wireless physical medium, but device is not\n"); "driver requires wireless physical medium, but device is not\n");
retval = -ENODEV; retval = -ENODEV;
goto halt_fail_and_release; goto halt_fail_and_release;
} }
if ((flags & FLAG_RNDIS_PHYM_NOT_WIRELESS) && if ((flags & FLAG_RNDIS_PHYM_NOT_WIRELESS) &&
*phym == cpu_to_le32(RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN)) { le32_to_cpup(phym) == RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
netif_dbg(dev, probe, dev->net, netif_dbg(dev, probe, dev->net,
"driver requires non-wireless physical medium, but device is wireless.\n"); "driver requires non-wireless physical medium, but device is wireless.\n");
retval = -ENODEV; retval = -ENODEV;
...@@ -496,16 +499,16 @@ int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb) ...@@ -496,16 +499,16 @@ int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
while (likely(skb->len)) { while (likely(skb->len)) {
struct rndis_data_hdr *hdr = (void *)skb->data; struct rndis_data_hdr *hdr = (void *)skb->data;
struct sk_buff *skb2; struct sk_buff *skb2;
u32 msg_len, data_offset, data_len; u32 msg_type, msg_len, data_offset, data_len;
msg_type = le32_to_cpu(hdr->msg_type);
msg_len = le32_to_cpu(hdr->msg_len); msg_len = le32_to_cpu(hdr->msg_len);
data_offset = le32_to_cpu(hdr->data_offset); data_offset = le32_to_cpu(hdr->data_offset);
data_len = le32_to_cpu(hdr->data_len); data_len = le32_to_cpu(hdr->data_len);
/* don't choke if we see oob, per-packet data, etc */ /* don't choke if we see oob, per-packet data, etc */
if (unlikely(hdr->msg_type != cpu_to_le32(RNDIS_MSG_PACKET) || if (unlikely(msg_type != RNDIS_MSG_PACKET || skb->len < msg_len
skb->len < msg_len || || (data_offset + data_len + 8) > msg_len)) {
(data_offset + data_len + 8) > msg_len)) {
dev->net->stats.rx_frame_errors++; dev->net->stats.rx_frame_errors++;
netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n", netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n",
le32_to_cpu(hdr->msg_type), le32_to_cpu(hdr->msg_type),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册