Skip to contentSkip to conversation

acer-wmi: Add rfkill support for wireless and bluetooth

RFC In review Carlos Corbacho 4 participants 11 messages Aug 30, 2008 – Sep 14, 2008 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 acer-wmi: Add rfkill support for wireless and bluetooth

This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

For now, we will always poll these devices once a second to guarantee we can catch state changes. On newer Acer laptops, it may be possible to rely on WMI events to do this instead, and experimental support for this will be added in a later patch.

3G has been deliberately left off for now, as we still have no way to detect it, (nor, AFAIK, has any Linux user tried the code) and on laptops that don't support 3G, trying to poll for the status will leave the logs full of ACPI tracebacks.

The old sysfs interface for wireless and 3G will be removed in a later patch.

---

 drivers/misc/Kconfig    |    1 +
 drivers/misc/acer-wmi.c |   89 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 0 deletions(-)
drivers/misc/Kconfig +1 -0
index a726f3b..6abb959 100644
@@ -145,6 +145,7 @@ config ACER_WMI
 	depends on NEW_LEDS
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on SERIO_I8042
+	depends on RFKILL
 	select ACPI_WMI
 	---help---
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
drivers/misc/acer-wmi.c +89 -0

121 lines not on this page · raw message

#1 lore raw

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 963

Quoted 11 lines · Carlos Corbacho
drivers/misc/acer-wmi.c +11 -0
+static void device##_rfkill_update(struct work_struct *ignored) \
+{ \
+	u32 state; \
+	acpi_status status; \
+	status = get_u32(&state, cap); \
+	\
+	if (ACPI_SUCCESS(status)) \
+		rfkill_force_state(device##_rfkill, state); \
+	queue_delayed_work(rfkill_workqueue, &device##_rfkill_work, \
+		round_jiffies_relative(HZ)); \
+}

Please explicitly map from state (int) to the parameter for rfkill_force_state (enum rfkill_state). The compiler will optimize it if it is numerically equal.

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 972

Quoted 5 lines
drivers/misc/acer-wmi.c +5 -0
+static int acer_rfkill_init(struct device *dev)
+{
+	u32 state;
+
+	wireless_rfkill = rfkill_allocate(dev, RFKILL_TYPE_WLAN);

Where's the error handling?

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 975

Quoted 3 lines
drivers/misc/acer-wmi.c +3 -0
+	wireless_rfkill->name = "acer-wireless";
+	get_u32(&state, ACER_CAP_WIRELESS);
+	wireless_rfkill->state = state;

Needs proper map between types to be future-proof.

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 979

Quoted 4 lines
drivers/misc/acer-wmi.c +4 -0
+	wireless_rfkill->toggle_radio = wireless_rfkill_set;
+	wireless_rfkill->user_claim_unsupported = 1;
+
+	bluetooth_rfkill = rfkill_allocate(dev, RFKILL_TYPE_BLUETOOTH);

Where's the error handling?

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 982

Quoted 3 lines
drivers/misc/acer-wmi.c +3 -0
+	bluetooth_rfkill->name = "acer-bluetooth";
+	get_u32(&state, ACER_CAP_BLUETOOTH);
+	bluetooth_rfkill->state = state;

Needs proper map between types to be future-proof.

BTW: you also need error handling on rfkill_register calls.

Since rfkill is a safety measure that the user will expect to be there (after you add support and he starts using it), if you cannot register the rfkill interfaces, you should fail the driver load.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

A message that is not in the archive (sent off-list or not yet received): 20080830140730.GB12246-ZGHd14iZgfaRjzvQDGKj+xxZW9W5cXbT@public.gmane.org

#3 lore raw

RFC 1/1 acer-wmi: Add rfkill support for wireless and bluetooth (v2)

Thanks for the comments - version 2 below.

Also, is there any particular reason why rfkill explicitly doesn't save & restore states on hibernation/ suspend-to-disk?

-Carlos
---
This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

For now, we will always poll these devices once a second to guarantee we can catch state changes. On newer Acer laptops, it may be possible to rely on WMI events to do this instead, and experimental support for this will be added in a later patch.

3G has been deliberately left off for now, as we still have no way to detect it, (nor, AFAIK, has any Linux user tried the code) and on laptops that don't support 3G, trying to poll for the status will leave the logs full of ACPI tracebacks.

The old sysfs interface for wireless and 3G will be removed in a later patch.

---

 drivers/misc/Kconfig    |    1 
 drivers/misc/acer-wmi.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)
drivers/misc/Kconfig +1 -0
index a726f3b..6abb959 100644
@@ -145,6 +145,7 @@ config ACER_WMI
 	depends on NEW_LEDS
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on SERIO_I8042
+	depends on RFKILL
 	select ACPI_WMI
 	---help---
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
drivers/misc/acer-wmi.c +100 -0

132 lines not on this page · raw message

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [RFC] acer-wmi: Add rfkill support for wireless and bluetooth (v2)

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 963

Quoted 11 lines · Carlos Corbacho
drivers/misc/acer-wmi.c +11 -0
+static void device##_rfkill_update(struct work_struct *ignored) \
+{ \
+	u32 state; \
+	acpi_status status; \
+	status = get_u32(&state, cap); \
+	\
+	if (ACPI_SUCCESS(status)) \
+		rfkill_force_state(device##_rfkill, state); \
+	queue_delayed_work(rfkill_workqueue, &device##_rfkill_work, \
+		round_jiffies_relative(HZ)); \
+}

You are still doing state = (int); rfkill_force_state(foo, state);

Please do a rfkill_force_state(foo, state ? RFKILL_STATE_UNBLOCKED :

					RFKILL_STATE_SOFT_BLOCKED);

or whatever is correct for what the values of (state) mean.

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 985

Quoted 3 lines
drivers/misc/acer-wmi.c +3 -0
+	err = rfkill_register(wireless_rfkill);
+	if (err)
+		return err;

You have to manually dealocate wireless_rfkill on the error path here using rfkill_free (and maybe set it to NULL to avoid double-free or somesuch), or you will leak memory.

I heavily suggest re-reading the kernel doc info for every rfkill function you're using. They're well described and documented, including caveats such as the one above.

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 1004

Quoted 2 lines
drivers/misc/acer-wmi.c +2 -0
+	if (!rfkill_workqueue)
+		return -ENOMEM;

Needs to dealocate the stuff you alocated, unless the caller will do so.

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 1017

Quoted 3 lines
drivers/misc/acer-wmi.c +3 -0
+	destroy_workqueue(rfkill_workqueue);
+	rfkill_unregister(wireless_rfkill);
+	rfkill_free(wireless_rfkill);

I know it is somewhat surprising, but you must never rfkill_free something you have called rfkill_unregister on. You use rfkill_free only to get rid of memory when rfkill_register fails.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#5 lore raw

RFC 1/1 acer-wmi: Add rfkill support for wireless and bluetooth (v3)

acer-wmi: Add rfkill support for wireless and bluetooth

From: Carlos Corbacho <[email protected]>

This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

For now, we will always poll these devices once a second to guarantee we can catch state changes. On newer Acer laptops, it may be possible to rely on WMI events to do this instead, and experimental support for this will be added in a later patch.

3G has been deliberately left off for now, as we still have no way to detect it, (nor, AFAIK, has any Linux user tried the code) and on laptops that don't support 3G, trying to poll for the status will leave the logs full of ACPI tracebacks.

The old sysfs interface for wireless and 3G will be removed in a later patch.

---

 drivers/misc/Kconfig    |    1 
 drivers/misc/acer-wmi.c |  128 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 1 deletions(-)
drivers/misc/Kconfig +1 -0
index a726f3b..6abb959 100644
@@ -145,6 +145,7 @@ config ACER_WMI
 	depends on NEW_LEDS
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on SERIO_I8042
+	depends on RFKILL
 	select ACPI_WMI
 	---help---
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
drivers/misc/acer-wmi.c +127 -1

158 lines not on this page · raw message

#6 lore raw

Re: [RFC] acer-wmi: Add rfkill support for wireless and bluetooth (v3)

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 951

Quoted 3 lines · Carlos Corbacho
drivers/misc/acer-wmi.c +3 -0
+	status = get_u32(&state, ACER_CAP_WIRELESS);
+	if (ACPI_SUCCESS(status))
+		rfkill_force_state(wireless_rfkill, state);

Please fix all calls to rfkill_force_state(). Refer to my previous post on this thread.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#7 lore raw

RFC 1/1 acer-wmi: Add rfkill support for wireless and bluetooth (v4)

This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

For now, we will always poll these devices once a second to guarantee we can catch state changes. On newer Acer laptops, it may be possible to rely on WMI events to do this instead, and experimental support for this will be added in a later patch.

3G has been deliberately left off for now, as we still have no way to detect it, (nor, AFAIK, has any Linux user tried the code) and on laptops that don't support 3G, trying to poll for the status will leave the logs full of ACPI tracebacks.

The old sysfs interface for wireless and 3G will be removed in a later patch.

---

 drivers/misc/Kconfig    |    1 
 drivers/misc/acer-wmi.c |  131 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 1 deletions(-)
drivers/misc/Kconfig +1 -0
index a726f3b..6abb959 100644
@@ -145,6 +145,7 @@ config ACER_WMI
 	depends on NEW_LEDS
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on SERIO_I8042
+	depends on RFKILL
 	select ACPI_WMI
 	---help---
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
drivers/misc/acer-wmi.c +130 -1

161 lines not on this page · raw message

Acked-by on v1 1/1
#8 lore raw

Re: [RFC] acer-wmi: Add rfkill support for wireless and bluetooth (v4)

Seems good at first glance, I have no further reservations about this patch.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

A message that is not in the archive (sent off-list or not yet received): 200809122044.27418.carlos-8YloKY0SPvpS8uBCpOlSjPXRex20P6io@public.gmane.org

#10 lore raw

Re: [RFC] acer-wmi: Add rfkill support for wireless and bluetooth (v4)

Hi Carlos,

Quoted 24 lines · Carlos Corbacho
drivers/misc/acer-wmi.c +24 -0
+
+static int acer_rfkill_register(struct device *dev, struct rfkill **rfkill_dev,
+enum rfkill_type type, char *name, u32 cap)
+{
+	int err;
+	u32 state;
+	u32 *data;
+
+	*rfkill_dev = rfkill_allocate(dev, type);
+	if (!*rfkill_dev)
+		return -ENOMEM;
+	(*rfkill_dev)->name = name;
+	get_u32(&state, cap);
+	(*rfkill_dev)->state = state ? RFKILL_STATE_UNBLOCKED :
+		RFKILL_STATE_SOFT_BLOCKED;
+	data = kzalloc(sizeof(u32), GFP_KERNEL);
+	if (!data) {
+		rfkill_free(*rfkill_dev);
+		return -ENOMEM;
+	}
+	*data = cap;
+	(*rfkill_dev)->data = data;
+	(*rfkill_dev)->toggle_radio = acer_rfkill_set;
+	(*rfkill_dev)->user_claim_unsupported = 1;

drivers/misc/acer-wmi.c static void acer_backlight_exit(void) · line 1008

Quoted 10 lines
drivers/misc/acer-wmi.c +10 -0
+
+	err = rfkill_register(*rfkill_dev);
+	if (err) {
+		kfree((*rfkill_dev)->data);
+		rfkill_free(*rfkill_dev);
+		return err;
+	}
+	return 0;
+}
+

Sorry if I am late to the party but this function is best to have 'struct rfkill *' return value and use ERR_PTR() to signal errors.

Signature · 5 lines
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20080912164039.ZZRA012-NG0XCrj25/[email protected]

#12 lore raw

RFC 1/1 acer-wmi: Add rfkill support for wireless and bluetooth (v5)

This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

For now, we will always poll these devices once a second to guarantee we can catch state changes. On newer Acer laptops, it may be possible to rely on WMI events to do this instead, and experimental support for this will be added in a later patch.

3G has been deliberately left off for now, as we still have no way to detect it, (nor, AFAIK, has any Linux user tried the code) and on laptops that don't support 3G, trying to poll for the status will leave the logs full of ACPI tracebacks.

The old sysfs interface for wireless and 3G will be removed in a later patch.

---

 drivers/misc/Kconfig    |    1 
 drivers/misc/acer-wmi.c |  130 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 1 deletions(-)
drivers/misc/Kconfig +1 -0
index a726f3b..6abb959 100644
@@ -145,6 +145,7 @@ config ACER_WMI
 	depends on NEW_LEDS
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on SERIO_I8042
+	depends on RFKILL
 	select ACPI_WMI
 	---help---
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
drivers/misc/acer-wmi.c +129 -1

160 lines not on this page · raw message

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 200809122304.21000.carlos-8YloKY0SPvpS8uBCpOlSjPXRex20P6io@public.gmane.org

#14 lore raw

Re: [RFC] acer-wmi: Add rfkill support for wireless and bluetooth (v5)

Quoted 2 lines · Carlos Corbacho

This patch implements rfkill support for the wireless and bluetooth devices commonly found on Acer laptops.

Yep, looks good, thanks.

Signature · 5 lines
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html