Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1339722
| From | "João Paulo Rechi Vita" <jprvita@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCHv2 08/10] rfkill: Use switch to demux userspace operations |
| Date | 2016-02-22 17:50 +0100 |
| Message-ID | <r51Qn-95-37@gated-at.bofh.it> (permalink) |
| References | <r51GG-8uQ-19@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Using a switch to handle different ev.op values in rfkill_fop_write()
makes the code easier to extend, as out-of-range values can always be
handled by the default case.
Signed-off-by: João Paulo Rechi Vita <jprvita@endlessm.com>
---
net/rfkill/core.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 50b538b..04d7fa1 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -1185,6 +1185,7 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
{
struct rfkill *rfkill;
struct rfkill_event ev;
+ int ret = 0;
/* we don't need the 'hard' variable but accept it */
if (count < RFKILL_EVENT_SIZE_V1 - 1)
@@ -1199,29 +1200,32 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
if (copy_from_user(&ev, buf, count))
return -EFAULT;
- if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL)
- return -EINVAL;
-
if (ev.type >= NUM_RFKILL_TYPES)
return -EINVAL;
mutex_lock(&rfkill_global_mutex);
- if (ev.op == RFKILL_OP_CHANGE_ALL)
+ switch (ev.op) {
+ case RFKILL_OP_CHANGE_ALL:
rfkill_update_global_state(ev.type, ev.soft);
-
- list_for_each_entry(rfkill, &rfkill_list, node) {
- if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL)
- continue;
-
- if (rfkill->type != ev.type && ev.type != RFKILL_TYPE_ALL)
- continue;
-
- rfkill_set_block(rfkill, ev.soft);
+ list_for_each_entry(rfkill, &rfkill_list, node)
+ if (rfkill->type == ev.type ||
+ ev.type == RFKILL_TYPE_ALL)
+ rfkill_set_block(rfkill, ev.soft);
+ break;
+ case RFKILL_OP_CHANGE:
+ list_for_each_entry(rfkill, &rfkill_list, node)
+ if (rfkill->idx == ev.idx && rfkill->type == ev.type)
+ rfkill_set_block(rfkill, ev.soft);
+ break;
+ default:
+ ret = -EINVAL;
+ break;
}
+
mutex_unlock(&rfkill_global_mutex);
- return count;
+ return ret ? ret : count;
}
static int rfkill_fop_release(struct inode *inode, struct file *file)
--
2.5.0
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCHv2 08/10] rfkill: Use switch to demux userspace operations "João Paulo Rechi Vita" <jprvita@gmail.com> - 2016-02-22 17:50 +0100
Re: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations Jouni Malinen <j@w1.fi> - 2016-02-26 19:10 +0100
Re: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations Jouni Malinen <j@w1.fi> - 2016-02-29 23:40 +0100
Re: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations Johannes Berg <johannes@sipsolutions.net> - 2016-03-01 14:50 +0100
Re: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations João Paulo Rechi Vita <jprvita@gmail.com> - 2016-03-01 17:20 +0100
Re: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations João Paulo Rechi Vita <jprvita@gmail.com> - 2016-02-29 23:40 +0100
csiph-web