Commit 8da04760 authored by Pascal Terjan's avatar Pascal Terjan Committed by Greg Kroah-Hartman
Browse files

staging: rtl8192u: Merge almost duplicate code



This causes a change in behaviour:
- stats also get updated when reordering, this seems like it should be
  the case but those lines were commented out.
- sub_skb NULL check now happens early in both cases, previously it
  happened only after dereferencing it 12 times, so it may not actually
  be needed.

Signed-off-by: default avatarPascal Terjan <pterjan@google.com>

Link: https://lore.kernel.org/r/20200519150042.199690-1-pterjan@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cf5ffd22
Loading
Loading
Loading
Loading
+49 −77
Original line number Original line Diff line number Diff line
@@ -520,55 +520,68 @@ static bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *p
	return true;
	return true;
}
}


void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray, u8  index)
static void indicate_packets(struct ieee80211_device *ieee,
			     struct ieee80211_rxb *rxb)
{
{
	u8 i = 0, j = 0;
	struct net_device_stats *stats = &ieee->stats;
	struct net_device *dev = ieee->dev;
	u16 ethertype;
	u16 ethertype;
//	if(index > 1)
	u8 i;
//		IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__func__,index);

	for (j = 0; j < index; j++) {
	for (i = 0; i < rxb->nr_subframes; i++) {
//added by amy for reorder
		struct sk_buff *sub_skb = rxb->subframes[i];
		struct ieee80211_rxb *prxb = prxbIndicateArray[j];

		for (i = 0; i < prxb->nr_subframes; i++) {
		if (!sub_skb)
			struct sk_buff *sub_skb = prxb->subframes[i];
			continue;


		/* convert hdr + possible LLC headers into Ethernet header */
		/* convert hdr + possible LLC headers into Ethernet header */
		ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
		ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
		if (sub_skb->len >= 8 &&
		if (sub_skb->len >= 8 &&
				((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
		    ((!memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) &&
				  ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
			ethertype != ETH_P_AARP &&
				 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
			ethertype != ETH_P_IPX) ||
		     !memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE))) {
			/* remove RFC1042 or Bridge-Tunnel encapsulation and
			/* remove RFC1042 or Bridge-Tunnel encapsulation and
			 * replace EtherType */
			 * replace EtherType */
			skb_pull(sub_skb, SNAP_SIZE);
			skb_pull(sub_skb, SNAP_SIZE);
				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
		} else {
		} else {
			/* Leave Ethernet header part of hdr and full payload */
			/* Leave Ethernet header part of hdr and full payload */
			put_unaligned_be16(sub_skb->len, skb_push(sub_skb, 2));
			put_unaligned_be16(sub_skb->len, skb_push(sub_skb, 2));
				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
				memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
		}
		}
			//stats->rx_packets++;
		memcpy(skb_push(sub_skb, ETH_ALEN), rxb->src, ETH_ALEN);
			//stats->rx_bytes += sub_skb->len;
		memcpy(skb_push(sub_skb, ETH_ALEN), rxb->dst, ETH_ALEN);

		stats->rx_packets++;
		stats->rx_bytes += sub_skb->len;
		if (is_multicast_ether_addr(rxb->dst))
			stats->multicast++;


		/* Indicate the packets to upper layer */
		/* Indicate the packets to upper layer */
			if (sub_skb) {
		sub_skb->protocol = eth_type_trans(sub_skb, dev);
				sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
		memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
		memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
				sub_skb->dev = ieee->dev;
		sub_skb->dev = dev;
				sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
		/* 802.11 crc not sufficient */
				//skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
		sub_skb->ip_summed = CHECKSUM_NONE;
		ieee->last_rx_ps_time = jiffies;
		ieee->last_rx_ps_time = jiffies;
		netif_rx(sub_skb);
		netif_rx(sub_skb);
	}
	}
}
}

void ieee80211_indicate_packets(struct ieee80211_device *ieee,
				struct ieee80211_rxb **prxbIndicateArray,
				u8 index)
{
	u8 i;

	for (i = 0; i < index; i++) {
		struct ieee80211_rxb *prxb = prxbIndicateArray[i];

		indicate_packets(ieee, prxb);
		kfree(prxb);
		kfree(prxb);
		prxb = NULL;
		prxb = NULL;
	}
	}
}
}



static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
				    struct ieee80211_rxb *prxb,
				    struct ieee80211_rxb *prxb,
				    struct rx_ts_record *pTS, u16 SeqNum)
				    struct rx_ts_record *pTS, u16 SeqNum)
@@ -877,7 +890,6 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
	u16 fc, type, stype, sc;
	u16 fc, type, stype, sc;
	struct net_device_stats *stats;
	struct net_device_stats *stats;
	unsigned int frag;
	unsigned int frag;
	u16 ethertype;
	//added by amy for reorder
	//added by amy for reorder
	u8	TID = 0;
	u8	TID = 0;
	u16	SeqNum = 0;
	u16	SeqNum = 0;
@@ -1260,47 +1272,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,


//added by amy for reorder
//added by amy for reorder
	if (!ieee->pHTInfo->bCurRxReorderEnable || !pTS) {
	if (!ieee->pHTInfo->bCurRxReorderEnable || !pTS) {
//added by amy for reorder
		indicate_packets(ieee, rxb);
		for (i = 0; i < rxb->nr_subframes; i++) {
			struct sk_buff *sub_skb = rxb->subframes[i];

			if (sub_skb) {
				/* convert hdr + possible LLC headers into Ethernet header */
				ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
				if (sub_skb->len >= 8 &&
						((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
						  ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
						 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
					/* remove RFC1042 or Bridge-Tunnel encapsulation and
					 * replace EtherType */
					skb_pull(sub_skb, SNAP_SIZE);
					memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
					memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
				} else {
					u16 len;
					/* Leave Ethernet header part of hdr and full payload */
					len = be16_to_cpu(htons(sub_skb->len));
					memcpy(skb_push(sub_skb, 2), &len, 2);
					memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
					memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
				}

				stats->rx_packets++;
				stats->rx_bytes += sub_skb->len;
				if (is_multicast_ether_addr(dst)) {
					stats->multicast++;
				}

				/* Indicate the packets to upper layer */
				sub_skb->protocol = eth_type_trans(sub_skb, dev);
				memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
				sub_skb->dev = dev;
				sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
				//skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
				ieee->last_rx_ps_time = jiffies;
				netif_rx(sub_skb);
			}
		}
		kfree(rxb);
		kfree(rxb);
		rxb = NULL;
		rxb = NULL;