ASoC: tegra-alt: Fix return type for getting the bclk ratio

The functions tegra_machine_get_bclk_ratio() and
tegra_machine_get_bclk_ratio_t18x() have a return type of unsigned int
but can return a negative error code on failure. This may cause users
of this function to get a very large bit clock ratio. Although it is
improbable that the bit clock ratio will ever be large enough to
overflow a signed integer, it is best to avoid changing the type of
the bit clock ratio variable. Therefore, return the bit clock ratio
via a pointer passed to the functions tegra_machine_get_bclk_ratio()
and tegra_machine_get_bclk_ratio_t18x().

Bug 2025176

Change-Id: Ia6e9a1ef68f53ebb594746f812de65a18269925f
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1655982
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Jon Hunter
2018-02-12 13:05:49 +00:00
committed by Sameer Pujar
parent baa66924d1
commit 6191131ae7
3 changed files with 27 additions and 33 deletions

View File

@@ -393,8 +393,8 @@ struct snd_soc_codec_conf *tegra_machine_new_codec_conf(
unsigned int tegra_machine_get_codec_dai_link_idx(const char *codec_name); unsigned int tegra_machine_get_codec_dai_link_idx(const char *codec_name);
unsigned int tegra_machine_get_bclk_ratio( int tegra_machine_get_bclk_ratio(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_pcm_runtime *rtd); unsigned int *ratio);
unsigned int tegra_machine_get_rx_mask( unsigned int tegra_machine_get_rx_mask(
struct snd_soc_pcm_runtime *rtd); struct snd_soc_pcm_runtime *rtd);
unsigned int tegra_machine_get_tx_mask( unsigned int tegra_machine_get_tx_mask(
@@ -429,8 +429,8 @@ int tegra_machine_append_codec_conf_t18x(struct snd_soc_codec_conf *conf,
unsigned int tegra_machine_get_codec_dai_link_idx_t18x(const char *codec_name); unsigned int tegra_machine_get_codec_dai_link_idx_t18x(const char *codec_name);
unsigned int tegra_machine_get_bclk_ratio_t18x( int tegra_machine_get_bclk_ratio_t18x(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_pcm_runtime *rtd); unsigned int *ratio);
unsigned int tegra_machine_get_rx_mask_t18x( unsigned int tegra_machine_get_rx_mask_t18x(
struct snd_soc_pcm_runtime *rtd); struct snd_soc_pcm_runtime *rtd);
unsigned int tegra_machine_get_tx_mask_t18x( unsigned int tegra_machine_get_tx_mask_t18x(

View File

@@ -92,7 +92,7 @@ struct tegra_machine_soc_data {
write_idle_bias_off_state; write_idle_bias_off_state;
/* call back APIs */ /* call back APIs */
unsigned int (*get_bclk_ratio)(struct snd_soc_pcm_runtime *rtd); int (*get_bclk_ratio)(struct snd_soc_pcm_runtime *, unsigned int *);
struct snd_soc_dai_link *(*get_dai_link)(void); struct snd_soc_dai_link *(*get_dai_link)(void);
struct snd_soc_codec_conf *(*get_codec_conf)(void); struct snd_soc_codec_conf *(*get_codec_conf)(void);
int (*append_dai_link)(struct snd_soc_dai_link *link, int (*append_dai_link)(struct snd_soc_dai_link *link,
@@ -668,15 +668,18 @@ static int tegra_machine_set_params(struct snd_soc_card *card,
dai_params->formats = formats; dai_params->formats = formats;
fmt = rtd->dai_link->dai_fmt; fmt = rtd->dai_link->dai_fmt;
bclk_ratio =
machine->soc_data->get_bclk_ratio(rtd);
if (bclk_ratio >= 0) { err = machine->soc_data->get_bclk_ratio(rtd,
err = snd_soc_dai_set_bclk_ratio( &bclk_ratio);
rtd->cpu_dai, if (err < 0) {
bclk_ratio); dev_err(card->dev,
"Failed to get bclk ratio for %s\n",
rtd->dai_link->name);
return err;
} }
err = snd_soc_dai_set_bclk_ratio(rtd->cpu_dai,
bclk_ratio);
if (err < 0) { if (err < 0) {
dev_err(card->dev, dev_err(card->dev,
"Failed to set cpu dai bclk ratio for %s\n", "Failed to set cpu dai bclk ratio for %s\n",

View File

@@ -3254,28 +3254,23 @@ err:
} }
EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx); EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx);
unsigned int tegra_machine_get_bclk_ratio( int tegra_machine_get_bclk_ratio(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_pcm_runtime *rtd) unsigned int *ratio)
{ {
struct snd_soc_dai_link *codec_dai_link = rtd->dai_link; struct snd_soc_dai_link *codec_dai_link = rtd->dai_link;
char *codec_name = (char *)codec_dai_link->name; char *codec_name = (char *)codec_dai_link->name;
unsigned int idx = unsigned int idx = tegra_machine_get_codec_dai_link_idx(codec_name);
tegra_machine_get_codec_dai_link_idx(codec_name);
if (idx == -EINVAL) if (idx == -EINVAL || !ratio || !bclk_ratio)
goto err; return -EINVAL;
if (!bclk_ratio)
goto err;
idx = idx - ((of_machine_is_compatible("nvidia,tegra210") || idx = idx - ((of_machine_is_compatible("nvidia,tegra210") ||
of_machine_is_compatible("nvidia,tegra210b01")) ? of_machine_is_compatible("nvidia,tegra210b01")) ?
TEGRA210_XBAR_DAI_LINKS : 0); TEGRA210_XBAR_DAI_LINKS : 0);
return bclk_ratio[idx]; *ratio = bclk_ratio[idx];
err: return 0;
return -EINVAL;
} }
EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio); EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio);
@@ -3513,8 +3508,8 @@ err:
} }
EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx_t18x); EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx_t18x);
unsigned int tegra_machine_get_bclk_ratio_t18x( int tegra_machine_get_bclk_ratio_t18x(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_pcm_runtime *rtd) unsigned int *ratio)
{ {
struct snd_soc_dai_link *codec_dai_link = rtd->dai_link; struct snd_soc_dai_link *codec_dai_link = rtd->dai_link;
char *codec_name = (char *)codec_dai_link->name; char *codec_name = (char *)codec_dai_link->name;
@@ -3523,18 +3518,14 @@ unsigned int tegra_machine_get_bclk_ratio_t18x(
unsigned int *bclk_ratio_t18x = unsigned int *bclk_ratio_t18x =
tegra_machine_get_bclk_ratio_array(); tegra_machine_get_bclk_ratio_array();
if (idx == -EINVAL) if (idx == -EINVAL || !ratio || !bclk_ratio_t18x)
goto err; return -EINVAL;
if (!bclk_ratio_t18x)
goto err;
idx = idx - tegra_machine_get_num_links_t18x(); idx = idx - tegra_machine_get_num_links_t18x();
return bclk_ratio_t18x[idx]; *ratio = bclk_ratio_t18x[idx];
err: return 0;
return -EINVAL;
} }
EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio_t18x); EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio_t18x);