Linux Sound subsystem development
 help / color / mirror / Atom feed
From: "Thierry Reding" <thierry.reding@gmail.com>
To: "Sameer Pujar" <spujar@nvidia.com>, <broonie@kernel.org>,
	<linux-sound@vger.kernel.org>, <alsa-devel@alsa-project.org>
Cc: <linux-tegra@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<lgirdwood@gmail.com>, <jonathanh@nvidia.com>,
	<mkumard@nvidia.com>
Subject: Re: [PATCH v2 1/2] ASoC: simple-card-utils: Split simple_fixup_sample_fmt func
Date: Thu, 30 May 2024 13:02:59 +0200	[thread overview]
Message-ID: <D1MXG0PGXQW8.2GBRKOVBQM49H@gmail.com> (raw)
In-Reply-To: <20240527125608.2461300-2-spujar@nvidia.com>

[-- Attachment #1: Type: text/plain, Size: 3355 bytes --]

On Mon May 27, 2024 at 2:56 PM CEST, Sameer Pujar wrote:
> From: Mohan Kumar <mkumard@nvidia.com>
>
> Split the simple_fixup_sample_fmt() into two functions by adding
> one more function named simple_util_get_sample_fmt() to return
> the sample format value.
>
> This is useful for drivers that wish to simply get the sample format
> without setting the mask.
>
> Signed-off-by: Mohan Kumar <mkumard@nvidia.com>
> Signed-off-by: Sameer Pujar <spujar@nvidia.com>
> ---
>  include/sound/simple_card_utils.h     |  2 ++
>  sound/soc/generic/simple-card-utils.c | 26 ++++++++++++++++++++------
>  2 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
> index ad67957b7b48..2c2279d082ec 100644
> --- a/include/sound/simple_card_utils.h
> +++ b/include/sound/simple_card_utils.h
> @@ -174,6 +174,8 @@ void simple_util_parse_convert(struct device_node *np, char *prefix,
>  			       struct simple_util_data *data);
>  bool simple_util_is_convert_required(const struct simple_util_data *data);
>  
> +int simple_util_get_sample_fmt(struct simple_util_data *data);
> +
>  int simple_util_parse_routing(struct snd_soc_card *card,
>  				      char *prefix);
>  int simple_util_parse_widgets(struct snd_soc_card *card,
> diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
> index 81077d16d22f..f1f5a1c025fc 100644
> --- a/sound/soc/generic/simple-card-utils.c
> +++ b/sound/soc/generic/simple-card-utils.c
> @@ -13,12 +13,11 @@
>  #include <sound/pcm_params.h>
>  #include <sound/simple_card_utils.h>
>  
> -static void simple_fixup_sample_fmt(struct simple_util_data *data,
> -					 struct snd_pcm_hw_params *params)
> +int simple_util_get_sample_fmt(struct simple_util_data *data)
>  {
>  	int i;
> -	struct snd_mask *mask = hw_param_mask(params,
> -					      SNDRV_PCM_HW_PARAM_FORMAT);
> +	int val = -EINVAL;
> +
>  	struct {
>  		char *fmt;
>  		u32 val;
> @@ -33,11 +32,26 @@ static void simple_fixup_sample_fmt(struct simple_util_data *data,
>  	for (i = 0; i < ARRAY_SIZE(of_sample_fmt_table); i++) {
>  		if (!strcmp(data->convert_sample_format,
>  			    of_sample_fmt_table[i].fmt)) {
> -			snd_mask_none(mask);
> -			snd_mask_set(mask, of_sample_fmt_table[i].val);
> +			val = of_sample_fmt_table[i].val;
>  			break;
>  		}
>  	}
> +	return val;
> +}
> +EXPORT_SYMBOL_GPL(simple_util_get_sample_fmt);
> +
> +static void simple_fixup_sample_fmt(struct simple_util_data *data,
> +				    struct snd_pcm_hw_params *params)
> +{
> +	int val;
> +	struct snd_mask *mask = hw_param_mask(params,
> +					      SNDRV_PCM_HW_PARAM_FORMAT);
> +
> +	val = simple_util_get_sample_fmt(data);
> +	if (val >= 0) {

Maybe nothing that we need to worry about, but this could be potentially
a problem if the snd_pcm_format_t ever outgrows the non-negative number
space. snd_pcm_format_t is defined to be an int as well, so any very
large number would wrap into a negative value and then would be
considered an error in this check.

Then again, if that ever were to happen, we'd likely get a compiler
error for the snd_pcm_format_t overflowing, so we'd probably notice and
rewrite at that point.

So I suppose:

Reviewed-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-05-30 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 12:56 [PATCH v2 0/2] Support Tegra I2S client format conversion Sameer Pujar
2024-05-27 12:56 ` [PATCH v2 1/2] ASoC: simple-card-utils: Split simple_fixup_sample_fmt func Sameer Pujar
2024-05-30 11:02   ` Thierry Reding [this message]
2024-05-27 12:56 ` [PATCH v2 2/2] ASoC: tegra: I2S client convert formats handling Sameer Pujar
2024-05-30 11:54   ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D1MXG0PGXQW8.2GBRKOVBQM49H@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mkumard@nvidia.com \
    --cc=spujar@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox