From 6191131ae72ac6432062dca15e8a7eb5c8b43f02 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 12 Feb 2018 13:05:49 +0000 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/1655982 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../include/tegra_asoc_machine_alt.h | 8 ++--- .../tegra_machine_driver_mobile.c | 17 +++++---- .../tegra-alt/utils/tegra_asoc_machine_alt.c | 35 +++++++------------ 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/sound/soc/tegra-alt/include/tegra_asoc_machine_alt.h b/sound/soc/tegra-alt/include/tegra_asoc_machine_alt.h index cf0ca06d..e6fbb734 100644 --- a/sound/soc/tegra-alt/include/tegra_asoc_machine_alt.h +++ b/sound/soc/tegra-alt/include/tegra_asoc_machine_alt.h @@ -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_bclk_ratio( - struct snd_soc_pcm_runtime *rtd); +int tegra_machine_get_bclk_ratio(struct snd_soc_pcm_runtime *rtd, + unsigned int *ratio); unsigned int tegra_machine_get_rx_mask( struct snd_soc_pcm_runtime *rtd); 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_bclk_ratio_t18x( - struct snd_soc_pcm_runtime *rtd); +int tegra_machine_get_bclk_ratio_t18x(struct snd_soc_pcm_runtime *rtd, + unsigned int *ratio); unsigned int tegra_machine_get_rx_mask_t18x( struct snd_soc_pcm_runtime *rtd); unsigned int tegra_machine_get_tx_mask_t18x( diff --git a/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c b/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c index 92210da0..0d7188a6 100644 --- a/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c +++ b/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c @@ -92,7 +92,7 @@ struct tegra_machine_soc_data { write_idle_bias_off_state; /* 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_codec_conf *(*get_codec_conf)(void); 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; fmt = rtd->dai_link->dai_fmt; - bclk_ratio = - machine->soc_data->get_bclk_ratio(rtd); - if (bclk_ratio >= 0) { - err = snd_soc_dai_set_bclk_ratio( - rtd->cpu_dai, - bclk_ratio); + err = machine->soc_data->get_bclk_ratio(rtd, + &bclk_ratio); + if (err < 0) { + 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) { dev_err(card->dev, "Failed to set cpu dai bclk ratio for %s\n", diff --git a/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c b/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c index b86873e2..9a73e72f 100644 --- a/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c +++ b/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c @@ -3254,28 +3254,23 @@ err: } EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx); -unsigned int tegra_machine_get_bclk_ratio( - struct snd_soc_pcm_runtime *rtd) +int tegra_machine_get_bclk_ratio(struct snd_soc_pcm_runtime *rtd, + unsigned int *ratio) { struct snd_soc_dai_link *codec_dai_link = rtd->dai_link; char *codec_name = (char *)codec_dai_link->name; - unsigned int idx = - tegra_machine_get_codec_dai_link_idx(codec_name); + unsigned int idx = tegra_machine_get_codec_dai_link_idx(codec_name); - if (idx == -EINVAL) - goto err; - - if (!bclk_ratio) - goto err; + if (idx == -EINVAL || !ratio || !bclk_ratio) + return -EINVAL; idx = idx - ((of_machine_is_compatible("nvidia,tegra210") || of_machine_is_compatible("nvidia,tegra210b01")) ? TEGRA210_XBAR_DAI_LINKS : 0); - return bclk_ratio[idx]; + *ratio = bclk_ratio[idx]; -err: - return -EINVAL; + return 0; } EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio); @@ -3513,8 +3508,8 @@ err: } EXPORT_SYMBOL_GPL(tegra_machine_get_codec_dai_link_idx_t18x); -unsigned int tegra_machine_get_bclk_ratio_t18x( - struct snd_soc_pcm_runtime *rtd) +int tegra_machine_get_bclk_ratio_t18x(struct snd_soc_pcm_runtime *rtd, + unsigned int *ratio) { struct snd_soc_dai_link *codec_dai_link = rtd->dai_link; 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 = tegra_machine_get_bclk_ratio_array(); - if (idx == -EINVAL) - goto err; - - if (!bclk_ratio_t18x) - goto err; + if (idx == -EINVAL || !ratio || !bclk_ratio_t18x) + return -EINVAL; idx = idx - tegra_machine_get_num_links_t18x(); - return bclk_ratio_t18x[idx]; + *ratio = bclk_ratio_t18x[idx]; -err: - return -EINVAL; + return 0; } EXPORT_SYMBOL_GPL(tegra_machine_get_bclk_ratio_t18x);