diff mbox series

device: Return error when ConnectProfile DBus method fails

Message ID 20200423233243.14937-1-pali@kernel.org (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series device: Return error when ConnectProfile DBus method fails | expand

Commit Message

Pali Rohár April 23, 2020, 11:32 p.m. UTC
Without this patch ConnectProfile DBus method does not return failure if
profile connection failed and some other profile was already connected.
This is not correct behavior as ConnectProfile DBus method should always
return error when specified profile failed to connect. This patch fixes
this it.
---
 src/device.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Luiz Augusto von Dentz April 24, 2020, 5:26 p.m. UTC | #1
Hi Pali,

On Thu, Apr 23, 2020 at 4:36 PM Pali Rohár <pali@kernel.org> wrote:
>
> Without this patch ConnectProfile DBus method does not return failure if
> profile connection failed and some other profile was already connected.
> This is not correct behavior as ConnectProfile DBus method should always
> return error when specified profile failed to connect. This patch fixes
> this it.
> ---
>  src/device.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/device.c b/src/device.c
> index a8d95346a..7ab30705f 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -1584,6 +1584,7 @@ static void device_profile_connected(struct btd_device *dev,
>                                         struct btd_profile *profile, int err)
>  {
>         struct btd_service *pending;
> +       bool report_error;
>         GSList *l;
>
>         DBG("%s %s (%d)", profile->name, strerror(-err), -err);
> @@ -1632,9 +1633,16 @@ done:
>
>         DBG("returning response to %s", dbus_message_get_sender(dev->connect));
>
> -       l = find_service_with_state(dev->services, BTD_SERVICE_STATE_CONNECTED);
> +       if (err && dbus_message_is_method_call(dev->connect, DEVICE_INTERFACE,
> +                                       "ConnectProfile"))
> +               report_error = true;
> +       else if (err && !find_service_with_state(dev->services,
> +                                       BTD_SERVICE_STATE_CONNECTED))
> +               report_error = true;
> +       else
> +               report_error = false;
>
> -       if (err && l == NULL) {
> +       if (report_error) {
>                 /* Fallback to LE bearer if supported */
>                 if (err == -EHOSTDOWN && dev->le && !dev->le_state.connected) {
>                         err = device_connect_le(dev);
> --
> 2.20.1

Applied, notice that I did some changes to make it a little more
simple but the end result is the same.
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index a8d95346a..7ab30705f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1584,6 +1584,7 @@  static void device_profile_connected(struct btd_device *dev,
 					struct btd_profile *profile, int err)
 {
 	struct btd_service *pending;
+	bool report_error;
 	GSList *l;
 
 	DBG("%s %s (%d)", profile->name, strerror(-err), -err);
@@ -1632,9 +1633,16 @@  done:
 
 	DBG("returning response to %s", dbus_message_get_sender(dev->connect));
 
-	l = find_service_with_state(dev->services, BTD_SERVICE_STATE_CONNECTED);
+	if (err && dbus_message_is_method_call(dev->connect, DEVICE_INTERFACE,
+					"ConnectProfile"))
+		report_error = true;
+	else if (err && !find_service_with_state(dev->services,
+					BTD_SERVICE_STATE_CONNECTED))
+		report_error = true;
+	else
+		report_error = false;
 
-	if (err && l == NULL) {
+	if (report_error) {
 		/* Fallback to LE bearer if supported */
 		if (err == -EHOSTDOWN && dev->le && !dev->le_state.connected) {
 			err = device_connect_le(dev);