From patchwork Sat May 12 08:17:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 8559 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E1A0423EB5 for ; Sat, 12 May 2012 08:17:39 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9C487A186C1 for ; Sat, 12 May 2012 08:17:39 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id un3so1708738obb.11 for ; Sat, 12 May 2012 01:17:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=eBlYBMtTDN78E8dkwpPLUZSJF7ustm/8Ggf51JMj2GY=; b=o6fw8zUprRnQfeJsn2OyJWjYKLy/zI3S2LLF8UcK8wu2X4Ba8rj/NfdKQsuIXHpK7j fmZof/MgGpbnqijK3195s0vKbM5caGWaSgQQIOXt5gGrlDQkMRE0jNTUoKnZaIAyN0s4 E3FrEhJeaENkuZTR0VcrODJwS52FuPVrZz1WcZZGscQg608d1ftYcX3Bh/r5Wz76+kaV /pcIU0lQ3c8l5zgUnK3cAAiscVGS1yBpDyolSOm3xIdscniz04G91kMLpAnuHI4PUS/C ZVNHpgh5DST+cgQyWSoFnvM/SVUymidiJ564sv9Y77VKRD3MIfKigC7O1J2GCQhVQFdD zmAA== Received: by 10.50.181.164 with SMTP id dx4mr528988igc.1.1336810659311; Sat, 12 May 2012 01:17:39 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.73.147 with SMTP id q19csp226561ibj; Sat, 12 May 2012 01:17:38 -0700 (PDT) Received: by 10.152.147.100 with SMTP id tj4mr959729lab.39.1336810658073; Sat, 12 May 2012 01:17:38 -0700 (PDT) Received: from mail.df.lth.se (mail.df.lth.se. [194.47.250.12]) by mx.google.com with ESMTPS id w4si5597183lby.13.2012.05.12.01.17.37 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 12 May 2012 01:17:38 -0700 (PDT) Received-SPF: neutral (google.com: 194.47.250.12 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=194.47.250.12; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.47.250.12 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) smtp.mail=linus.walleij@linaro.org Received: from fecusia (c83-249-216-219.bredband.comhem.se [83.249.216.219]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.df.lth.se (Postfix) with ESMTPSA id D05EA65D8B; Sat, 12 May 2012 10:17:35 +0200 (CEST) Received: by fecusia (sSMTP sendmail emulation); Sat, 12 May 2012 10:17:35 +0200 From: "Linus Walleij" To: netdev@vger.kernel.org, linux-usb@vger.kernel.org, "David S. Miller" , Greg Kroah-Hartman , Felipe Balbi Cc: Jussi Kivilinna , Haiyang Zhang , Wei Yongjun , Ben Hutchings , Linus Walleij Subject: [PATCH 14/17 v5] rndis_host: cleanup: byteswap data from device instead of RNDIS_* defines Date: Sat, 12 May 2012 10:17:34 +0200 Message-Id: <1336810654-5650-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.7.7.6 X-Gm-Message-State: ALoCoQkkJ9Pv4ZL4rhKDq65N+nNm19NqbL5GJCe9wtcQ8DLmwHF94+AdwHRYZ767G7mqHjzUZQSQ From: Jussi Kivilinna All other values from device provided buffer are byteswapped, so it seems more logical to do same for these. Signed-off-by: Jussi Kivilinna Signed-off-by: Linus Walleij --- drivers/net/usb/rndis_host.c | 53 ++++++++++++++++++++++------------------- 1 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c index dd342dc..74315fd 100644 --- a/drivers/net/usb/rndis_host.c +++ b/drivers/net/usb/rndis_host.c @@ -77,16 +77,17 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg, if (dev->driver_info->indication) { dev->driver_info->indication(dev, msg, buflen); } else { - switch (msg->status) { - case cpu_to_le32(RNDIS_STATUS_MEDIA_CONNECT): + u32 status = le32_to_cpu(msg->status); + + switch (status) { + case RNDIS_STATUS_MEDIA_CONNECT: dev_info(udev, "rndis media connect\n"); break; - case cpu_to_le32(RNDIS_STATUS_MEDIA_DISCONNECT): + case RNDIS_STATUS_MEDIA_DISCONNECT: dev_info(udev, "rndis media disconnect\n"); break; default: - dev_info(udev, "rndis indication: 0x%08x\n", - le32_to_cpu(msg->status)); + dev_info(udev, "rndis indication: 0x%08x\n", status); } } } @@ -109,16 +110,17 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) int retval; int partial; unsigned count; - __le32 rsp; - u32 xid = 0, msg_len, request_id; + u32 xid = 0, msg_len, request_id, msg_type, rsp, + status; /* REVISIT when this gets called from contexts other than probe() or * 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 */ - if (likely(buf->msg_type != cpu_to_le32(RNDIS_MSG_HALT) && - buf->msg_type != cpu_to_le32(RNDIS_MSG_RESET))) { + if (likely(msg_type != RNDIS_MSG_HALT && msg_type != RNDIS_MSG_RESET)) { xid = dev->xid++; if (!xid) xid = dev->xid++; @@ -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 */ - 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++) { memset(buf, 0, CONTROL_BUFFER_SIZE); retval = usb_control_msg(dev->udev, @@ -160,30 +162,31 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) buf, buflen, RNDIS_CONTROL_TIMEOUT_MS); if (likely(retval >= 8)) { + msg_type = le32_to_cpu(buf->msg_type); msg_len = le32_to_cpu(buf->msg_len); + status = le32_to_cpu(buf->status); request_id = (__force u32) buf->request_id; - if (likely(buf->msg_type == rsp)) { + if (likely(msg_type == rsp)) { if (likely(request_id == xid)) { - if (unlikely(rsp == - cpu_to_le32(RNDIS_MSG_RESET_C))) + if (unlikely(rsp == RNDIS_MSG_RESET_C)) return 0; - if (likely(cpu_to_le32(RNDIS_STATUS_SUCCESS) - == buf->status)) + if (likely(RNDIS_STATUS_SUCCESS == + status)) return 0; dev_dbg(&info->control->dev, "rndis reply status %08x\n", - le32_to_cpu(buf->status)); + status); return -EL3RST; } dev_dbg(&info->control->dev, "rndis reply id %d expected %d\n", request_id, xid); /* then likely retry */ - } else switch (buf->msg_type) { - case cpu_to_le32(RNDIS_MSG_INDICATE): /* fault/event */ + } else switch (msg_type) { + case RNDIS_MSG_INDICATE: /* fault/event */ rndis_msg_indicate(dev, (void *)buf, buflen); break; - case cpu_to_le32(RNDIS_MSG_KEEPALIVE): { /* ping */ + case RNDIS_MSG_KEEPALIVE: { /* ping */ struct rndis_keepalive_c *msg = (void *)buf; 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) phym = &phym_unspec; } 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, "driver requires wireless physical medium, but device is not\n"); retval = -ENODEV; goto halt_fail_and_release; } 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, "driver requires non-wireless physical medium, but device is wireless.\n"); retval = -ENODEV; @@ -496,16 +499,16 @@ int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb) while (likely(skb->len)) { struct rndis_data_hdr *hdr = (void *)skb->data; 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); data_offset = le32_to_cpu(hdr->data_offset); data_len = le32_to_cpu(hdr->data_len); /* don't choke if we see oob, per-packet data, etc */ - if (unlikely(hdr->msg_type != cpu_to_le32(RNDIS_MSG_PACKET) || - skb->len < msg_len || - (data_offset + data_len + 8) > msg_len)) { + if (unlikely(msg_type != RNDIS_MSG_PACKET || skb->len < msg_len + || (data_offset + data_len + 8) > msg_len)) { dev->net->stats.rx_frame_errors++; netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n", le32_to_cpu(hdr->msg_type),