aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2007-10-28 10:16:50 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-11-11 01:00:15 -0500
commit7319f1e6bcf04abd2eddb19747b0933a76f839ce (patch)
treeb6b1579a2bf0bfab90736ee589fa836835ede6cc
parentf51359a8fb1bb00ae87051991e59d0f92d90604b (diff)
rfkill: Use mutex_lock() at register and add sanity check
Replace mutex_lock_interruptible() by mutex_lock() in rfkill_register(), as interruptible doesn't make sense there. Add a sanity check for rfkill->type, as that's used for an unchecked dereference in an array and might cause hard to debug crashes if the driver sets this to an invalid value. Signed-off-by: Michael Buesch <mb@bu3sch.de> Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--net/rfkill/rfkill.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index bbfbb9e7a917..47e8cd0322c0 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -276,21 +276,17 @@ static struct class rfkill_class = {
276 276
277static int rfkill_add_switch(struct rfkill *rfkill) 277static int rfkill_add_switch(struct rfkill *rfkill)
278{ 278{
279 int retval; 279 int error;
280
281 retval = mutex_lock_interruptible(&rfkill_mutex);
282 if (retval)
283 return retval;
284 280
285 retval = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]); 281 mutex_lock(&rfkill_mutex);
286 if (retval)
287 goto out;
288 282
289 list_add_tail(&rfkill->node, &rfkill_list); 283 error = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]);
284 if (!error)
285 list_add_tail(&rfkill->node, &rfkill_list);
290 286
291 out:
292 mutex_unlock(&rfkill_mutex); 287 mutex_unlock(&rfkill_mutex);
293 return retval; 288
289 return error;
294} 290}
295 291
296static void rfkill_remove_switch(struct rfkill *rfkill) 292static void rfkill_remove_switch(struct rfkill *rfkill)
@@ -387,6 +383,8 @@ int rfkill_register(struct rfkill *rfkill)
387 383
388 if (!rfkill->toggle_radio) 384 if (!rfkill->toggle_radio)
389 return -EINVAL; 385 return -EINVAL;
386 if (rfkill->type >= RFKILL_TYPE_MAX)
387 return -EINVAL;
390 388
391 snprintf(dev->bus_id, sizeof(dev->bus_id), 389 snprintf(dev->bus_id, sizeof(dev->bus_id),
392 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1); 390 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);