[pulseaudio-discuss] [PATCH 3/7] alsa, bluetooth: fail if user-requested profile doesn't exist
David Henningsson
david.henningsson at canonical.com
Mon Oct 26 02:57:00 PDT 2015
On 2015-10-23 12:56, Tanu Kaskinen wrote:
> If we can't fulfill the user request fully, I think we shouldn't
> fulfill it at all, to make it clear that the requested operation
> didn't succeed.
> ---
> src/modules/alsa/module-alsa-card.c | 10 ++++++++--
> src/modules/bluetooth/module-bluez4-device.c | 6 ++++--
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
> index e173e51..0943a17 100644
> --- a/src/modules/alsa/module-alsa-card.c
> +++ b/src/modules/alsa/module-alsa-card.c
> @@ -768,8 +768,14 @@ int pa__init(pa_module *m) {
> goto fail;
> }
>
> - if ((profile = pa_modargs_get_value(u->modargs, "profile", NULL)))
> - pa_card_new_data_set_profile(&data, profile);
> + if ((profile = pa_modargs_get_value(u->modargs, "profile", NULL))) {
> + if (pa_hashmap_get(data.profiles, profile))
> + pa_card_new_data_set_profile(&data, profile);
> + else {
> + pa_log("No such profile: %s", profile);
> + goto fail;
> + }
> + }
>
> u->card = pa_card_new(m->core, &data);
> pa_card_new_data_done(&data);
> diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c
> index af36e6a..41b436f 100644
> --- a/src/modules/bluetooth/module-bluez4-device.c
> +++ b/src/modules/bluetooth/module-bluez4-device.c
> @@ -2307,8 +2307,10 @@ static int add_card(struct userdata *u) {
> if ((default_profile = pa_modargs_get_value(u->modargs, "profile", NULL))) {
> if (pa_hashmap_get(data.profiles, default_profile))
> pa_card_new_data_set_profile(&data, default_profile);
> - else
> - pa_log_warn("Profile '%s' not valid or not supported by device.", default_profile);
> + else {
> + pa_log("Profile '%s' not valid or not supported by device.", default_profile);
> + return -1;
This will leak at least a pa_card_profile and a pa_card_new_data object.
Otherwise okay with the behavior change in general - that said, I
haven't checked if we tend to add this somewhere so that this module
argument is more widely used than we think. Have you?
> + }
> }
>
> u->card = pa_card_new(u->core, &data);
>
--
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
More information about the pulseaudio-discuss
mailing list