[OpenWrt-Devel] [PATCH] mac80211: fix removing rt2x00 module

Kristian Evensen kristian.evensen at gmail.com
Thu Jan 31 09:54:51 EST 2019


When EEPROM is loaded from mtd, removing the rt2x00 module triggers a
kernel oops. The reason for the oops is that release_firmware() is
always called from rt2x00lib_free_eeprom_file(). release_firmware()
frees the memory allocated by request_firmware(), which is called when
EEPROM is loaded from file. However, when loaded from mtd, no memory is
allocated for the EEPROM (and the firwmware subsystem is not used
either).

The best indication I could think of for if EEPROM is loaded from file
or mtd, is to check for the "ralink,mtd-eeprom" property. At least on
the devices I have access to and where this property is set, EEPROM is
only available from mtd.

Signed-off-by: Kristian Evensen <kristian.evensen at gmail.com>
---
 ...om-on-SoC-from-a-mtd-device-defines-.patch | 34 ++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/package/kernel/mac80211/patches/rt2x00/604-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch b/package/kernel/mac80211/patches/rt2x00/604-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch
index a98b49c541..0362dd10f5 100644
--- a/package/kernel/mac80211/patches/rt2x00/604-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch
+++ b/package/kernel/mac80211/patches/rt2x00/604-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch
@@ -1,4 +1,4 @@
-From 339fe73f340161a624cc08e738d2244814852c3e Mon Sep 17 00:00:00 2001
+From b5e9327001bf4a859d2645442640c5f8ab77be07 Mon Sep 17 00:00:00 2001
 From: John Crispin <blogic at openwrt.org>
 Date: Sun, 17 Mar 2013 00:55:04 +0100
 Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
@@ -6,10 +6,12 @@ Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
 
 Signed-off-by: John Crispin <blogic at openwrt.org>
 ---
- drivers/net/wireless/ralink/rt2x00/Kconfig        |  1 +
- drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c | 65 +++++++++++++++++++++++
- 2 files changed, 66 insertions(+)
+ drivers/net/wireless/ralink/rt2x00/Kconfig    |  1 +
+ .../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 75 +++++++++++++++++++
+ 2 files changed, 76 insertions(+)
 
+diff --git a/drivers/net/wireless/ralink/rt2x00/Kconfig b/drivers/net/wireless/ralink/rt2x00/Kconfig
+index 39fdaaf..2e836d8 100644
 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
 @@ -219,6 +219,7 @@ config RT2800SOC
@@ -20,6 +22,8 @@ Signed-off-by: John Crispin <blogic at openwrt.org>
  	---help---
  	  This adds support for Ralink WiSoC devices.
  	  Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
+diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
+index 1a30f9c..404a1f7 100644
 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
 @@ -26,11 +26,73 @@
@@ -96,7 +100,7 @@ Signed-off-by: John Crispin <blogic at openwrt.org>
  static const char *
  rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
  {
-@@ -58,6 +120,9 @@ static int rt2x00lib_request_eeprom_file
+@@ -58,6 +120,9 @@ static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
  	const char *ee_name;
  	int retval;
  
@@ -106,3 +110,23 @@ Signed-off-by: John Crispin <blogic at openwrt.org>
  	ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
  	if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
  		rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");
+@@ -111,6 +176,16 @@ int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
+ 
+ void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
+ {
++#ifdef CONFIG_OF
++	struct device_node *np = rt2x00dev->dev->of_node;
++	int size;
++
++	if (np && of_get_property(np, "ralink,mtd-eeprom", &size)) {
++		rt2x00dev->eeprom_file = NULL;
++		return;
++	}
++#endif
++
+ 	release_firmware(rt2x00dev->eeprom_file);
+ 	rt2x00dev->eeprom_file = NULL;
+ }
+-- 
+2.19.1
+
-- 
2.19.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list