Skip to contentSkip to conversation

ksz884x: fix Endian

PATCH Applied [email protected] 3 participants 5 messages Jul 5, 2012 – Jul 9, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 ksz884x: fix Endian

From: Li RongQing <[email protected]>

ETH_P_IP is host Endian, skb->protocol is big Endian, when compare them, we should change skb->protocol from big endian to host endian, ntohs, not htons.

---
 drivers/net/ethernet/micrel/ksz884x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/micrel/ksz884x.c +1 -1
index eaf9ff0..d9727f7 100644
@@ -4882,7 +4882,7 @@ static netdev_tx_t netdev_tx(struct sk_buff *skb, struct net_device *dev)
 	if (left) {
 		if (left < num ||
 				((CHECKSUM_PARTIAL == skb->ip_summed) &&
-				(ETH_P_IPV6 == htons(skb->protocol)))) {
+				(ETH_P_IPV6 == ntohs(skb->protocol)))) {
 			struct sk_buff *org_skb = skb;
 
 			skb = netdev_alloc_skb(dev, org_skb->len);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 17 lines · On Thu, 2012-07-05 at 10:06 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

ETH_P_IP is host Endian, skb->protocol is big Endian, when compare them, we should change skb->protocol from big endian to host endian, ntohs, not htons.

---
 drivers/net/ethernet/micrel/ksz884x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/micrel/ksz884x.c +0 -0
index eaf9ff0..d9727f7 100644

drivers/net/ethernet/micrel/ksz884x.c static netdev_tx_t netdev_tx(struct sk_buff *skb, struct net_device *dev) · line 4885

Quoted 5 lines
drivers/net/ethernet/micrel/ksz884x.c +1 -1
@@ -4882,7 +4882,7 @@ static netdev_tx_t netdev_tx(struct sk_buff *skb, struct net_device *dev)
 	if (left) {
 		if (left < num ||
 				((CHECKSUM_PARTIAL == skb->ip_summed) &&
-				(ETH_P_IPV6 == htons(skb->protocol)))) {
+				(ETH_P_IPV6 == ntohs(skb->protocol)))) {

This should really be changed to the idiomatic 'skb->protocol == htons(ETH_P_IPV6)'. For the current code, the compiler will probably generate a run-time byte-swap for little-endian systems.

Ben.

Quoted 3 lines
drivers/net/ethernet/micrel/ksz884x.c +0 -0
 			struct sk_buff *org_skb = skb;
 
 			skb = netdev_alloc_skb(dev, org_skb->len);
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw

2012/7/7, Ben Hutchings <[email protected]>:

Quoted 43 lines · On Thu, 2012-07-05 at 10:06 +0800, [email protected] wrote:
Quoted 18 lines

From: Li RongQing <[email protected]>

ETH_P_IP is host Endian, skb->protocol is big Endian, when compare them, we should change skb->protocol from big endian to host endian, ntohs, not htons.

---
 drivers/net/ethernet/micrel/ksz884x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/micrel/ksz884x.c +0 -0
index eaf9ff0..d9727f7 100644

drivers/net/ethernet/micrel/ksz884x.c static netdev_tx_t netdev_tx(struct sk_buff *skb, · line 4886

Quoted 6 lines
drivers/net/ethernet/micrel/ksz884x.c +1 -1
@@ -4882,7 +4882,7 @@ static netdev_tx_t netdev_tx(struct sk_buff *skb,
 struct net_device *dev)
 	if (left) {
 		if (left < num ||
 				((CHECKSUM_PARTIAL == skb->ip_summed) &&
-				(ETH_P_IPV6 == htons(skb->protocol)))) {
+				(ETH_P_IPV6 == ntohs(skb->protocol)))) {

This should really be changed to the idiomatic 'skb->protocol == htons(ETH_P_IPV6)'. For the current code, the compiler will probably generate a run-time byte-swap for little-endian systems.

Ben.

Quoted 3 lines
drivers/net/ethernet/micrel/ksz884x.c +0 -0
 			struct sk_buff *org_skb = skb;
 

skb = netdev_alloc_skb(dev, org_skb->len);

--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.

#3 lore raw

Please ignore the first reply.

OK, I will change it as Ben's suggestion.

Thanks

-Roy

#4 lore raw
In reply to RongQing Li
Quoted 5 lines · RongQing Li

2012/7/7, Ben Hutchings <[email protected]>:

Quoted 4 lines · On Thu, 2012-07-05 at 10:06 +0800, [email protected] wrote:
Quoted 3 lines

ETH_P_IP is host Endian, skb->protocol is big Endian, when compare them, we should change skb->protocol from big endian to host endian, ntohs, not htons.

[]

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

[]

Quoted 11 lines
Quoted 11 lines

drivers/net/ethernet/micrel/ksz884x.c static netdev_tx_t netdev_tx(struct sk_buff *skb, · line 4886

Quoted 7 lines
drivers/net/ethernet/micrel/ksz884x.c +1 -1
@@ -4882,7 +4882,7 @@ static netdev_tx_t netdev_tx(struct sk_buff *skb,
 struct net_device *dev)
 	if (left) {
 		if (left < num ||
 				((CHECKSUM_PARTIAL == skb->ip_summed) &&
-				(ETH_P_IPV6 == htons(skb->protocol)))) {
+				(ETH_P_IPV6 == ntohs(skb->protocol)))) {

This should really be changed to the idiomatic 'skb->protocol == htons(ETH_P_IPV6)'. For the current code, the compiler will probably generate a run-time byte-swap for little-endian systems.

True. Perhaps this would be better written as:

	if (left) {
		if (left < num ||
		    (ip->ip_summed == CHECKSUM_PARTIAL &&
		     skb->protocol == htons(ETH_P_IPV6))) {

			etc...