From f0ebf9d9c4a58d373a64df9b6f9835c88d427bb8 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 12 Mar 2018 13:55:01 +0000 Subject: [PATCH] ASoC: tegra-alt: Fix restoration of mixer controls When using the ALSA 'alsactl' tool to save and restore mixer settings the following type of errors are observed ... alsactl: set_control:1461: Cannot write control '2:0:0:ADMAIF1 Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:AMX1 Output Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:RX1 Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:TX1 Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:TX5 Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:SFC1 Channels:0' : Invalid argument ... alsactl: set_control:1461: Cannot write control '2:0:0:MVC1 Bits:0' : Invalid argument These are just a few examples but these errors are seen for all instances of the devices. The problem is that the 'put' handler for the above mixer controls treats '0' as an invalid setting and so if the default value is '0', then when we try to restore the setting to '0' it fails because this is consider an 'invalid argument'. However, '0' is not a invalid argument, it simply means that we are not overriding this setting from userspace. Furthermore, if someone happens to set an of the above mixer controls to a non-zero value, then it is not possible to set it back to '0' again. Fix this by allowing userspace to set the above mixer controls to '0'. Bug 2058979 Change-Id: Icd543c2ea956cb0690238d9a1f184c144a572029 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/1675098 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions --- sound/soc/tegra-alt/tegra210_admaif_alt.c | 4 ++-- sound/soc/tegra-alt/tegra210_amx_alt.c | 6 +++--- sound/soc/tegra-alt/tegra210_mixer_alt.c | 4 ++-- sound/soc/tegra-alt/tegra210_mvc_alt.c | 4 +++- sound/soc/tegra-alt/tegra210_sfc_alt.c | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sound/soc/tegra-alt/tegra210_admaif_alt.c b/sound/soc/tegra-alt/tegra210_admaif_alt.c index 4ec57208..4bf15768 100644 --- a/sound/soc/tegra-alt/tegra210_admaif_alt.c +++ b/sound/soc/tegra-alt/tegra210_admaif_alt.c @@ -1,7 +1,7 @@ /* * tegra210_admaif_alt.c - Tegra ADMAIF driver * - * Copyright (c) 2014-2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -570,7 +570,7 @@ static int tegra_admaif_put_format(struct snd_kcontrol *kcontrol, char buf[50]; if (strstr(kcontrol->id.name, "Channels")) { - if (value > 0 && value <= 16) + if (value >= 0 && value <= 16) admaif->override_channels[mc->reg] = value; else return -EINVAL; diff --git a/sound/soc/tegra-alt/tegra210_amx_alt.c b/sound/soc/tegra-alt/tegra210_amx_alt.c index e63eeadd..ab166f5a 100644 --- a/sound/soc/tegra-alt/tegra210_amx_alt.c +++ b/sound/soc/tegra-alt/tegra210_amx_alt.c @@ -1,7 +1,7 @@ /* * tegra210_amx_alt.c - Tegra210 AMX driver * - * Copyright (c) 2014-2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -574,12 +574,12 @@ static int tegra210_amx_put_channels(struct snd_kcontrol *kcontrol, snprintf(buf, 50, "Input%d Channels", reg); if (strstr(kcontrol->id.name, buf)) { - if (value > 0 && value <= 16) + if (value >= 0 && value <= 16) amx->input_channels[reg - 1] = value; else return -EINVAL; } else if (strstr(kcontrol->id.name, "Output Channels")) { - if (value > 0 && value <= 16) + if (value >= 0 && value <= 16) amx->output_channels = value; else return -EINVAL; diff --git a/sound/soc/tegra-alt/tegra210_mixer_alt.c b/sound/soc/tegra-alt/tegra210_mixer_alt.c index bbc18aab..be9069a5 100644 --- a/sound/soc/tegra-alt/tegra210_mixer_alt.c +++ b/sound/soc/tegra-alt/tegra210_mixer_alt.c @@ -1,7 +1,7 @@ /* * tegra210_mixer_alt.c - Tegra210 MIXER driver * - * Copyright (c) 2014-2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -155,7 +155,7 @@ static int tegra210_mixer_put_format(struct snd_kcontrol *kcontrol, int value = ucontrol->value.integer.value[0]; if (strstr(kcontrol->id.name, "Channels")) { - if (value > 0 && value <= 8) + if (value >= 0 && value <= 8) mixer->channels_via_control[mc->reg - 1] = value; else return -EINVAL; diff --git a/sound/soc/tegra-alt/tegra210_mvc_alt.c b/sound/soc/tegra-alt/tegra210_mvc_alt.c index 16f490d3..efb40915 100644 --- a/sound/soc/tegra-alt/tegra210_mvc_alt.c +++ b/sound/soc/tegra-alt/tegra210_mvc_alt.c @@ -1,7 +1,7 @@ /* * tegra210_mvc_alt.c - Tegra210 MVC driver * - * Copyright (c) 2014-2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -304,6 +304,8 @@ static int tegra210_mvc_put_audio_bits(struct snd_kcontrol *kcontrol, val = ucontrol->value.integer.value[0]; if ((val >= 8) && (val <= 32) && (val%4 == 0)) mvc->audio_bits = val/4 - 1; + else if (val == 0) + mvc->audio_bits = 0; else return -EINVAL; diff --git a/sound/soc/tegra-alt/tegra210_sfc_alt.c b/sound/soc/tegra-alt/tegra210_sfc_alt.c index 9724932d..51eb4130 100644 --- a/sound/soc/tegra-alt/tegra210_sfc_alt.c +++ b/sound/soc/tegra-alt/tegra210_sfc_alt.c @@ -1,7 +1,7 @@ /* * tegra210_sfc_alt.c - Tegra210 SFC driver * - * Copyright (c) 2014-2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -499,7 +499,7 @@ static int tegra210_sfc_put_format(struct snd_kcontrol *kcontrol, else if (strstr(kcontrol->id.name, "output")) sfc->format_out = value; else if (strstr(kcontrol->id.name, "Channels")) { - if (value > 0 && value <= 2) + if (value >= 0 && value <= 2) sfc->channels_via_control = value; else return -EINVAL;