core.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2006 - 2007 Ivo van Doorn
  4. * Copyright (C) 2007 Dmitry Torokhov
  5. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/capability.h>
  12. #include <linux/list.h>
  13. #include <linux/mutex.h>
  14. #include <linux/rfkill.h>
  15. #include <linux/sched.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/device.h>
  18. #include <linux/miscdevice.h>
  19. #include <linux/wait.h>
  20. #include <linux/poll.h>
  21. #include <linux/fs.h>
  22. #include <linux/slab.h>
  23. #include "rfkill.h"
  24. #define POLL_INTERVAL (5 * HZ)
  25. #define RFKILL_BLOCK_HW BIT(0)
  26. #define RFKILL_BLOCK_SW BIT(1)
  27. #define RFKILL_BLOCK_SW_PREV BIT(2)
  28. #define RFKILL_BLOCK_ANY (RFKILL_BLOCK_HW |\
  29. RFKILL_BLOCK_SW |\
  30. RFKILL_BLOCK_SW_PREV)
  31. #define RFKILL_BLOCK_SW_SETCALL BIT(31)
  32. struct rfkill {
  33. spinlock_t lock;
  34. enum rfkill_type type;
  35. unsigned long state;
  36. u32 idx;
  37. bool registered;
  38. bool persistent;
  39. bool polling_paused;
  40. bool suspended;
  41. const struct rfkill_ops *ops;
  42. void *data;
  43. #ifdef CONFIG_RFKILL_LEDS
  44. struct led_trigger led_trigger;
  45. const char *ledtrigname;
  46. #endif
  47. struct device dev;
  48. struct list_head node;
  49. struct delayed_work poll_work;
  50. struct work_struct uevent_work;
  51. struct work_struct sync_work;
  52. char name[];
  53. };
  54. #define to_rfkill(d) container_of(d, struct rfkill, dev)
  55. struct rfkill_int_event {
  56. struct list_head list;
  57. struct rfkill_event ev;
  58. };
  59. struct rfkill_data {
  60. struct list_head list;
  61. struct list_head events;
  62. struct mutex mtx;
  63. wait_queue_head_t read_wait;
  64. bool input_handler;
  65. };
  66. MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
  67. MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
  68. MODULE_DESCRIPTION("RF switch support");
  69. MODULE_LICENSE("GPL");
  70. /*
  71. * The locking here should be made much smarter, we currently have
  72. * a bit of a stupid situation because drivers might want to register
  73. * the rfkill struct under their own lock, and take this lock during
  74. * rfkill method calls -- which will cause an AB-BA deadlock situation.
  75. *
  76. * To fix that, we need to rework this code here to be mostly lock-free
  77. * and only use the mutex for list manipulations, not to protect the
  78. * various other global variables. Then we can avoid holding the mutex
  79. * around driver operations, and all is happy.
  80. */
  81. static LIST_HEAD(rfkill_list); /* list of registered rf switches */
  82. static DEFINE_MUTEX(rfkill_global_mutex);
  83. static LIST_HEAD(rfkill_fds); /* list of open fds of /dev/rfkill */
  84. static unsigned int rfkill_default_state = 1;
  85. module_param_named(default_state, rfkill_default_state, uint, 0444);
  86. MODULE_PARM_DESC(default_state,
  87. "Default initial state for all radio types, 0 = radio off");
  88. static struct {
  89. bool cur, sav;
  90. } rfkill_global_states[NUM_RFKILL_TYPES];
  91. static bool rfkill_epo_lock_active;
  92. #ifdef CONFIG_RFKILL_LEDS
  93. static void rfkill_led_trigger_event(struct rfkill *rfkill)
  94. {
  95. struct led_trigger *trigger;
  96. if (!rfkill->registered)
  97. return;
  98. trigger = &rfkill->led_trigger;
  99. if (rfkill->state & RFKILL_BLOCK_ANY)
  100. led_trigger_event(trigger, LED_OFF);
  101. else
  102. led_trigger_event(trigger, LED_FULL);
  103. }
  104. static int rfkill_led_trigger_activate(struct led_classdev *led)
  105. {
  106. struct rfkill *rfkill;
  107. rfkill = container_of(led->trigger, struct rfkill, led_trigger);
  108. rfkill_led_trigger_event(rfkill);
  109. return 0;
  110. }
  111. const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
  112. {
  113. return rfkill->led_trigger.name;
  114. }
  115. EXPORT_SYMBOL(rfkill_get_led_trigger_name);
  116. void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
  117. {
  118. BUG_ON(!rfkill);
  119. rfkill->ledtrigname = name;
  120. }
  121. EXPORT_SYMBOL(rfkill_set_led_trigger_name);
  122. static int rfkill_led_trigger_register(struct rfkill *rfkill)
  123. {
  124. rfkill->led_trigger.name = rfkill->ledtrigname
  125. ? : dev_name(&rfkill->dev);
  126. rfkill->led_trigger.activate = rfkill_led_trigger_activate;
  127. return led_trigger_register(&rfkill->led_trigger);
  128. }
  129. static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
  130. {
  131. led_trigger_unregister(&rfkill->led_trigger);
  132. }
  133. static struct led_trigger rfkill_any_led_trigger;
  134. static struct led_trigger rfkill_none_led_trigger;
  135. static struct work_struct rfkill_global_led_trigger_work;
  136. static void rfkill_global_led_trigger_worker(struct work_struct *work)
  137. {
  138. enum led_brightness brightness = LED_OFF;
  139. struct rfkill *rfkill;
  140. mutex_lock(&rfkill_global_mutex);
  141. list_for_each_entry(rfkill, &rfkill_list, node) {
  142. if (!(rfkill->state & RFKILL_BLOCK_ANY)) {
  143. brightness = LED_FULL;
  144. break;
  145. }
  146. }
  147. mutex_unlock(&rfkill_global_mutex);
  148. led_trigger_event(&rfkill_any_led_trigger, brightness);
  149. led_trigger_event(&rfkill_none_led_trigger,
  150. brightness == LED_OFF ? LED_FULL : LED_OFF);
  151. }
  152. static void rfkill_global_led_trigger_event(void)
  153. {
  154. schedule_work(&rfkill_global_led_trigger_work);
  155. }
  156. static int rfkill_global_led_trigger_register(void)
  157. {
  158. int ret;
  159. INIT_WORK(&rfkill_global_led_trigger_work,
  160. rfkill_global_led_trigger_worker);
  161. rfkill_any_led_trigger.name = "rfkill-any";
  162. ret = led_trigger_register(&rfkill_any_led_trigger);
  163. if (ret)
  164. return ret;
  165. rfkill_none_led_trigger.name = "rfkill-none";
  166. ret = led_trigger_register(&rfkill_none_led_trigger);
  167. if (ret)
  168. led_trigger_unregister(&rfkill_any_led_trigger);
  169. else
  170. /* Delay activation until all global triggers are registered */
  171. rfkill_global_led_trigger_event();
  172. return ret;
  173. }
  174. static void rfkill_global_led_trigger_unregister(void)
  175. {
  176. led_trigger_unregister(&rfkill_none_led_trigger);
  177. led_trigger_unregister(&rfkill_any_led_trigger);
  178. cancel_work_sync(&rfkill_global_led_trigger_work);
  179. }
  180. #else
  181. static void rfkill_led_trigger_event(struct rfkill *rfkill)
  182. {
  183. }
  184. static inline int rfkill_led_trigger_register(struct rfkill *rfkill)
  185. {
  186. return 0;
  187. }
  188. static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill)
  189. {
  190. }
  191. static void rfkill_global_led_trigger_event(void)
  192. {
  193. }
  194. static int rfkill_global_led_trigger_register(void)
  195. {
  196. return 0;
  197. }
  198. static void rfkill_global_led_trigger_unregister(void)
  199. {
  200. }
  201. #endif /* CONFIG_RFKILL_LEDS */
  202. static void rfkill_fill_event(struct rfkill_event *ev, struct rfkill *rfkill,
  203. enum rfkill_operation op)
  204. {
  205. unsigned long flags;
  206. ev->idx = rfkill->idx;
  207. ev->type = rfkill->type;
  208. ev->op = op;
  209. spin_lock_irqsave(&rfkill->lock, flags);
  210. ev->hard = !!(rfkill->state & RFKILL_BLOCK_HW);
  211. ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW |
  212. RFKILL_BLOCK_SW_PREV));
  213. spin_unlock_irqrestore(&rfkill->lock, flags);
  214. }
  215. static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op)
  216. {
  217. struct rfkill_data *data;
  218. struct rfkill_int_event *ev;
  219. list_for_each_entry(data, &rfkill_fds, list) {
  220. ev = kzalloc(sizeof(*ev), GFP_KERNEL);
  221. if (!ev)
  222. continue;
  223. rfkill_fill_event(&ev->ev, rfkill, op);
  224. mutex_lock(&data->mtx);
  225. list_add_tail(&ev->list, &data->events);
  226. mutex_unlock(&data->mtx);
  227. wake_up_interruptible(&data->read_wait);
  228. }
  229. }
  230. static void rfkill_event(struct rfkill *rfkill)
  231. {
  232. if (!rfkill->registered)
  233. return;
  234. kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
  235. /* also send event to /dev/rfkill */
  236. rfkill_send_events(rfkill, RFKILL_OP_CHANGE);
  237. }
  238. /**
  239. * rfkill_set_block - wrapper for set_block method
  240. *
  241. * @rfkill: the rfkill struct to use
  242. * @blocked: the new software state
  243. *
  244. * Calls the set_block method (when applicable) and handles notifications
  245. * etc. as well.
  246. */
  247. static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
  248. {
  249. unsigned long flags;
  250. bool prev, curr;
  251. int err;
  252. if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
  253. return;
  254. /*
  255. * Some platforms (...!) generate input events which affect the
  256. * _hard_ kill state -- whenever something tries to change the
  257. * current software state query the hardware state too.
  258. */
  259. if (rfkill->ops->query)
  260. rfkill->ops->query(rfkill, rfkill->data);
  261. spin_lock_irqsave(&rfkill->lock, flags);
  262. prev = rfkill->state & RFKILL_BLOCK_SW;
  263. if (prev)
  264. rfkill->state |= RFKILL_BLOCK_SW_PREV;
  265. else
  266. rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
  267. if (blocked)
  268. rfkill->state |= RFKILL_BLOCK_SW;
  269. else
  270. rfkill->state &= ~RFKILL_BLOCK_SW;
  271. rfkill->state |= RFKILL_BLOCK_SW_SETCALL;
  272. spin_unlock_irqrestore(&rfkill->lock, flags);
  273. err = rfkill->ops->set_block(rfkill->data, blocked);
  274. spin_lock_irqsave(&rfkill->lock, flags);
  275. if (err) {
  276. /*
  277. * Failed -- reset status to _PREV, which may be different
  278. * from what we have set _PREV to earlier in this function
  279. * if rfkill_set_sw_state was invoked.
  280. */
  281. if (rfkill->state & RFKILL_BLOCK_SW_PREV)
  282. rfkill->state |= RFKILL_BLOCK_SW;
  283. else
  284. rfkill->state &= ~RFKILL_BLOCK_SW;
  285. }
  286. rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL;
  287. rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
  288. curr = rfkill->state & RFKILL_BLOCK_SW;
  289. spin_unlock_irqrestore(&rfkill->lock, flags);
  290. rfkill_led_trigger_event(rfkill);
  291. rfkill_global_led_trigger_event();
  292. if (prev != curr)
  293. rfkill_event(rfkill);
  294. }
  295. static void rfkill_update_global_state(enum rfkill_type type, bool blocked)
  296. {
  297. int i;
  298. if (type != RFKILL_TYPE_ALL) {
  299. rfkill_global_states[type].cur = blocked;
  300. return;
  301. }
  302. for (i = 0; i < NUM_RFKILL_TYPES; i++)
  303. rfkill_global_states[i].cur = blocked;
  304. }
  305. #ifdef CONFIG_RFKILL_INPUT
  306. static atomic_t rfkill_input_disabled = ATOMIC_INIT(0);
  307. /**
  308. * __rfkill_switch_all - Toggle state of all switches of given type
  309. * @type: type of interfaces to be affected
  310. * @blocked: the new state
  311. *
  312. * This function sets the state of all switches of given type,
  313. * unless a specific switch is suspended.
  314. *
  315. * Caller must have acquired rfkill_global_mutex.
  316. */
  317. static void __rfkill_switch_all(const enum rfkill_type type, bool blocked)
  318. {
  319. struct rfkill *rfkill;
  320. rfkill_update_global_state(type, blocked);
  321. list_for_each_entry(rfkill, &rfkill_list, node) {
  322. if (rfkill->type != type && type != RFKILL_TYPE_ALL)
  323. continue;
  324. rfkill_set_block(rfkill, blocked);
  325. }
  326. }
  327. /**
  328. * rfkill_switch_all - Toggle state of all switches of given type
  329. * @type: type of interfaces to be affected
  330. * @blocked: the new state
  331. *
  332. * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state).
  333. * Please refer to __rfkill_switch_all() for details.
  334. *
  335. * Does nothing if the EPO lock is active.
  336. */
  337. void rfkill_switch_all(enum rfkill_type type, bool blocked)
  338. {
  339. if (atomic_read(&rfkill_input_disabled))
  340. return;
  341. mutex_lock(&rfkill_global_mutex);
  342. if (!rfkill_epo_lock_active)
  343. __rfkill_switch_all(type, blocked);
  344. mutex_unlock(&rfkill_global_mutex);
  345. }
  346. /**
  347. * rfkill_epo - emergency power off all transmitters
  348. *
  349. * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
  350. * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
  351. *
  352. * The global state before the EPO is saved and can be restored later
  353. * using rfkill_restore_states().
  354. */
  355. void rfkill_epo(void)
  356. {
  357. struct rfkill *rfkill;
  358. int i;
  359. if (atomic_read(&rfkill_input_disabled))
  360. return;
  361. mutex_lock(&rfkill_global_mutex);
  362. rfkill_epo_lock_active = true;
  363. list_for_each_entry(rfkill, &rfkill_list, node)
  364. rfkill_set_block(rfkill, true);
  365. for (i = 0; i < NUM_RFKILL_TYPES; i++) {
  366. rfkill_global_states[i].sav = rfkill_global_states[i].cur;
  367. rfkill_global_states[i].cur = true;
  368. }
  369. mutex_unlock(&rfkill_global_mutex);
  370. }
  371. /**
  372. * rfkill_restore_states - restore global states
  373. *
  374. * Restore (and sync switches to) the global state from the
  375. * states in rfkill_default_states. This can undo the effects of
  376. * a call to rfkill_epo().
  377. */
  378. void rfkill_restore_states(void)
  379. {
  380. int i;
  381. if (atomic_read(&rfkill_input_disabled))
  382. return;
  383. mutex_lock(&rfkill_global_mutex);
  384. rfkill_epo_lock_active = false;
  385. for (i = 0; i < NUM_RFKILL_TYPES; i++)
  386. __rfkill_switch_all(i, rfkill_global_states[i].sav);
  387. mutex_unlock(&rfkill_global_mutex);
  388. }
  389. /**
  390. * rfkill_remove_epo_lock - unlock state changes
  391. *
  392. * Used by rfkill-input manually unlock state changes, when
  393. * the EPO switch is deactivated.
  394. */
  395. void rfkill_remove_epo_lock(void)
  396. {
  397. if (atomic_read(&rfkill_input_disabled))
  398. return;
  399. mutex_lock(&rfkill_global_mutex);
  400. rfkill_epo_lock_active = false;
  401. mutex_unlock(&rfkill_global_mutex);
  402. }
  403. /**
  404. * rfkill_is_epo_lock_active - returns true EPO is active
  405. *
  406. * Returns 0 (false) if there is NOT an active EPO condition,
  407. * and 1 (true) if there is an active EPO condition, which
  408. * locks all radios in one of the BLOCKED states.
  409. *
  410. * Can be called in atomic context.
  411. */
  412. bool rfkill_is_epo_lock_active(void)
  413. {
  414. return rfkill_epo_lock_active;
  415. }
  416. /**
  417. * rfkill_get_global_sw_state - returns global state for a type
  418. * @type: the type to get the global state of
  419. *
  420. * Returns the current global state for a given wireless
  421. * device type.
  422. */
  423. bool rfkill_get_global_sw_state(const enum rfkill_type type)
  424. {
  425. return rfkill_global_states[type].cur;
  426. }
  427. #endif
  428. bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
  429. {
  430. unsigned long flags;
  431. bool ret, prev;
  432. BUG_ON(!rfkill);
  433. spin_lock_irqsave(&rfkill->lock, flags);
  434. prev = !!(rfkill->state & RFKILL_BLOCK_HW);
  435. if (blocked)
  436. rfkill->state |= RFKILL_BLOCK_HW;
  437. else
  438. rfkill->state &= ~RFKILL_BLOCK_HW;
  439. ret = !!(rfkill->state & RFKILL_BLOCK_ANY);
  440. spin_unlock_irqrestore(&rfkill->lock, flags);
  441. rfkill_led_trigger_event(rfkill);
  442. rfkill_global_led_trigger_event();
  443. if (rfkill->registered && prev != blocked)
  444. schedule_work(&rfkill->uevent_work);
  445. return ret;
  446. }
  447. EXPORT_SYMBOL(rfkill_set_hw_state);
  448. static void __rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  449. {
  450. u32 bit = RFKILL_BLOCK_SW;
  451. /* if in a ops->set_block right now, use other bit */
  452. if (rfkill->state & RFKILL_BLOCK_SW_SETCALL)
  453. bit = RFKILL_BLOCK_SW_PREV;
  454. if (blocked)
  455. rfkill->state |= bit;
  456. else
  457. rfkill->state &= ~bit;
  458. }
  459. bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  460. {
  461. unsigned long flags;
  462. bool prev, hwblock;
  463. BUG_ON(!rfkill);
  464. spin_lock_irqsave(&rfkill->lock, flags);
  465. prev = !!(rfkill->state & RFKILL_BLOCK_SW);
  466. __rfkill_set_sw_state(rfkill, blocked);
  467. hwblock = !!(rfkill->state & RFKILL_BLOCK_HW);
  468. blocked = blocked || hwblock;
  469. spin_unlock_irqrestore(&rfkill->lock, flags);
  470. if (!rfkill->registered)
  471. return blocked;
  472. if (prev != blocked && !hwblock)
  473. schedule_work(&rfkill->uevent_work);
  474. rfkill_led_trigger_event(rfkill);
  475. rfkill_global_led_trigger_event();
  476. return blocked;
  477. }
  478. EXPORT_SYMBOL(rfkill_set_sw_state);
  479. void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
  480. {
  481. unsigned long flags;
  482. BUG_ON(!rfkill);
  483. BUG_ON(rfkill->registered);
  484. spin_lock_irqsave(&rfkill->lock, flags);
  485. __rfkill_set_sw_state(rfkill, blocked);
  486. rfkill->persistent = true;
  487. spin_unlock_irqrestore(&rfkill->lock, flags);
  488. }
  489. EXPORT_SYMBOL(rfkill_init_sw_state);
  490. void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
  491. {
  492. unsigned long flags;
  493. bool swprev, hwprev;
  494. BUG_ON(!rfkill);
  495. spin_lock_irqsave(&rfkill->lock, flags);
  496. /*
  497. * No need to care about prev/setblock ... this is for uevent only
  498. * and that will get triggered by rfkill_set_block anyway.
  499. */
  500. swprev = !!(rfkill->state & RFKILL_BLOCK_SW);
  501. hwprev = !!(rfkill->state & RFKILL_BLOCK_HW);
  502. __rfkill_set_sw_state(rfkill, sw);
  503. if (hw)
  504. rfkill->state |= RFKILL_BLOCK_HW;
  505. else
  506. rfkill->state &= ~RFKILL_BLOCK_HW;
  507. spin_unlock_irqrestore(&rfkill->lock, flags);
  508. if (!rfkill->registered) {
  509. rfkill->persistent = true;
  510. } else {
  511. if (swprev != sw || hwprev != hw)
  512. schedule_work(&rfkill->uevent_work);
  513. rfkill_led_trigger_event(rfkill);
  514. rfkill_global_led_trigger_event();
  515. }
  516. }
  517. EXPORT_SYMBOL(rfkill_set_states);
  518. static const char * const rfkill_types[] = {
  519. NULL, /* RFKILL_TYPE_ALL */
  520. "wlan",
  521. "bluetooth",
  522. "ultrawideband",
  523. "wimax",
  524. "wwan",
  525. "gps",
  526. "fm",
  527. "nfc",
  528. };
  529. enum rfkill_type rfkill_find_type(const char *name)
  530. {
  531. int i;
  532. BUILD_BUG_ON(ARRAY_SIZE(rfkill_types) != NUM_RFKILL_TYPES);
  533. if (!name)
  534. return RFKILL_TYPE_ALL;
  535. for (i = 1; i < NUM_RFKILL_TYPES; i++)
  536. if (!strcmp(name, rfkill_types[i]))
  537. return i;
  538. return RFKILL_TYPE_ALL;
  539. }
  540. EXPORT_SYMBOL(rfkill_find_type);
  541. static ssize_t name_show(struct device *dev, struct device_attribute *attr,
  542. char *buf)
  543. {
  544. struct rfkill *rfkill = to_rfkill(dev);
  545. return sprintf(buf, "%s\n", rfkill->name);
  546. }
  547. static DEVICE_ATTR_RO(name);
  548. static ssize_t type_show(struct device *dev, struct device_attribute *attr,
  549. char *buf)
  550. {
  551. struct rfkill *rfkill = to_rfkill(dev);
  552. return sprintf(buf, "%s\n", rfkill_types[rfkill->type]);
  553. }
  554. static DEVICE_ATTR_RO(type);
  555. static ssize_t index_show(struct device *dev, struct device_attribute *attr,
  556. char *buf)
  557. {
  558. struct rfkill *rfkill = to_rfkill(dev);
  559. return sprintf(buf, "%d\n", rfkill->idx);
  560. }
  561. static DEVICE_ATTR_RO(index);
  562. static ssize_t persistent_show(struct device *dev,
  563. struct device_attribute *attr, char *buf)
  564. {
  565. struct rfkill *rfkill = to_rfkill(dev);
  566. return sprintf(buf, "%d\n", rfkill->persistent);
  567. }
  568. static DEVICE_ATTR_RO(persistent);
  569. static ssize_t hard_show(struct device *dev, struct device_attribute *attr,
  570. char *buf)
  571. {
  572. struct rfkill *rfkill = to_rfkill(dev);
  573. return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_HW) ? 1 : 0 );
  574. }
  575. static DEVICE_ATTR_RO(hard);
  576. static ssize_t soft_show(struct device *dev, struct device_attribute *attr,
  577. char *buf)
  578. {
  579. struct rfkill *rfkill = to_rfkill(dev);
  580. return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0 );
  581. }
  582. static ssize_t soft_store(struct device *dev, struct device_attribute *attr,
  583. const char *buf, size_t count)
  584. {
  585. struct rfkill *rfkill = to_rfkill(dev);
  586. unsigned long state;
  587. int err;
  588. if (!capable(CAP_NET_ADMIN))
  589. return -EPERM;
  590. err = kstrtoul(buf, 0, &state);
  591. if (err)
  592. return err;
  593. if (state > 1 )
  594. return -EINVAL;
  595. mutex_lock(&rfkill_global_mutex);
  596. rfkill_set_block(rfkill, state);
  597. mutex_unlock(&rfkill_global_mutex);
  598. return count;
  599. }
  600. static DEVICE_ATTR_RW(soft);
  601. static u8 user_state_from_blocked(unsigned long state)
  602. {
  603. if (state & RFKILL_BLOCK_HW)
  604. return RFKILL_USER_STATE_HARD_BLOCKED;
  605. if (state & RFKILL_BLOCK_SW)
  606. return RFKILL_USER_STATE_SOFT_BLOCKED;
  607. return RFKILL_USER_STATE_UNBLOCKED;
  608. }
  609. static ssize_t state_show(struct device *dev, struct device_attribute *attr,
  610. char *buf)
  611. {
  612. struct rfkill *rfkill = to_rfkill(dev);
  613. return sprintf(buf, "%d\n", user_state_from_blocked(rfkill->state));
  614. }
  615. static ssize_t state_store(struct device *dev, struct device_attribute *attr,
  616. const char *buf, size_t count)
  617. {
  618. struct rfkill *rfkill = to_rfkill(dev);
  619. unsigned long state;
  620. int err;
  621. if (!capable(CAP_NET_ADMIN))
  622. return -EPERM;
  623. err = kstrtoul(buf, 0, &state);
  624. if (err)
  625. return err;
  626. if (state != RFKILL_USER_STATE_SOFT_BLOCKED &&
  627. state != RFKILL_USER_STATE_UNBLOCKED)
  628. return -EINVAL;
  629. mutex_lock(&rfkill_global_mutex);
  630. rfkill_set_block(rfkill, state == RFKILL_USER_STATE_SOFT_BLOCKED);
  631. mutex_unlock(&rfkill_global_mutex);
  632. return count;
  633. }
  634. static DEVICE_ATTR_RW(state);
  635. static struct attribute *rfkill_dev_attrs[] = {
  636. &dev_attr_name.attr,
  637. &dev_attr_type.attr,
  638. &dev_attr_index.attr,
  639. &dev_attr_persistent.attr,
  640. &dev_attr_state.attr,
  641. &dev_attr_soft.attr,
  642. &dev_attr_hard.attr,
  643. NULL,
  644. };
  645. ATTRIBUTE_GROUPS(rfkill_dev);
  646. static void rfkill_release(struct device *dev)
  647. {
  648. struct rfkill *rfkill = to_rfkill(dev);
  649. kfree(rfkill);
  650. }
  651. static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
  652. {
  653. struct rfkill *rfkill = to_rfkill(dev);
  654. unsigned long flags;
  655. u32 state;
  656. int error;
  657. error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
  658. if (error)
  659. return error;
  660. error = add_uevent_var(env, "RFKILL_TYPE=%s",
  661. rfkill_types[rfkill->type]);
  662. if (error)
  663. return error;
  664. spin_lock_irqsave(&rfkill->lock, flags);
  665. state = rfkill->state;
  666. spin_unlock_irqrestore(&rfkill->lock, flags);
  667. error = add_uevent_var(env, "RFKILL_STATE=%d",
  668. user_state_from_blocked(state));
  669. return error;
  670. }
  671. void rfkill_pause_polling(struct rfkill *rfkill)
  672. {
  673. BUG_ON(!rfkill);
  674. if (!rfkill->ops->poll)
  675. return;
  676. rfkill->polling_paused = true;
  677. cancel_delayed_work_sync(&rfkill->poll_work);
  678. }
  679. EXPORT_SYMBOL(rfkill_pause_polling);
  680. void rfkill_resume_polling(struct rfkill *rfkill)
  681. {
  682. BUG_ON(!rfkill);
  683. if (!rfkill->ops->poll)
  684. return;
  685. rfkill->polling_paused = false;
  686. if (rfkill->suspended)
  687. return;
  688. queue_delayed_work(system_power_efficient_wq,
  689. &rfkill->poll_work, 0);
  690. }
  691. EXPORT_SYMBOL(rfkill_resume_polling);
  692. #ifdef CONFIG_PM_SLEEP
  693. static int rfkill_suspend(struct device *dev)
  694. {
  695. struct rfkill *rfkill = to_rfkill(dev);
  696. rfkill->suspended = true;
  697. cancel_delayed_work_sync(&rfkill->poll_work);
  698. return 0;
  699. }
  700. static int rfkill_resume(struct device *dev)
  701. {
  702. struct rfkill *rfkill = to_rfkill(dev);
  703. bool cur;
  704. rfkill->suspended = false;
  705. if (!rfkill->registered)
  706. return 0;
  707. if (!rfkill->persistent) {
  708. cur = !!(rfkill->state & RFKILL_BLOCK_SW);
  709. rfkill_set_block(rfkill, cur);
  710. }
  711. if (rfkill->ops->poll && !rfkill->polling_paused)
  712. queue_delayed_work(system_power_efficient_wq,
  713. &rfkill->poll_work, 0);
  714. return 0;
  715. }
  716. static SIMPLE_DEV_PM_OPS(rfkill_pm_ops, rfkill_suspend, rfkill_resume);
  717. #define RFKILL_PM_OPS (&rfkill_pm_ops)
  718. #else
  719. #define RFKILL_PM_OPS NULL
  720. #endif
  721. static struct class rfkill_class = {
  722. .name = "rfkill",
  723. .dev_release = rfkill_release,
  724. .dev_groups = rfkill_dev_groups,
  725. .dev_uevent = rfkill_dev_uevent,
  726. .pm = RFKILL_PM_OPS,
  727. };
  728. bool rfkill_blocked(struct rfkill *rfkill)
  729. {
  730. unsigned long flags;
  731. u32 state;
  732. spin_lock_irqsave(&rfkill->lock, flags);
  733. state = rfkill->state;
  734. spin_unlock_irqrestore(&rfkill->lock, flags);
  735. return !!(state & RFKILL_BLOCK_ANY);
  736. }
  737. EXPORT_SYMBOL(rfkill_blocked);
  738. struct rfkill * __must_check rfkill_alloc(const char *name,
  739. struct device *parent,
  740. const enum rfkill_type type,
  741. const struct rfkill_ops *ops,
  742. void *ops_data)
  743. {
  744. struct rfkill *rfkill;
  745. struct device *dev;
  746. if (WARN_ON(!ops))
  747. return NULL;
  748. if (WARN_ON(!ops->set_block))
  749. return NULL;
  750. if (WARN_ON(!name))
  751. return NULL;
  752. if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
  753. return NULL;
  754. rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
  755. if (!rfkill)
  756. return NULL;
  757. spin_lock_init(&rfkill->lock);
  758. INIT_LIST_HEAD(&rfkill->node);
  759. rfkill->type = type;
  760. strcpy(rfkill->name, name);
  761. rfkill->ops = ops;
  762. rfkill->data = ops_data;
  763. dev = &rfkill->dev;
  764. dev->class = &rfkill_class;
  765. dev->parent = parent;
  766. device_initialize(dev);
  767. return rfkill;
  768. }
  769. EXPORT_SYMBOL(rfkill_alloc);
  770. static void rfkill_poll(struct work_struct *work)
  771. {
  772. struct rfkill *rfkill;
  773. rfkill = container_of(work, struct rfkill, poll_work.work);
  774. /*
  775. * Poll hardware state -- driver will use one of the
  776. * rfkill_set{,_hw,_sw}_state functions and use its
  777. * return value to update the current status.
  778. */
  779. rfkill->ops->poll(rfkill, rfkill->data);
  780. queue_delayed_work(system_power_efficient_wq,
  781. &rfkill->poll_work,
  782. round_jiffies_relative(POLL_INTERVAL));
  783. }
  784. static void rfkill_uevent_work(struct work_struct *work)
  785. {
  786. struct rfkill *rfkill;
  787. rfkill = container_of(work, struct rfkill, uevent_work);
  788. mutex_lock(&rfkill_global_mutex);
  789. rfkill_event(rfkill);
  790. mutex_unlock(&rfkill_global_mutex);
  791. }
  792. static void rfkill_sync_work(struct work_struct *work)
  793. {
  794. struct rfkill *rfkill;
  795. bool cur;
  796. rfkill = container_of(work, struct rfkill, sync_work);
  797. mutex_lock(&rfkill_global_mutex);
  798. cur = rfkill_global_states[rfkill->type].cur;
  799. rfkill_set_block(rfkill, cur);
  800. mutex_unlock(&rfkill_global_mutex);
  801. }
  802. int __must_check rfkill_register(struct rfkill *rfkill)
  803. {
  804. static unsigned long rfkill_no;
  805. struct device *dev;
  806. int error;
  807. if (!rfkill)
  808. return -EINVAL;
  809. dev = &rfkill->dev;
  810. mutex_lock(&rfkill_global_mutex);
  811. if (rfkill->registered) {
  812. error = -EALREADY;
  813. goto unlock;
  814. }
  815. rfkill->idx = rfkill_no;
  816. dev_set_name(dev, "rfkill%lu", rfkill_no);
  817. rfkill_no++;
  818. list_add_tail(&rfkill->node, &rfkill_list);
  819. error = device_add(dev);
  820. if (error)
  821. goto remove;
  822. error = rfkill_led_trigger_register(rfkill);
  823. if (error)
  824. goto devdel;
  825. rfkill->registered = true;
  826. INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll);
  827. INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work);
  828. INIT_WORK(&rfkill->sync_work, rfkill_sync_work);
  829. if (rfkill->ops->poll)
  830. queue_delayed_work(system_power_efficient_wq,
  831. &rfkill->poll_work,
  832. round_jiffies_relative(POLL_INTERVAL));
  833. if (!rfkill->persistent || rfkill_epo_lock_active) {
  834. schedule_work(&rfkill->sync_work);
  835. } else {
  836. #ifdef CONFIG_RFKILL_INPUT
  837. bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW);
  838. if (!atomic_read(&rfkill_input_disabled))
  839. __rfkill_switch_all(rfkill->type, soft_blocked);
  840. #endif
  841. }
  842. rfkill_global_led_trigger_event();
  843. rfkill_send_events(rfkill, RFKILL_OP_ADD);
  844. mutex_unlock(&rfkill_global_mutex);
  845. return 0;
  846. devdel:
  847. device_del(&rfkill->dev);
  848. remove:
  849. list_del_init(&rfkill->node);
  850. unlock:
  851. mutex_unlock(&rfkill_global_mutex);
  852. return error;
  853. }
  854. EXPORT_SYMBOL(rfkill_register);
  855. void rfkill_unregister(struct rfkill *rfkill)
  856. {
  857. BUG_ON(!rfkill);
  858. if (rfkill->ops->poll)
  859. cancel_delayed_work_sync(&rfkill->poll_work);
  860. cancel_work_sync(&rfkill->uevent_work);
  861. cancel_work_sync(&rfkill->sync_work);
  862. rfkill->registered = false;
  863. device_del(&rfkill->dev);
  864. mutex_lock(&rfkill_global_mutex);
  865. rfkill_send_events(rfkill, RFKILL_OP_DEL);
  866. list_del_init(&rfkill->node);
  867. rfkill_global_led_trigger_event();
  868. mutex_unlock(&rfkill_global_mutex);
  869. rfkill_led_trigger_unregister(rfkill);
  870. }
  871. EXPORT_SYMBOL(rfkill_unregister);
  872. void rfkill_destroy(struct rfkill *rfkill)
  873. {
  874. if (rfkill)
  875. put_device(&rfkill->dev);
  876. }
  877. EXPORT_SYMBOL(rfkill_destroy);
  878. static int rfkill_fop_open(struct inode *inode, struct file *file)
  879. {
  880. struct rfkill_data *data;
  881. struct rfkill *rfkill;
  882. struct rfkill_int_event *ev, *tmp;
  883. data = kzalloc(sizeof(*data), GFP_KERNEL);
  884. if (!data)
  885. return -ENOMEM;
  886. INIT_LIST_HEAD(&data->events);
  887. mutex_init(&data->mtx);
  888. init_waitqueue_head(&data->read_wait);
  889. mutex_lock(&rfkill_global_mutex);
  890. mutex_lock(&data->mtx);
  891. /*
  892. * start getting events from elsewhere but hold mtx to get
  893. * startup events added first
  894. */
  895. list_for_each_entry(rfkill, &rfkill_list, node) {
  896. ev = kzalloc(sizeof(*ev), GFP_KERNEL);
  897. if (!ev)
  898. goto free;
  899. rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD);
  900. list_add_tail(&ev->list, &data->events);
  901. }
  902. list_add(&data->list, &rfkill_fds);
  903. mutex_unlock(&data->mtx);
  904. mutex_unlock(&rfkill_global_mutex);
  905. file->private_data = data;
  906. return stream_open(inode, file);
  907. free:
  908. mutex_unlock(&data->mtx);
  909. mutex_unlock(&rfkill_global_mutex);
  910. mutex_destroy(&data->mtx);
  911. list_for_each_entry_safe(ev, tmp, &data->events, list)
  912. kfree(ev);
  913. kfree(data);
  914. return -ENOMEM;
  915. }
  916. static __poll_t rfkill_fop_poll(struct file *file, poll_table *wait)
  917. {
  918. struct rfkill_data *data = file->private_data;
  919. __poll_t res = EPOLLOUT | EPOLLWRNORM;
  920. poll_wait(file, &data->read_wait, wait);
  921. mutex_lock(&data->mtx);
  922. if (!list_empty(&data->events))
  923. res = EPOLLIN | EPOLLRDNORM;
  924. mutex_unlock(&data->mtx);
  925. return res;
  926. }
  927. static ssize_t rfkill_fop_read(struct file *file, char __user *buf,
  928. size_t count, loff_t *pos)
  929. {
  930. struct rfkill_data *data = file->private_data;
  931. struct rfkill_int_event *ev;
  932. unsigned long sz;
  933. int ret;
  934. mutex_lock(&data->mtx);
  935. while (list_empty(&data->events)) {
  936. if (file->f_flags & O_NONBLOCK) {
  937. ret = -EAGAIN;
  938. goto out;
  939. }
  940. mutex_unlock(&data->mtx);
  941. /* since we re-check and it just compares pointers,
  942. * using !list_empty() without locking isn't a problem
  943. */
  944. ret = wait_event_interruptible(data->read_wait,
  945. !list_empty(&data->events));
  946. mutex_lock(&data->mtx);
  947. if (ret)
  948. goto out;
  949. }
  950. ev = list_first_entry(&data->events, struct rfkill_int_event,
  951. list);
  952. sz = min_t(unsigned long, sizeof(ev->ev), count);
  953. ret = sz;
  954. if (copy_to_user(buf, &ev->ev, sz))
  955. ret = -EFAULT;
  956. list_del(&ev->list);
  957. kfree(ev);
  958. out:
  959. mutex_unlock(&data->mtx);
  960. return ret;
  961. }
  962. static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
  963. size_t count, loff_t *pos)
  964. {
  965. struct rfkill *rfkill;
  966. struct rfkill_event ev;
  967. int ret;
  968. /* we don't need the 'hard' variable but accept it */
  969. if (count < RFKILL_EVENT_SIZE_V1 - 1)
  970. return -EINVAL;
  971. /*
  972. * Copy as much data as we can accept into our 'ev' buffer,
  973. * but tell userspace how much we've copied so it can determine
  974. * our API version even in a write() call, if it cares.
  975. */
  976. count = min(count, sizeof(ev));
  977. if (copy_from_user(&ev, buf, count))
  978. return -EFAULT;
  979. if (ev.type >= NUM_RFKILL_TYPES)
  980. return -EINVAL;
  981. mutex_lock(&rfkill_global_mutex);
  982. switch (ev.op) {
  983. case RFKILL_OP_CHANGE_ALL:
  984. rfkill_update_global_state(ev.type, ev.soft);
  985. list_for_each_entry(rfkill, &rfkill_list, node)
  986. if (rfkill->type == ev.type ||
  987. ev.type == RFKILL_TYPE_ALL)
  988. rfkill_set_block(rfkill, ev.soft);
  989. ret = 0;
  990. break;
  991. case RFKILL_OP_CHANGE:
  992. list_for_each_entry(rfkill, &rfkill_list, node)
  993. if (rfkill->idx == ev.idx &&
  994. (rfkill->type == ev.type ||
  995. ev.type == RFKILL_TYPE_ALL))
  996. rfkill_set_block(rfkill, ev.soft);
  997. ret = 0;
  998. break;
  999. default:
  1000. ret = -EINVAL;
  1001. break;
  1002. }
  1003. mutex_unlock(&rfkill_global_mutex);
  1004. return ret ?: count;
  1005. }
  1006. static int rfkill_fop_release(struct inode *inode, struct file *file)
  1007. {
  1008. struct rfkill_data *data = file->private_data;
  1009. struct rfkill_int_event *ev, *tmp;
  1010. mutex_lock(&rfkill_global_mutex);
  1011. list_del(&data->list);
  1012. mutex_unlock(&rfkill_global_mutex);
  1013. mutex_destroy(&data->mtx);
  1014. list_for_each_entry_safe(ev, tmp, &data->events, list)
  1015. kfree(ev);
  1016. #ifdef CONFIG_RFKILL_INPUT
  1017. if (data->input_handler)
  1018. if (atomic_dec_return(&rfkill_input_disabled) == 0)
  1019. printk(KERN_DEBUG "rfkill: input handler enabled\n");
  1020. #endif
  1021. kfree(data);
  1022. return 0;
  1023. }
  1024. #ifdef CONFIG_RFKILL_INPUT
  1025. static long rfkill_fop_ioctl(struct file *file, unsigned int cmd,
  1026. unsigned long arg)
  1027. {
  1028. struct rfkill_data *data = file->private_data;
  1029. if (_IOC_TYPE(cmd) != RFKILL_IOC_MAGIC)
  1030. return -ENOSYS;
  1031. if (_IOC_NR(cmd) != RFKILL_IOC_NOINPUT)
  1032. return -ENOSYS;
  1033. mutex_lock(&data->mtx);
  1034. if (!data->input_handler) {
  1035. if (atomic_inc_return(&rfkill_input_disabled) == 1)
  1036. printk(KERN_DEBUG "rfkill: input handler disabled\n");
  1037. data->input_handler = true;
  1038. }
  1039. mutex_unlock(&data->mtx);
  1040. return 0;
  1041. }
  1042. #endif
  1043. static const struct file_operations rfkill_fops = {
  1044. .owner = THIS_MODULE,
  1045. .open = rfkill_fop_open,
  1046. .read = rfkill_fop_read,
  1047. .write = rfkill_fop_write,
  1048. .poll = rfkill_fop_poll,
  1049. .release = rfkill_fop_release,
  1050. #ifdef CONFIG_RFKILL_INPUT
  1051. .unlocked_ioctl = rfkill_fop_ioctl,
  1052. .compat_ioctl = compat_ptr_ioctl,
  1053. #endif
  1054. .llseek = no_llseek,
  1055. };
  1056. #define RFKILL_NAME "rfkill"
  1057. static struct miscdevice rfkill_miscdev = {
  1058. .fops = &rfkill_fops,
  1059. .name = RFKILL_NAME,
  1060. .minor = RFKILL_MINOR,
  1061. };
  1062. static int __init rfkill_init(void)
  1063. {
  1064. int error;
  1065. rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state);
  1066. error = class_register(&rfkill_class);
  1067. if (error)
  1068. goto error_class;
  1069. error = misc_register(&rfkill_miscdev);
  1070. if (error)
  1071. goto error_misc;
  1072. error = rfkill_global_led_trigger_register();
  1073. if (error)
  1074. goto error_led_trigger;
  1075. #ifdef CONFIG_RFKILL_INPUT
  1076. error = rfkill_handler_init();
  1077. if (error)
  1078. goto error_input;
  1079. #endif
  1080. return 0;
  1081. #ifdef CONFIG_RFKILL_INPUT
  1082. error_input:
  1083. rfkill_global_led_trigger_unregister();
  1084. #endif
  1085. error_led_trigger:
  1086. misc_deregister(&rfkill_miscdev);
  1087. error_misc:
  1088. class_unregister(&rfkill_class);
  1089. error_class:
  1090. return error;
  1091. }
  1092. subsys_initcall(rfkill_init);
  1093. static void __exit rfkill_exit(void)
  1094. {
  1095. #ifdef CONFIG_RFKILL_INPUT
  1096. rfkill_handler_exit();
  1097. #endif
  1098. rfkill_global_led_trigger_unregister();
  1099. misc_deregister(&rfkill_miscdev);
  1100. class_unregister(&rfkill_class);
  1101. }
  1102. module_exit(rfkill_exit);
  1103. MODULE_ALIAS_MISCDEV(RFKILL_MINOR);
  1104. MODULE_ALIAS("devname:" RFKILL_NAME);