Patchwork [v2] mac80211_hwsim: Register and bind to driver

login
register
mail settings
Submitter Martin Pitt
Date April 8, 2013, 9:30 a.m.
Message ID <20130408093001.GE2818@piware.de>
Download mbox | patch
Permalink /patch/234615/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Martin Pitt - April 8, 2013, 9:30 a.m.
Properly register our mac80211_hwsim_driver, attach it to the platform bus.
Bind newly created hwsim devices to that driver, so that our wlan devices get
a proper "driver" sysfs attribute.

This makes mac80211_hwsim interfaces work with NetworkManager.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
---
 drivers/net/wireless/mac80211_hwsim.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
Johannes Berg - April 8, 2013, 2:32 p.m.
On Mon, 2013-04-08 at 11:30 +0200, Martin Pitt wrote:
> Properly register our mac80211_hwsim_driver, attach it to the platform bus.
> Bind newly created hwsim devices to that driver, so that our wlan devices get
> a proper "driver" sysfs attribute.
> 
> This makes mac80211_hwsim interfaces work with NetworkManager.

Applied.

johannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sasha Levin - April 24, 2013, 4:13 a.m.
On 04/08/2013 10:32 AM, Johannes Berg wrote:
> On Mon, 2013-04-08 at 11:30 +0200, Martin Pitt wrote:
>> Properly register our mac80211_hwsim_driver, attach it to the platform bus.
>> Bind newly created hwsim devices to that driver, so that our wlan devices get
>> a proper "driver" sysfs attribute.
>>
>> This makes mac80211_hwsim interfaces work with NetworkManager.
> 
> Applied.

Hi guys,

The registration of the driver here is somewhat odd.

You're trying to register a platform driver, but are not actually creating
a struct platform_driver at any point. This makes registration do the wrong
thing.

Simply booting a kernel with that patch would cause it to blow up because
running to_platform_driver() on the device_driver object would point to garbage:

[   25.349569] BUG: unable to handle kernel NULL pointer dereference at 0000000000000001
[   25.350254] IP: [<ffffffff81f39fa5>] platform_match+0x45/0xc0
[   25.350886] PGD 0
[   25.351141] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
[   25.351775] Dumping ftrace buffer:
[   25.352174]    (ftrace buffer empty)
[   25.352581] Modules linked in:
[   25.352949] CPU: 3 PID: 1 Comm: swapper/0 Tainted: G        W    3.9.0-rc8-next-20130423-sasha-00013-gff425d3-dirty #350
[   25.353905] task: ffff8800b9f08000 ti: ffff8800b9f10000 task.ti: ffff8800b9f10000
[   25.354577] RIP: 0010:[<ffffffff81f39fa5>]  [<ffffffff81f39fa5>] platform_match+0x45/0xc0
[   25.355485] RSP: 0000:ffff8800b9f11c98  EFLAGS: 00010202
[   25.356307] RAX: 000000000000000e RBX: ffff8800b9ad9be8 RCX: 00000000f4b5f4b4
[   25.357184] RDX: ffff8800b9f08000 RSI: 0000000000000001 RDI: 0000000000000282
[   25.357939] RBP: ffff8800b9f11cb8 R08: 0000000000000002 R09: 0000000000000000
[   25.358791] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff86083640
[   25.359134] R13: 0000000000000001 R14: 0000000000000000 R15: ffffffff85f963c0
[   25.359134] FS:  0000000000000000(0000) GS:ffff8800bba00000(0000) knlGS:0000000000000000
[   25.359134] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   25.359134] CR2: 0000000000000001 CR3: 0000000005826000 CR4: 00000000000406e0
[   25.359134] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[   25.359134] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[   25.359134] Stack:
[   25.359134]  ffff8800b9f11cd8 ffff8800b9ad9be8 ffffffff86083640 ffffffff81f37f90
[   25.359134]  ffff8800b9f11ce8 ffffffff81f37fca 0000000000000000 0000000000000000
[   25.359134]  ffffffff86083640 ffffffff81f37f90 ffff8800b9f11d28 ffffffff81f35ca1
[   25.359134] Call Trace:
[   25.359134]  [<ffffffff81f37f90>] ? driver_probe_device+0x340/0x340
[   25.359134]  [<ffffffff81f37fca>] __driver_attach+0x3a/0xb0
[   25.359134]  [<ffffffff81f37f90>] ? driver_probe_device+0x340/0x340
[   25.359134]  [<ffffffff81f35ca1>] bus_for_each_dev+0x61/0xa0
[   25.359134]  [<ffffffff81f37629>] driver_attach+0x19/0x20
[   25.359134]  [<ffffffff81f37198>] bus_add_driver+0x118/0x2a0
[   25.359134]  [<ffffffff8668694e>] ? wil6210_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff81f38778>] driver_register+0xa8/0x170
[   25.359134]  [<ffffffff8668694e>] ? wil6210_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff8668694e>] ? wil6210_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff86686a3e>] init_mac80211_hwsim+0xf0/0xaaa
[   25.359134]  [<ffffffff86686933>] ? ar5523_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff86686933>] ? ar5523_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff8668694e>] ? wil6210_driver_init+0x1b/0x1b
[   25.359134]  [<ffffffff810020f2>] do_one_initcall+0xb2/0x1b0
[   25.359134]  [<ffffffff865f3021>] kernel_init_freeable+0x15d/0x1ef
[   25.359134]  [<ffffffff865f2801>] ? loglevel+0x31/0x31
[   25.359134]  [<ffffffff83f8ebd0>] ? rest_init+0x140/0x140
[   25.359134]  [<ffffffff83f8ebd9>] kernel_init+0x9/0xf0
[   25.359134]  [<ffffffff83fff1fc>] ret_from_fork+0x7c/0xb0
[   25.359134]  [<ffffffff83f8ebd0>] ? rest_init+0x140/0x140
[   25.359134] Code: 48 8b 7e 30 48 89 de e8 5d d7 c5 ff 48 85 c0 75 75 48 8b 73 f0 48 c7 c7 fa a0 20 85 e8 74 01 07 02 4d 8b 6c
24 78 4d 85 ed 74 43 <41> 80 7d 00 00 74 2f 4c 8b 63 f0 4c 89 ee 4c 89 e7 e8 35 1e ae
[   25.359134] RIP  [<ffffffff81f39fa5>] platform_match+0x45/0xc0
[   25.359134]  RSP <ffff8800b9f11c98>
[   25.359134] CR2: 0000000000000001
[   25.386186] ---[ end trace 6293fa4fd2b61873 ]---

I don't have the hardware to test out any changes I do, but I'll send out a patch
tomorrow to try and fix that unless someone beats me to it.


Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 0064d38..0a6fb4a 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -25,6 +25,7 @@ 
 #include <linux/if_arp.h>
 #include <linux/rtnetlink.h>
 #include <linux/etherdevice.h>
+#include <linux/platform_device.h>
 #include <linux/debugfs.h>
 #include <linux/module.h>
 #include <linux/ktime.h>
@@ -1675,6 +1676,7 @@  static void mac80211_hwsim_free(void)
 		debugfs_remove(data->debugfs_ps);
 		debugfs_remove(data->debugfs);
 		ieee80211_unregister_hw(data->hw);
+		device_release_driver(data->dev);
 		device_unregister(data->dev);
 		ieee80211_free_hw(data->hw);
 	}
@@ -1683,7 +1685,9 @@  static void mac80211_hwsim_free(void)
 
 
 static struct device_driver mac80211_hwsim_driver = {
-	.name = "mac80211_hwsim"
+	.name = "mac80211_hwsim",
+	.bus = &platform_bus_type,
+	.owner = THIS_MODULE,
 };
 
 static const struct net_device_ops hwsim_netdev_ops = {
@@ -2179,6 +2183,8 @@  static int __init init_mac80211_hwsim(void)
 	if (IS_ERR(hwsim_class))
 		return PTR_ERR(hwsim_class);
 
+	driver_register(&mac80211_hwsim_driver);
+
 	memset(addr, 0, ETH_ALEN);
 	addr[0] = 0x02;
 
@@ -2205,6 +2211,14 @@  static int __init init_mac80211_hwsim(void)
 			goto failed_drvdata;
 		}
 		data->dev->driver = &mac80211_hwsim_driver;
+		err = device_bind_driver(data->dev);
+		if (err != 0) {
+			printk(KERN_DEBUG
+			       "mac80211_hwsim: device_bind_driver "
+			       "failed (%d)\n", err);
+			goto failed_hw;
+		}
+
 		skb_queue_head_init(&data->pending);
 
 		SET_IEEE80211_DEV(hw, data->dev);
@@ -2506,6 +2520,7 @@  failed_drvdata:
 	ieee80211_free_hw(hw);
 failed:
 	mac80211_hwsim_free();
+	driver_unregister(&mac80211_hwsim_driver);
 	return err;
 }
 module_init(init_mac80211_hwsim);
@@ -2518,5 +2533,6 @@  static void __exit exit_mac80211_hwsim(void)
 
 	mac80211_hwsim_free();
 	unregister_netdev(hwsim_mon);
+	driver_unregister(&mac80211_hwsim_driver);
 }
 module_exit(exit_mac80211_hwsim);