Commit 02589f60 authored by Henrique de Moraes Holschuh's avatar Henrique de Moraes Holschuh Committed by John W. Linville
Browse files

rfkill: detect bogus double-registering (v2)

Detect and abort with -EEXIST if rfkill_register is called twice on the
same rfkill struct.  And WARN_ON(it) for good measure.

While at it, flag when we are adding the first switch of a type, we will
need that information later.

Signed-off-by: default avatarHenrique de Moraes Holschuh <>
Acked-by: default avatarIvo van Doorn <>
Cc: Johannes Berg <>
Signed-off-by: default avatarJohn W. Linville <>
parent c94c93da
......@@ -525,17 +525,44 @@ static struct class rfkill_class = {
.dev_uevent = rfkill_dev_uevent,
static int rfkill_check_duplicity(const struct rfkill *rfkill)
struct rfkill *p;
unsigned long seen[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
memset(seen, 0, sizeof(seen));
list_for_each_entry(p, &rfkill_list, node) {
if (p == rfkill) {
return -EEXIST;
set_bit(p->type, seen);
/* 0: first switch of its kind */
return test_bit(rfkill->type, seen);
static int rfkill_add_switch(struct rfkill *rfkill)
int error;
error = rfkill_check_duplicity(rfkill);
if (error < 0)
goto unlock_out;
rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);
list_add_tail(&rfkill->node, &rfkill_list);
error = 0;
return 0;
return error;
static void rfkill_remove_switch(struct rfkill *rfkill)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment