From: "Marius B. Kotsbak" <marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Marius B. Kotsbak"
<marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
Subject: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
Date: Wed, 22 Jun 2011 17:26:16 +0200 [thread overview]
Message-ID: <1308756376-9920-1-git-send-email-marius@kotsbak.com> (raw)
In-Reply-To: <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
-Support for big endian.
-Do not use USB buffers at the stack.
-Safer/more efficient code for local constants.
Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
---
drivers/net/usb/kalmia.c | 40 ++++++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index d965fb1..d4edeb2 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
static int
kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
{
- char init_msg_1[] =
+ const static char init_msg_1[] =
{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
0x00, 0x00 };
- char init_msg_2[] =
+ const static char init_msg_2[] =
{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
0x00, 0x00 };
- char receive_buf[28];
+ const static int buflen = 28;
+ char *usb_buf;
int status;
- status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
- / sizeof(init_msg_1[0]), receive_buf, 24);
+ usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
+ if (!usb_buf)
+ return -ENOMEM;
+
+ memcpy(usb_buf, init_msg_1, 12);
+ status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
+ / sizeof(init_msg_1[0]), usb_buf, 24);
if (status != 0)
return status;
- status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
- / sizeof(init_msg_2[0]), receive_buf, 28);
+ memcpy(usb_buf, init_msg_2, 12);
+ status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
+ / sizeof(init_msg_2[0]), usb_buf, 28);
if (status != 0)
return status;
- memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+ memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
+ kfree(usb_buf);
return status;
}
@@ -190,7 +198,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
dev_kfree_skb_any(skb);
skb = skb2;
- done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+done:
+ header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
@@ -201,9 +210,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
header_start[0] = 0x57;
header_start[1] = 0x44;
content_len = skb->len - KALMIA_HEADER_LENGTH;
- header_start[2] = (content_len & 0xff); /* low byte */
- header_start[3] = (content_len >> 8); /* high byte */
+ put_unaligned_le16(content_len, &header_start[2]);
header_start[4] = ether_type_1;
header_start[5] = ether_type_2;
@@ -231,13 +239,13 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
* Our task here is to strip off framing, leaving skb with one
* data frame for the usbnet framework code to process.
*/
- const u8 HEADER_END_OF_USB_PACKET[] =
+ const static u8 HEADER_END_OF_USB_PACKET[] =
{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
- const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+ const static u8 EXPECTED_UNKNOWN_HEADER_1[] =
{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
- const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+ const static u8 EXPECTED_UNKNOWN_HEADER_2[] =
{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
- u8 i = 0;
+ int i = 0;
/* incomplete header? */
if (skb->len < KALMIA_HEADER_LENGTH)
@@ -285,7 +293,7 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
/* subtract start header and end header */
usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
- ether_packet_length = header_start[2] + (header_start[3] << 8);
+ ether_packet_length = get_unaligned_le16(&header_start[2]);
skb_pull(skb, KALMIA_HEADER_LENGTH);
/* Some small packets misses end marker */
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2011-06-22 15:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-10 23:34 [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 Marius B. Kotsbak
[not found] ` <1307748870-12950-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-10 23:55 ` Greg KH
[not found] ` <20110610235557.GA23443-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2011-06-11 0:25 ` Marius Kotsbak
2011-06-11 20:06 ` Greg KH
2011-06-11 21:55 ` Marius B. Kotsbak
2011-06-11 23:27 ` David Miller
2011-06-11 23:29 ` David Miller
[not found] ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-12 3:46 ` Ben Hutchings
2011-06-12 12:35 ` Marius B. Kotsbak
2011-06-17 2:01 ` David Miller
[not found] ` <20110616.220112.882657314456163072.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-17 10:31 ` Marius Bjørnstad Kotsbak
2011-06-12 12:36 ` Marius Kotsbak
[not found] ` <1307829318-18246-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-14 8:49 ` Oliver Neukum
[not found] ` <201106141049.39150.oneukum-l3A5Bk7waGM@public.gmane.org>
2011-06-14 9:32 ` Marius Kotsbak
[not found] ` <4DF72A90.1070702-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-14 9:46 ` Oliver Neukum
[not found] ` <201106141146.19097.oneukum-l3A5Bk7waGM@public.gmane.org>
2011-06-19 21:45 ` [PATCH 1/2] " Marius B. Kotsbak
2011-06-19 21:45 ` [PATCH 2/2] Various fixes for better support of non-x86 architectures Marius B. Kotsbak
2011-06-19 22:57 ` [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 David Miller
[not found] ` <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-22 15:24 ` Marius Kotsbak
2011-06-22 15:26 ` Marius B. Kotsbak [this message]
2011-06-22 20:41 ` [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures David Miller
[not found] ` <1308756376-9920-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-23 10:46 ` Sergei Shtylyov
[not found] ` <4E03198A.2060600-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
2011-06-23 14:28 ` Alan Stern
2011-06-23 14:55 ` Sergei Shtylyov
[not found] ` <4E0353D0.1060604-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
2011-06-24 5:42 ` Oliver Neukum
[not found] ` <201106240742.38806.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2011-06-24 11:55 ` Sergei Shtylyov
2011-06-23 20:56 ` Marius Kotsbak
2011-06-19 21:53 ` [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 Marius Kotsbak
[not found] ` <4DFE6FD8.1080003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-20 6:47 ` Oliver Neukum
2011-06-11 21:57 ` Marius Kotsbak
[not found] ` <4DF3E4E1.2070309-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-11 22:40 ` Greg KH
2011-06-13 14:57 ` Dan Williams
[not found] ` <1307977039.2117.7.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
2011-06-13 15:01 ` Marius Kotsbak
[not found] ` <4DF62656.8060506-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-13 15:19 ` Dan Williams
[not found] ` <1307978364.2117.11.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
2011-06-18 20:03 ` Marius Kotsbak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308756376-9920-1-git-send-email-marius@kotsbak.com \
--to=marius.kotsbak-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).