Subject: [PATCH 6/32] rt2x00: Use arraylike accessors for entries in DMA ring

From: Ivo van Doorn <[email-masked]>
Date: Fri, 28 Apr 2006 00:02:56 +0200

From: Ivo van Doorn <[email-masked]>

Make the code a bit more readable by using
array like accessors for pointers in a loop.

Signed-off-by: Ivo van Doorn <[email-masked]>

diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2400pci.c wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2400pci.c
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2400pci.c	2006-04-27 21:39:24.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2400pci.c	2006-04-27 21:40:06.000000000 +0200
@@ -951,15 +951,15 @@ rt2400pci_alloc_ring(
 	 * Initialize all ring entries to contain valid
 	 * addresses.
 	 */
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		entry->skb = NULL;
-		entry->desc_addr = ring->data_addr
+		entry[counter].skb = NULL;
+		entry[counter].desc_addr = ring->data_addr
 			+ (counter * ring->desc_size);
-		entry->data_addr = ring->data_addr
+		entry[counter].data_addr = ring->data_addr
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
-		entry->data_dma = ring->data_dma
+		entry[counter].data_dma = ring->data_dma
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
 	}
@@ -989,14 +989,14 @@ rt2400pci_init_rxdesc(struct rt2x00_pci 
 
 	memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
 
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		rxd = entry->desc_addr;
+		rxd = entry[counter].desc_addr;
 
 		rt2x00_set_field32(&rxd->word2, RXD_W2_BUFFER_LENGTH,
 			ring->data_size);
 		rt2x00_set_field32(&rxd->word1, RXD_W1_BUFFER_ADDRESS,
-			entry->data_dma);
+			entry[counter].data_dma);
 		rt2x00_set_field32(&rxd->word0, RXD_W0_OWNER_NIC, 1);
 	}
 
@@ -1012,14 +1012,14 @@ rt2400pci_init_txdesc(struct rt2x00_pci 
 
 	memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
 
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		txd = entry->desc_addr;
+		txd = entry[counter].desc_addr;
 
 		rt2x00_set_field32(&txd->word2, TXD_W2_BUFFER_LENGTH,
 			ring->data_size);
 		rt2x00_set_field32(&txd->word1, TXD_W1_BUFFER_ADDRESS,
-			entry->data_dma);
+			entry[counter].data_dma);
 		rt2x00_set_field32(&txd->word0, TXD_W0_VALID, 0);
 		rt2x00_set_field32(&txd->word0, TXD_W0_OWNER_NIC, 0);
 	}
diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500pci.c wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500pci.c
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500pci.c	2006-04-27 21:39:24.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500pci.c	2006-04-27 21:40:06.000000000 +0200
@@ -987,15 +987,15 @@ rt2500pci_alloc_ring(
 	 * Initialize all ring entries to contain valid
 	 * addresses.
 	 */
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		entry->skb = NULL;
-		entry->desc_addr = ring->data_addr
+		entry[counter].skb = NULL;
+		entry[counter].desc_addr = ring->data_addr
 			+ (counter * ring->desc_size);
-		entry->data_addr = ring->data_addr
+		entry[counter].data_addr = ring->data_addr
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
-		entry->data_dma = ring->data_dma
+		entry[counter].data_dma = ring->data_dma
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
 	}
@@ -1025,12 +1025,12 @@ rt2500pci_init_rxdesc(struct rt2x00_pci 
 
 	memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
 
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		rxd = entry->desc_addr;
+		rxd = entry[counter].desc_addr;
 
 		rt2x00_set_field32(&rxd->word1, RXD_W1_BUFFER_ADDRESS,
-			entry->data_dma);
+			entry[counter].data_dma);
 		rt2x00_set_field32(&rxd->word0, RXD_W0_OWNER_NIC, 1);
 	}
 
@@ -1046,12 +1046,12 @@ rt2500pci_init_txdesc(struct rt2x00_pci 
 
 	memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
 
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		txd = entry->desc_addr;
+		txd = entry[counter].desc_addr;
 
 		rt2x00_set_field32(&txd->word1, TXD_W1_BUFFER_ADDRESS,
-			entry->data_dma);
+			entry[counter].data_dma);
 		rt2x00_set_field32(&txd->word0, TXD_W0_VALID, 0);
 		rt2x00_set_field32(&txd->word0, TXD_W0_OWNER_NIC, 0);
 	}
diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500usb.c wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500usb.c
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500usb.c	2006-04-27 21:39:24.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500usb.c	2006-04-27 21:40:06.000000000 +0200
@@ -803,22 +803,22 @@ rt2500usb_alloc_ring(
 	 * addresses.
 	 */
 	status = 0;
+	entry = (struct data_entry*)ring->entry;
 	for (counter = 0; counter < ring->stats.limit; counter++) {
-		entry = ring->entry + (counter * ring->entry_size);
-		entry->ring = ring;
+		entry[counter].ring = ring;
 		if (!status)
-			entry->urb = usb_alloc_urb(0, GFP_KERNEL);
+			entry[counter].urb = usb_alloc_urb(0, GFP_KERNEL);
 		else
-			entry->urb = NULL;
-		if (entry->urb == NULL)
+			entry[counter].urb = NULL;
+		if (entry[counter].urb == NULL)
 			status = -ENOMEM;
-		entry->skb = NULL;
-		entry->desc_addr = ring->data_addr
+		entry[counter].skb = NULL;
+		entry[counter].desc_addr = ring->data_addr
 			+ (counter * ring->desc_size);
-		entry->data_addr = ring->data_addr
+		entry[counter].data_addr = ring->data_addr
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
-		entry->data_dma = ring->data_dma
+		entry[counter].data_dma = ring->data_dma
 			+ (ring->stats.limit * ring->desc_size)
 			+ (counter * ring->data_size);
 	}