From 31768a08d9f276332368f612c010e35d7b4370a2 Mon Sep 17 00:00:00 2001 From: Chengyi Zhao Date: Thu, 23 Dec 2021 21:32:07 +0800 Subject: [PATCH] bluetooth: Initialize profile with both input and output directions If this module initializes a profile with both input and output directions, in fact, when the add_sink function fails, there is no need to continue execute the add_source function. --- src/modules/bluetooth/module-bluez5-device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c index 767482e4a..2685c127a 100644 --- a/src/modules/bluetooth/module-bluez5-device.c +++ b/src/modules/bluetooth/module-bluez5-device.c @@ -1400,13 +1400,18 @@ static int init_profile(struct userdata *u) { pa_assert(u->transport); - if (get_profile_direction (u->profile) & PA_DIRECTION_OUTPUT) + /* For a profile with both input and output directions */ + if ((get_profile_direction (u->profile) & PA_DIRECTION_OUTPUT) && + (get_profile_direction (u->profile) & PA_DIRECTION_INPUT)) { + if (add_sink(u) < 0 || add_source(u) < 0) + r = -1; + } else if (get_profile_direction (u->profile) & PA_DIRECTION_OUTPUT) { if (add_sink(u) < 0) r = -1; - - if (get_profile_direction (u->profile) & PA_DIRECTION_INPUT) + } else if (get_profile_direction (u->profile) & PA_DIRECTION_INPUT) { if (add_source(u) < 0) r = -1; + } return r; }