Subject: [PATCH 14/32] rt2x00: Allocate eeprom memory

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

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

Make the EEPROM array in rt2x00_pci and rt2x00_usb a pointer,
and allocate the memory seperately. This is needed for make
the structures more generic for all rt2x00 pci or usb modules.

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:45:08.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2400pci.c	2006-04-27 21:47:22.000000000 +0200
@@ -1831,7 +1831,6 @@ rt2400pci_init_eeprom(struct rt2x00_pci 
 	u32			reg;
 	u16			value;
 	u16			eeprom;
-	int			counter;
 
 	/*
 	 * 1 - Detect EEPROM width.
@@ -1886,8 +1885,12 @@ rt2400pci_init_eeprom(struct rt2x00_pci 
 	/*
 	 * 7 - Read BBP data from EEPROM and store in private structure.
 	 */
+	rt2x00pci->eeprom = kzalloc(EEPROM_BBP_SIZE * sizeof(u16), GFP_KERNEL);
+	if (!rt2x00pci->eeprom) 
+		return -ENOMEM;
+
 	rt2x00_eeprom_multiread(rt2x00pci, EEPROM_BBP_START,
-		&rt2x00pci->eeprom, EEPROM_BBP_SIZE * sizeof(u16));
+		rt2x00pci->eeprom, EEPROM_BBP_SIZE * sizeof(u16));
 
 	return 0;
 }
@@ -2197,6 +2200,8 @@ rt2400pci_uninitialize(struct net_device
 	del_timer_sync(&rt2x00pci->poll_timer);
 #endif /* CONFIG_RT2400PCI_BUTTON */
 
+	kfree(rt2x00pci->eeprom);
+
 	if (likely(rt2x00pci->csr_addr)) {
 		iounmap(rt2x00pci->csr_addr);
 		rt2x00pci->csr_addr = NULL;
diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2400pci.h wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2400pci.h
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2400pci.h	2006-04-27 21:45:08.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2400pci.h	2006-04-27 21:47:22.000000000 +0200
@@ -945,7 +945,7 @@ struct rt2x00_pci{
 	/*
 	 * EEPROM BBP data.
 	 */
-	u16					eeprom[EEPROM_BBP_SIZE];
+	u16					*eeprom;
 
 	/*
 	 * Low level statistics which will have
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:45:08.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500pci.c	2006-04-27 21:47:22.000000000 +0200
@@ -1939,7 +1939,6 @@ rt2500pci_init_eeprom(struct rt2x00_pci 
 	u32			reg;
 	u16			value;
 	u16			eeprom;
-	int			counter;
 
 	/*
 	 * 1 - Detect EEPROM width.
@@ -1998,8 +1997,12 @@ rt2500pci_init_eeprom(struct rt2x00_pci 
 	/*
 	 * 7 - Read BBP data from EEPROM and store in private structure.
 	 */
+	rt2x00pci->eeprom = kzalloc(EEPROM_BBP_SIZE * sizeof(u16), GFP_KERNEL);
+	if (!rt2x00pci->eeprom)
+		return -ENOMEM;
+
 	rt2x00_eeprom_multiread(rt2x00pci, EEPROM_BBP_START,
-		&rt2x00pci->eeprom, EEPROM_BBP_SIZE * sizeof(u16));
+		rt2x00pci->eeprom, EEPROM_BBP_SIZE * sizeof(u16));
 
 	return 0;
 }
@@ -2495,6 +2498,8 @@ rt2500pci_uninitialize(struct net_device
 	del_timer_sync(&rt2x00pci->poll_timer);
 #endif /* CONFIG_RT2500PCI_BUTTON */
 
+	kfree(rt2x00pci->eeprom);
+
 	if (likely(rt2x00pci->csr_addr)) {
 		iounmap(rt2x00pci->csr_addr);
 		rt2x00pci->csr_addr = NULL;
diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500pci.h wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500pci.h
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500pci.h	2006-04-27 21:43:27.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500pci.h	2006-04-27 21:47:22.000000000 +0200
@@ -1215,7 +1215,7 @@ struct rt2x00_pci{
 	/*
 	 * EEPROM BBP data.
 	 */
-	u16					eeprom[EEPROM_BBP_SIZE];
+	u16					*eeprom;
 
 	/*
 	 * Low level statistics which will have
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:45:08.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500usb.c	2006-04-27 21:47:22.000000000 +0200
@@ -1657,9 +1657,12 @@ rt2500usb_init_eeprom(struct rt2x00_usb 
 	/*
 	 * 5 - Read BBP data from EEPROM and store in private structure.
 	 */
-	memset(&rt2x00usb->eeprom, 0x00, sizeof(rt2x00usb->eeprom));
+	rt2x00usb->eeprom = kzalloc(EEPROM_BBP_SIZE * sizeof(u16), GFP_KERNEL);
+	if (!rt2x00usb->eeprom) 
+		return -ENOMEM;
+
 	rt2x00_eeprom_multiread(rt2x00usb, EEPROM_BBP_START,
-		&rt2x00usb->eeprom[0], EEPROM_BBP_SIZE);
+		rt2x00usb->eeprom, EEPROM_BBP_SIZE * sizeof(u16));
 
 	return 0;
 }
@@ -2116,6 +2119,8 @@ rt2500usb_uninitialize(struct net_device
 {
 	struct rt2x00_usb	*rt2x00usb = ieee80211_dev_hw_data(net_dev);
 
+	kfree(rt2x00usb->eeprom);
+
 	if (rt2x00usb->scan) {
 		rt2x00usb->scan->cancelled = 1;
 		complete_all(&rt2x00usb->scan->completion);
@@ -2129,7 +2134,7 @@ rt2500usb_uninitialize(struct net_device
 
 		kfree(rt2x00usb->hw.modes);
 		rt2x00usb->hw.modes = NULL;
-	}
+}
 
 /*
  * USB driver handlers.
diff -uprN wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500usb.h wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500usb.h
--- wireless-dev-rt2x00/drivers/net/wireless/d80211/rt2x00/rt2500usb.h	2006-04-27 21:43:27.000000000 +0200
+++ wireless-dev-rt2x00-patch/drivers/net/wireless/d80211/rt2x00/rt2500usb.h	2006-04-27 21:47:22.000000000 +0200
@@ -727,7 +727,7 @@ struct rt2x00_usb{
 	/*
 	 * EEPROM BBP data.
 	 */
-	u16					eeprom[EEPROM_BBP_SIZE];
+	u16					*eeprom;
 
 	/*
 	 * Low level statistics which will have