Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1533257 > unrolled thread

[PATCH 1/2] net: rfkill: Cleanup error handling in rfkill_init()

Started byMichał Kępień <kernel@kempniu.pl>
First post2016-11-30 13:10 +0100
Last post2016-12-05 15:00 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] net: rfkill: Cleanup error handling in rfkill_init() Michał Kępień <kernel@kempniu.pl> - 2016-11-30 13:10 +0100
    [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger Michał Kępień <kernel@kempniu.pl> - 2016-11-30 13:10 +0100
      Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger kbuild test robot <lkp@intel.com> - 2016-12-01 18:40 +0100
        Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger Michał Kępień <kernel@kempniu.pl> - 2016-12-01 21:10 +0100
          Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger Johannes Berg <johannes@sipsolutions.net> - 2016-12-05 15:00 +0100

#1533257 — [PATCH 1/2] net: rfkill: Cleanup error handling in rfkill_init()

FromMichał Kępień <kernel@kempniu.pl>
Date2016-11-30 13:10 +0100
Subject[PATCH 1/2] net: rfkill: Cleanup error handling in rfkill_init()
Message-ID<sJbS2-5UT-7@gated-at.bofh.it>
Use a separate label per error condition in rfkill_init() to make it a
bit cleaner and easier to extend.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
 net/rfkill/core.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 884027f..f28e441 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -1266,24 +1266,25 @@ static int __init rfkill_init(void)
 
 	error = class_register(&rfkill_class);
 	if (error)
-		goto out;
+		goto error_class;
 
 	error = misc_register(&rfkill_miscdev);
-	if (error) {
-		class_unregister(&rfkill_class);
-		goto out;
-	}
+	if (error)
+		goto error_misc;
 
 #ifdef CONFIG_RFKILL_INPUT
 	error = rfkill_handler_init();
-	if (error) {
-		misc_deregister(&rfkill_miscdev);
-		class_unregister(&rfkill_class);
-		goto out;
-	}
+	if (error)
+		goto error_input;
 #endif
 
- out:
+	return 0;
+
+error_input:
+	misc_deregister(&rfkill_miscdev);
+error_misc:
+	class_unregister(&rfkill_class);
+error_class:
 	return error;
 }
 subsys_initcall(rfkill_init);
-- 
2.10.2

[toc] | [next] | [standalone]


#1533258 — [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger

FromMichał Kępień <kernel@kempniu.pl>
Date2016-11-30 13:10 +0100
Subject[PATCH 2/2] net: rfkill: Add rfkill-any LED trigger
Message-ID<sJbS2-5UT-19@gated-at.bofh.it>
In reply to#1533257
This patch adds a new "global" (i.e. not per-rfkill device) LED trigger,
rfkill-any, which may be useful for laptops with a single "radio LED"
and multiple radio transmitters.  The trigger is meant to turn a LED on
whenever there is at least one radio transmitter active and turn it off
otherwise.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
Note that the search for any active radio will have quadratic complexity
whenever __rfkill_switch_all() is used (as it calls rfkill_set_block()
for every affected rfkill device), but I intentionally refrained from
implementing rfkill_any_led_trigger_event() using struct work_struct to
keep things simple, given the average number of rfkill devices in
hardware these days.  Please let me know in case this should be
reworked.

 net/rfkill/core.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index f28e441..5275f2f 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -176,6 +176,47 @@ static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
 {
 	led_trigger_unregister(&rfkill->led_trigger);
 }
+
+static struct led_trigger rfkill_any_led_trigger;
+
+static void __rfkill_any_led_trigger_event(void)
+{
+	enum led_brightness brightness = LED_OFF;
+	struct rfkill *rfkill;
+
+	list_for_each_entry(rfkill, &rfkill_list, node) {
+		if (!(rfkill->state & RFKILL_BLOCK_ANY)) {
+			brightness = LED_FULL;
+			break;
+		}
+	}
+
+	led_trigger_event(&rfkill_any_led_trigger, brightness);
+}
+
+static void rfkill_any_led_trigger_event(void)
+{
+	mutex_lock(&rfkill_global_mutex);
+	__rfkill_any_led_trigger_event();
+	mutex_unlock(&rfkill_global_mutex);
+}
+
+static void rfkill_any_led_trigger_activate(struct led_classdev *led_cdev)
+{
+	rfkill_any_led_trigger_event();
+}
+
+static int rfkill_any_led_trigger_register(void)
+{
+	rfkill_any_led_trigger.name = "rfkill-any";
+	rfkill_any_led_trigger.activate = rfkill_any_led_trigger_activate;
+	return led_trigger_register(&rfkill_any_led_trigger);
+}
+
+static void rfkill_any_led_trigger_unregister(void)
+{
+	led_trigger_unregister(&rfkill_any_led_trigger);
+}
 #else
 static void rfkill_led_trigger_event(struct rfkill *rfkill)
 {
@@ -189,6 +230,19 @@ static inline int rfkill_led_trigger_register(struct rfkill *rfkill)
 static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill)
 {
 }
+
+static void rfkill_any_led_trigger_event(void)
+{
+}
+
+static int rfkill_any_led_trigger_register(void)
+{
+	return 0;
+}
+
+static void rfkill_any_led_trigger_unregister(void)
+{
+}
 #endif /* CONFIG_RFKILL_LEDS */
 
 static void rfkill_fill_event(struct rfkill_event *ev, struct rfkill *rfkill,
@@ -297,6 +351,7 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
 	spin_unlock_irqrestore(&rfkill->lock, flags);
 
 	rfkill_led_trigger_event(rfkill);
+	__rfkill_any_led_trigger_event();
 
 	if (prev != curr)
 		rfkill_event(rfkill);
@@ -477,6 +532,7 @@ bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
 	spin_unlock_irqrestore(&rfkill->lock, flags);
 
 	rfkill_led_trigger_event(rfkill);
+	rfkill_any_led_trigger_event();
 
 	if (!rfkill->registered)
 		return ret;
@@ -523,6 +579,7 @@ bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
 		schedule_work(&rfkill->uevent_work);
 
 	rfkill_led_trigger_event(rfkill);
+	rfkill_any_led_trigger_event();
 
 	return blocked;
 }
@@ -572,6 +629,7 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
 			schedule_work(&rfkill->uevent_work);
 
 		rfkill_led_trigger_event(rfkill);
+		rfkill_any_led_trigger_event();
 	}
 }
 EXPORT_SYMBOL(rfkill_set_states);
@@ -988,6 +1046,7 @@ int __must_check rfkill_register(struct rfkill *rfkill)
 #endif
 	}
 
+	__rfkill_any_led_trigger_event();
 	rfkill_send_events(rfkill, RFKILL_OP_ADD);
 
 	mutex_unlock(&rfkill_global_mutex);
@@ -1020,6 +1079,7 @@ void rfkill_unregister(struct rfkill *rfkill)
 	mutex_lock(&rfkill_global_mutex);
 	rfkill_send_events(rfkill, RFKILL_OP_DEL);
 	list_del_init(&rfkill->node);
+	__rfkill_any_led_trigger_event();
 	mutex_unlock(&rfkill_global_mutex);
 
 	rfkill_led_trigger_unregister(rfkill);
@@ -1278,8 +1338,18 @@ static int __init rfkill_init(void)
 		goto error_input;
 #endif
 
+#ifdef CONFIG_RFKILL_LEDS
+	error = rfkill_any_led_trigger_register();
+	if (error)
+		goto error_led_trigger;
+#endif
+
 	return 0;
 
+error_led_trigger:
+#ifdef CONFIG_RFKILL_INPUT
+	rfkill_handler_exit();
+#endif
 error_input:
 	misc_deregister(&rfkill_miscdev);
 error_misc:
@@ -1291,6 +1361,9 @@ subsys_initcall(rfkill_init);
 
 static void __exit rfkill_exit(void)
 {
+#ifdef CONFIG_RFKILL_LEDS
+	rfkill_any_led_trigger_unregister();
+#endif
 #ifdef CONFIG_RFKILL_INPUT
 	rfkill_handler_exit();
 #endif
-- 
2.10.2

[toc] | [prev] | [next] | [standalone]


#1534330 — Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger

Fromkbuild test robot <lkp@intel.com>
Date2016-12-01 18:40 +0100
SubjectRe: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger
Message-ID<sJDuW-7nV-7@gated-at.bofh.it>
In reply to#1533258

[Multipart message — attachments visible in raw view] — view raw

Hi Michał,

[auto build test ERROR on mac80211-next/master]
[also build test ERROR on v4.9-rc7 next-20161201]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Micha-K-pie/net-rfkill-Cleanup-error-handling-in-rfkill_init/20161202-002119
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git master
config: i386-randconfig-x004-201648 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   net/rfkill/core.c: In function 'rfkill_set_block':
>> net/rfkill/core.c:354:2: error: implicit declaration of function '__rfkill_any_led_trigger_event' [-Werror=implicit-function-declaration]
     __rfkill_any_led_trigger_event();
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   net/rfkill/core.c: In function 'rfkill_init':
   net/rfkill/core.c:1349:1: warning: label 'error_led_trigger' defined but not used [-Wunused-label]
    error_led_trigger:
    ^~~~~~~~~~~~~~~~~
   At top level:
   net/rfkill/core.c:243:13: warning: 'rfkill_any_led_trigger_unregister' defined but not used [-Wunused-function]
    static void rfkill_any_led_trigger_unregister(void)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   net/rfkill/core.c:238:12: warning: 'rfkill_any_led_trigger_register' defined but not used [-Wunused-function]
    static int rfkill_any_led_trigger_register(void)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/__rfkill_any_led_trigger_event +354 net/rfkill/core.c

   348		rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL;
   349		rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
   350		curr = rfkill->state & RFKILL_BLOCK_SW;
   351		spin_unlock_irqrestore(&rfkill->lock, flags);
   352	
   353		rfkill_led_trigger_event(rfkill);
 > 354		__rfkill_any_led_trigger_event();
   355	
   356		if (prev != curr)
   357			rfkill_event(rfkill);

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[toc] | [prev] | [next] | [standalone]


#1534414 — Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger

FromMichał Kępień <kernel@kempniu.pl>
Date2016-12-01 21:10 +0100
SubjectRe: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger
Message-ID<sJFQ6-1ih-17@gated-at.bofh.it>
In reply to#1534330
> Hi Michał,
> 
> [auto build test ERROR on mac80211-next/master]
> [also build test ERROR on v4.9-rc7 next-20161201]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Micha-K-pie/net-rfkill-Cleanup-error-handling-in-rfkill_init/20161202-002119
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git master
> config: i386-randconfig-x004-201648 (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=i386 
> 
> All errors (new ones prefixed by >>):
> 
>    net/rfkill/core.c: In function 'rfkill_set_block':
> >> net/rfkill/core.c:354:2: error: implicit declaration of function '__rfkill_any_led_trigger_event' [-Werror=implicit-function-declaration]
>      __rfkill_any_led_trigger_event();
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    net/rfkill/core.c: In function 'rfkill_init':
>    net/rfkill/core.c:1349:1: warning: label 'error_led_trigger' defined but not used [-Wunused-label]
>     error_led_trigger:
>     ^~~~~~~~~~~~~~~~~
>    At top level:
>    net/rfkill/core.c:243:13: warning: 'rfkill_any_led_trigger_unregister' defined but not used [-Wunused-function]
>     static void rfkill_any_led_trigger_unregister(void)
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    net/rfkill/core.c:238:12: warning: 'rfkill_any_led_trigger_register' defined but not used [-Wunused-function]
>     static int rfkill_any_led_trigger_register(void)
>                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    cc1: some warnings being treated as errors
> 
> vim +/__rfkill_any_led_trigger_event +354 net/rfkill/core.c
> 
>    348		rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL;
>    349		rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
>    350		curr = rfkill->state & RFKILL_BLOCK_SW;
>    351		spin_unlock_irqrestore(&rfkill->lock, flags);
>    352	
>    353		rfkill_led_trigger_event(rfkill);
>  > 354		__rfkill_any_led_trigger_event();
>    355	
>    356		if (prev != curr)
>    357			rfkill_event(rfkill);

Thanks, these are obviously all valid concerns.  Sorry for being sloppy
with the ifdefs.  If I get positive feedback on the proposed feature
itself, all these issues (and the warning pointed out in the other
message) will be resolved in v2.

-- 
Best regards,
Michał Kępień

[toc] | [prev] | [next] | [standalone]


#1536112 — Re: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger

FromJohannes Berg <johannes@sipsolutions.net>
Date2016-12-05 15:00 +0100
SubjectRe: [PATCH 2/2] net: rfkill: Add rfkill-any LED trigger
Message-ID<sL1Yi-5fD-23@gated-at.bofh.it>
In reply to#1534414
> Thanks, these are obviously all valid concerns.  Sorry for being
> sloppy
> with the ifdefs.  If I get positive feedback on the proposed feature
> itself, all these issues (and the warning pointed out in the other
> message) will be resolved in v2.

Looks fine, please do that.

johannes

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web