* [PATCH 3/3] Maemo6 MCE: handle race condition at startup
@ 2010-08-13 9:19 Daniel Örstadius
2010-08-18 11:25 ` Daniel Örstadius
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-13 9:19 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 415 bytes --]
Since bluetoothd power cycles the adapter at startup, it is possible
that the plugin gets a reply from reading the state of the MCE and
tries to power the adapter before it is down. The patch checks for
that situation and if it occurs postpones powering the adapter to
the mode change callback. The off_requested member of btd_adapter
is used for the check, so it is set to FALSE when the adapter is
down.
/Daniel
[-- Attachment #2: 0001-Maemo6-MCE-handle-race-condition-at-startup.patch --]
[-- Type: text/x-patch, Size: 2622 bytes --]
From 16455aa43369853f2724d16751a41724df9a4fd5 Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Fri, 13 Aug 2010 11:41:37 +0300
Subject: [PATCH] Maemo6 MCE: handle race condition at startup
Since bluetoothd power cycles the adapter at startup, it is possible
that the plugin gets a reply from reading the state of the MCE and
tries to power the adapter before it is down. The patch checks for
that situation and if it occurs postpones powering the adapter to
the mode change callback. The off_requested member of btd_adapter
is used for the check, so it is set to FALSE when the adapter is
down.
---
plugins/maemo6.c | 24 ++++++++++++++++++++++++
src/adapter.c | 1 +
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/plugins/maemo6.c b/plugins/maemo6.c
index 20e5c00..4a04fa9 100644
--- a/plugins/maemo6.c
+++ b/plugins/maemo6.c
@@ -50,6 +50,7 @@
static guint watch_id;
static DBusConnection *conn = NULL;
static gboolean mce_bt_set = FALSE;
+static gboolean collision = FALSE;
static gboolean mce_signal_callback(DBusConnection *connection,
DBusMessage *message, void *user_data)
@@ -112,6 +113,14 @@ static void read_radio_states_cb(DBusPendingCall *call, void *user_data)
mce_bt_set = radio_states & MCE_RADIO_STATE_BLUETOOTH;
+ /* check if the adapter has not completed the initial power
+ cycle, if so delay action to mce_notify_powered */
+
+ collision = adapter_powering_down(adapter);
+
+ if (collision)
+ goto done;
+
if (mce_bt_set)
btd_adapter_switch_online(adapter);
else
@@ -133,6 +142,21 @@ static void adapter_mode_change(struct btd_adapter *adapter, gboolean powered)
if (mce_bt_set == powered)
return;
+ /* check if the plugin got the reply from the mce when the
+ adapter was not yet down during the power cycling when
+ bluetoothd is started */
+ if (collision) {
+ error("maemo6: collision");
+ collision = FALSE;
+
+ if (mce_bt_set)
+ btd_adapter_switch_online(adapter);
+ else
+ btd_adapter_switch_offline(adapter);
+
+ return;
+ }
+
/* set the mce value according to the state of the adapter */
msg = dbus_message_new_method_call(MCE_SERVICE, MCE_REQUEST_PATH,
MCE_REQUEST_IF, MCE_RADIO_STATES_CHANGE_REQ);
diff --git a/src/adapter.c b/src/adapter.c
index ff78539..712ca08 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2502,6 +2502,7 @@ int adapter_stop(struct btd_adapter *adapter)
adapter->state = DISCOVER_TYPE_NONE;
adapter->cache_enable = TRUE;
adapter->pending_cod = 0;
+ adapter->off_requested = FALSE;
adapter_mode_callbacks(adapter, FALSE);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] Maemo6 MCE: handle race condition at startup
2010-08-13 9:19 [PATCH 3/3] Maemo6 MCE: handle race condition at startup Daniel Örstadius
@ 2010-08-18 11:25 ` Daniel Örstadius
2010-08-18 13:20 ` Daniel Örstadius
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-18 11:25 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 558 bytes --]
On Fri, Aug 13, 2010 at 12:19 PM, Daniel Örstadius
<daniel.orstadius@gmail.com> wrote:
> Since bluetoothd power cycles the adapter at startup, it is possible
> that the plugin gets a reply from reading the state of the MCE and
> tries to power the adapter before it is down. The patch checks for
> that situation and if it occurs postpones powering the adapter to
> the mode change callback. The off_requested member of btd_adapter
> is used for the check, so it is set to FALSE when the adapter is
> down.
>
Attaching updated patch.
/Daniel
[-- Attachment #2: 0001-Maemo6-MCE-handle-race-condition-at-startup.patch --]
[-- Type: text/x-patch, Size: 2533 bytes --]
From ab1249f50673d6da226c1d8f490b962d999fd890 Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Wed, 18 Aug 2010 14:22:31 +0300
Subject: [PATCH] Maemo6 MCE: handle race condition at startup
Since bluetoothd power cycles the adapter at startup, it is possible
that the plugin gets a reply from reading the state of the MCE and
tries to power the adapter before it is down. The patch checks for
that situation and if it occurs postpones powering the adapter to
the powered state callback. The off_requested member of btd_adapter
is used for the check, so it is set to FALSE when the adapter is
down.
---
plugins/maemo6.c | 22 ++++++++++++++++++++++
src/adapter.c | 1 +
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/plugins/maemo6.c b/plugins/maemo6.c
index 55ea508..ad86c30 100644
--- a/plugins/maemo6.c
+++ b/plugins/maemo6.c
@@ -50,6 +50,7 @@
static guint watch_id;
static DBusConnection *conn = NULL;
static gboolean mce_bt_set = FALSE;
+static gboolean collision = FALSE;
static gboolean mce_signal_callback(DBusConnection *connection,
DBusMessage *message, void *user_data)
@@ -112,6 +113,14 @@ static void read_radio_states_cb(DBusPendingCall *call, void *user_data)
mce_bt_set = radio_states & MCE_RADIO_STATE_BLUETOOTH;
+ /* check if the adapter has not completed the initial power
+ cycle, if so delay action to mce_notify_powered */
+
+ collision = mce_bt_set && adapter_powering_down(adapter);
+
+ if (collision)
+ goto done;
+
if (mce_bt_set)
btd_adapter_switch_online(adapter);
else
@@ -129,6 +138,19 @@ static void adapter_powered(struct btd_adapter *adapter, gboolean powered)
DBG("adapter_powered called with %d", powered);
+ /* check if the plugin got the get_radio_states reply from the
+ mce when the adapter was not yet down during the power
+ cycling when bluetoothd is started */
+ if (collision) {
+ error("maemo6: powered state collision");
+ collision = FALSE;
+
+ if (mce_bt_set)
+ btd_adapter_switch_online(adapter);
+
+ return;
+ }
+
/* nothing to do if the states match */
if (mce_bt_set == powered)
return;
diff --git a/src/adapter.c b/src/adapter.c
index 4ad4165..98db2d5 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2502,6 +2502,7 @@ int adapter_stop(struct btd_adapter *adapter)
adapter->state = DISCOVER_TYPE_NONE;
adapter->cache_enable = TRUE;
adapter->pending_cod = 0;
+ adapter->off_requested = FALSE;
call_adapter_powered_callbacks(adapter, FALSE);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] Maemo6 MCE: handle race condition at startup
2010-08-18 11:25 ` Daniel Örstadius
@ 2010-08-18 13:20 ` Daniel Örstadius
2010-08-18 13:33 ` Johan Hedberg
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-18 13:20 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
On Wed, Aug 18, 2010 at 2:25 PM, Daniel Örstadius
<daniel.orstadius@gmail.com> wrote:
> On Fri, Aug 13, 2010 at 12:19 PM, Daniel Örstadius
> <daniel.orstadius@gmail.com> wrote:
>> Since bluetoothd power cycles the adapter at startup, it is possible
>> that the plugin gets a reply from reading the state of the MCE and
>> tries to power the adapter before it is down. The patch checks for
>> that situation and if it occurs postpones powering the adapter to
>> the mode change callback. The off_requested member of btd_adapter
>> is used for the check, so it is set to FALSE when the adapter is
>> down.
>>
>
> Attaching updated patch.
>
Patch without the off_requested part.
/Daniel
[-- Attachment #2: 0001-Maemo6-MCE-handle-race-condition-at-startup.patch --]
[-- Type: text/x-patch, Size: 2027 bytes --]
From 3160d36371fe7c95ecd5a4eb3e167ac374dbc4d4 Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Wed, 18 Aug 2010 15:48:28 +0300
Subject: [PATCH] Maemo6 MCE: handle race condition at startup
Since bluetoothd power cycles the adapter at startup, it is possible
that the plugin gets a reply from reading the state of the MCE and
tries to power the adapter before it is down. The patch checks for
that situation and if it occurs postpones powering the adapter to
the powered state callback.
---
plugins/maemo6.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/plugins/maemo6.c b/plugins/maemo6.c
index 55ea508..ad86c30 100644
--- a/plugins/maemo6.c
+++ b/plugins/maemo6.c
@@ -50,6 +50,7 @@
static guint watch_id;
static DBusConnection *conn = NULL;
static gboolean mce_bt_set = FALSE;
+static gboolean collision = FALSE;
static gboolean mce_signal_callback(DBusConnection *connection,
DBusMessage *message, void *user_data)
@@ -112,6 +113,14 @@ static void read_radio_states_cb(DBusPendingCall *call, void *user_data)
mce_bt_set = radio_states & MCE_RADIO_STATE_BLUETOOTH;
+ /* check if the adapter has not completed the initial power
+ cycle, if so delay action to mce_notify_powered */
+
+ collision = mce_bt_set && adapter_powering_down(adapter);
+
+ if (collision)
+ goto done;
+
if (mce_bt_set)
btd_adapter_switch_online(adapter);
else
@@ -129,6 +138,19 @@ static void adapter_powered(struct btd_adapter *adapter, gboolean powered)
DBG("adapter_powered called with %d", powered);
+ /* check if the plugin got the get_radio_states reply from the
+ mce when the adapter was not yet down during the power
+ cycling when bluetoothd is started */
+ if (collision) {
+ error("maemo6: powered state collision");
+ collision = FALSE;
+
+ if (mce_bt_set)
+ btd_adapter_switch_online(adapter);
+
+ return;
+ }
+
/* nothing to do if the states match */
if (mce_bt_set == powered)
return;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] Maemo6 MCE: handle race condition at startup
2010-08-18 13:20 ` Daniel Örstadius
@ 2010-08-18 13:33 ` Johan Hedberg
0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-08-18 13:33 UTC (permalink / raw)
To: Daniel Örstadius; +Cc: linux-bluetooth
Hi Daniel,
On Wed, Aug 18, 2010, Daniel Örstadius wrote:
> Patch without the off_requested part.
>
> /Daniel
>
> From 3160d36371fe7c95ecd5a4eb3e167ac374dbc4d4 Mon Sep 17 00:00:00 2001
> From: Daniel Orstadius <daniel.orstadius@nokia.com>
> Date: Wed, 18 Aug 2010 15:48:28 +0300
> Subject: [PATCH] Maemo6 MCE: handle race condition at startup
>
> Since bluetoothd power cycles the adapter at startup, it is possible
> that the plugin gets a reply from reading the state of the MCE and
> tries to power the adapter before it is down. The patch checks for
> that situation and if it occurs postpones powering the adapter to
> the powered state callback.
> ---
> plugins/maemo6.c | 22 ++++++++++++++++++++++
> 1 files changed, 22 insertions(+), 0 deletions(-)
Thanks. This one is now also upstream.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-18 13:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-13 9:19 [PATCH 3/3] Maemo6 MCE: handle race condition at startup Daniel Örstadius
2010-08-18 11:25 ` Daniel Örstadius
2010-08-18 13:20 ` Daniel Örstadius
2010-08-18 13:33 ` Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox