Skip to content

Commit 9ea9277

Browse files
martinpittjmberg-intel
authored andcommitted
mac80211_hwsim: Register and bind to driver
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> [fix an old and a new message to not be line-broken, also fix the driver_register error path] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent ddc4db2 commit 9ea9277

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

drivers/net/wireless/mac80211_hwsim.c

+26-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/if_arp.h>
2626
#include <linux/rtnetlink.h>
2727
#include <linux/etherdevice.h>
28+
#include <linux/platform_device.h>
2829
#include <linux/debugfs.h>
2930
#include <linux/module.h>
3031
#include <linux/ktime.h>
@@ -1687,6 +1688,7 @@ static void mac80211_hwsim_free(void)
16871688
debugfs_remove(data->debugfs_ps);
16881689
debugfs_remove(data->debugfs);
16891690
ieee80211_unregister_hw(data->hw);
1691+
device_release_driver(data->dev);
16901692
device_unregister(data->dev);
16911693
ieee80211_free_hw(data->hw);
16921694
}
@@ -1695,7 +1697,9 @@ static void mac80211_hwsim_free(void)
16951697

16961698

16971699
static struct device_driver mac80211_hwsim_driver = {
1698-
.name = "mac80211_hwsim"
1700+
.name = "mac80211_hwsim",
1701+
.bus = &platform_bus_type,
1702+
.owner = THIS_MODULE,
16991703
};
17001704

17011705
static const struct net_device_ops hwsim_netdev_ops = {
@@ -2187,9 +2191,15 @@ static int __init init_mac80211_hwsim(void)
21872191
spin_lock_init(&hwsim_radio_lock);
21882192
INIT_LIST_HEAD(&hwsim_radios);
21892193

2194+
err = driver_register(&mac80211_hwsim_driver);
2195+
if (err)
2196+
return err;
2197+
21902198
hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
2191-
if (IS_ERR(hwsim_class))
2192-
return PTR_ERR(hwsim_class);
2199+
if (IS_ERR(hwsim_class)) {
2200+
err = PTR_ERR(hwsim_class);
2201+
goto failed_unregister_driver;
2202+
}
21932203

21942204
memset(addr, 0, ETH_ALEN);
21952205
addr[0] = 0x02;
@@ -2211,12 +2221,20 @@ static int __init init_mac80211_hwsim(void)
22112221
"hwsim%d", i);
22122222
if (IS_ERR(data->dev)) {
22132223
printk(KERN_DEBUG
2214-
"mac80211_hwsim: device_create "
2215-
"failed (%ld)\n", PTR_ERR(data->dev));
2224+
"mac80211_hwsim: device_create failed (%ld)\n",
2225+
PTR_ERR(data->dev));
22162226
err = -ENOMEM;
22172227
goto failed_drvdata;
22182228
}
22192229
data->dev->driver = &mac80211_hwsim_driver;
2230+
err = device_bind_driver(data->dev);
2231+
if (err != 0) {
2232+
printk(KERN_DEBUG
2233+
"mac80211_hwsim: device_bind_driver failed (%d)\n",
2234+
err);
2235+
goto failed_hw;
2236+
}
2237+
22202238
skb_queue_head_init(&data->pending);
22212239

22222240
SET_IEEE80211_DEV(hw, data->dev);
@@ -2515,6 +2533,8 @@ static int __init init_mac80211_hwsim(void)
25152533
ieee80211_free_hw(hw);
25162534
failed:
25172535
mac80211_hwsim_free();
2536+
failed_unregister_driver:
2537+
driver_unregister(&mac80211_hwsim_driver);
25182538
return err;
25192539
}
25202540
module_init(init_mac80211_hwsim);
@@ -2527,5 +2547,6 @@ static void __exit exit_mac80211_hwsim(void)
25272547

25282548
mac80211_hwsim_free();
25292549
unregister_netdev(hwsim_mon);
2550+
driver_unregister(&mac80211_hwsim_driver);
25302551
}
25312552
module_exit(exit_mac80211_hwsim);

0 commit comments

Comments
 (0)