summaryrefslogtreecommitdiffstats
path: root/net/rfkill
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@gmail.com>2016-02-22 11:36:39 -0500
committerJohannes Berg <johannes.berg@intel.com>2016-04-05 04:48:53 -0400
commit1948b2a2ec132115b422ae1feba1a3f5598f4acd (patch)
tree91599c316608ab816cde1e505bb07dbd41ec2a0f /net/rfkill
parent98bd147d7903580ca5d5dfa0bc39c2d16714d84e (diff)
rfkill: Use switch to demux userspace operations
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> [roll in fix for RFKILL_OP_CHANGE from Jouni] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/rfkill')
-rw-r--r--net/rfkill/core.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 03f26e3a6f48..884027f62783 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -1141,6 +1141,7 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
1141{ 1141{
1142 struct rfkill *rfkill; 1142 struct rfkill *rfkill;
1143 struct rfkill_event ev; 1143 struct rfkill_event ev;
1144 int ret;
1144 1145
1145 /* we don't need the 'hard' variable but accept it */ 1146 /* we don't need the 'hard' variable but accept it */
1146 if (count < RFKILL_EVENT_SIZE_V1 - 1) 1147 if (count < RFKILL_EVENT_SIZE_V1 - 1)
@@ -1155,29 +1156,36 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
1155 if (copy_from_user(&ev, buf, count)) 1156 if (copy_from_user(&ev, buf, count))
1156 return -EFAULT; 1157 return -EFAULT;
1157 1158
1158 if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL)
1159 return -EINVAL;
1160
1161 if (ev.type >= NUM_RFKILL_TYPES) 1159 if (ev.type >= NUM_RFKILL_TYPES)
1162 return -EINVAL; 1160 return -EINVAL;
1163 1161
1164 mutex_lock(&rfkill_global_mutex); 1162 mutex_lock(&rfkill_global_mutex);
1165 1163
1166 if (ev.op == RFKILL_OP_CHANGE_ALL) 1164 switch (ev.op) {
1165 case RFKILL_OP_CHANGE_ALL:
1167 rfkill_update_global_state(ev.type, ev.soft); 1166 rfkill_update_global_state(ev.type, ev.soft);
1168 1167 list_for_each_entry(rfkill, &rfkill_list, node)
1169 list_for_each_entry(rfkill, &rfkill_list, node) { 1168 if (rfkill->type == ev.type ||
1170 if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) 1169 ev.type == RFKILL_TYPE_ALL)
1171 continue; 1170 rfkill_set_block(rfkill, ev.soft);
1172 1171 ret = 0;
1173 if (rfkill->type != ev.type && ev.type != RFKILL_TYPE_ALL) 1172 break;
1174 continue; 1173 case RFKILL_OP_CHANGE:
1175 1174 list_for_each_entry(rfkill, &rfkill_list, node)
1176 rfkill_set_block(rfkill, ev.soft); 1175 if (rfkill->idx == ev.idx &&
1176 (rfkill->type == ev.type ||
1177 ev.type == RFKILL_TYPE_ALL))
1178 rfkill_set_block(rfkill, ev.soft);
1179 ret = 0;
1180 break;
1181 default:
1182 ret = -EINVAL;
1183 break;
1177 } 1184 }
1185
1178 mutex_unlock(&rfkill_global_mutex); 1186 mutex_unlock(&rfkill_global_mutex);
1179 1187
1180 return count; 1188 return ret ?: count;
1181} 1189}
1182 1190
1183static int rfkill_fop_release(struct inode *inode, struct file *file) 1191static int rfkill_fop_release(struct inode *inode, struct file *file)