mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-22 17:25:35 +03:00
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:
@@ -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(
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user