mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Cc: "tiwai@suse.de" <tiwai@suse.de>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Support Opensource <Support.Opensource@diasemi.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Subject: RE: [RFC PATCH 2/2] ASoC: da732x: simplify code
Date: Thu, 15 Apr 2021 16:00:48 +0000	[thread overview]
Message-ID: <PR3PR10MB4142E8DBB9313E751DA52DD0804D9@PR3PR10MB4142.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20210326221619.949961-3-pierre-louis.bossart@linux.intel.com>

On 26 March 2021 22:16, Pierre-Louis Bossart wrote:

> cppcheck reports a false positive:
> 
> sound/soc/codecs/da732x.c:1161:25: warning: Either the condition
> 'indiv<0' is redundant or there is division by zero at line
> 1161. [zerodivcond]
>  fref = (da732x->sysclk / indiv);
>                         ^
> sound/soc/codecs/da732x.c:1158:12: note: Assuming that condition
> 'indiv<0' is not redundant
>  if (indiv < 0)
>            ^
> sound/soc/codecs/da732x.c:1161:25: note: Division by zero
>  fref = (da732x->sysclk / indiv);
>                         ^
> 
> The code is awfully convoluted/confusing and can be simplified with a
> single variable and the BIT macro.
> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---

Apologies for the delay in getting to this. The change looks fine to me,
although this part was EOL some time back, and I find it hard to believe anyone
out there has a board with this on. Wondering if it would make sense to remove
the driver permanently?

For the change at hand though:

Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

>  sound/soc/codecs/da732x.c | 17 ++++++-----------
>  sound/soc/codecs/da732x.h | 12 ++++--------
>  2 files changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
> index d43ee7159ae0..42d6a3fc3af5 100644
> --- a/sound/soc/codecs/da732x.c
> +++ b/sound/soc/codecs/da732x.c
> @@ -168,30 +168,25 @@ static const struct reg_default da732x_reg_cache[] = {
>  static inline int da732x_get_input_div(struct snd_soc_component *component,
> int sysclk)
>  {
>  	int val;
> -	int ret;
> 
>  	if (sysclk < DA732X_MCLK_10MHZ) {
> -		val = DA732X_MCLK_RET_0_10MHZ;
> -		ret = DA732X_MCLK_VAL_0_10MHZ;
> +		val = DA732X_MCLK_VAL_0_10MHZ;
>  	} else if ((sysclk >= DA732X_MCLK_10MHZ) &&
>  	    (sysclk < DA732X_MCLK_20MHZ)) {
> -		val = DA732X_MCLK_RET_10_20MHZ;
> -		ret = DA732X_MCLK_VAL_10_20MHZ;
> +		val = DA732X_MCLK_VAL_10_20MHZ;
>  	} else if ((sysclk >= DA732X_MCLK_20MHZ) &&
>  	    (sysclk < DA732X_MCLK_40MHZ)) {
> -		val = DA732X_MCLK_RET_20_40MHZ;
> -		ret = DA732X_MCLK_VAL_20_40MHZ;
> +		val = DA732X_MCLK_VAL_20_40MHZ;
>  	} else if ((sysclk >= DA732X_MCLK_40MHZ) &&
>  	    (sysclk <= DA732X_MCLK_54MHZ)) {
> -		val = DA732X_MCLK_RET_40_54MHZ;
> -		ret = DA732X_MCLK_VAL_40_54MHZ;
> +		val = DA732X_MCLK_VAL_40_54MHZ;
>  	} else {
>  		return -EINVAL;
>  	}
> 
>  	snd_soc_component_write(component, DA732X_REG_PLL_CTRL, val);
> 
> -	return ret;
> +	return val;
>  }
> 
>  static void da732x_set_charge_pump(struct snd_soc_component *component,
> int state)
> @@ -1158,7 +1153,7 @@ static int da732x_set_dai_pll(struct
> snd_soc_component *component, int pll_id,
>  	if (indiv < 0)
>  		return indiv;
> 
> -	fref = (da732x->sysclk / indiv);
> +	fref = da732x->sysclk / BIT(indiv);
>  	div_hi = freq_out / fref;
>  	frac_div = (u64)(freq_out % fref) * 8192ULL;
>  	do_div(frac_div, fref);
> diff --git a/sound/soc/codecs/da732x.h b/sound/soc/codecs/da732x.h
> index c5af17ee1516..c2f784c3f359 100644
> --- a/sound/soc/codecs/da732x.h
> +++ b/sound/soc/codecs/da732x.h
> @@ -48,14 +48,10 @@
>  #define	DA732X_MCLK_20MHZ		20000000
>  #define	DA732X_MCLK_40MHZ		40000000
>  #define	DA732X_MCLK_54MHZ		54000000
> -#define	DA732X_MCLK_RET_0_10MHZ		0
> -#define	DA732X_MCLK_VAL_0_10MHZ		1
> -#define	DA732X_MCLK_RET_10_20MHZ	1
> -#define	DA732X_MCLK_VAL_10_20MHZ	2
> -#define	DA732X_MCLK_RET_20_40MHZ	2
> -#define	DA732X_MCLK_VAL_20_40MHZ	4
> -#define	DA732X_MCLK_RET_40_54MHZ	3
> -#define	DA732X_MCLK_VAL_40_54MHZ	8
> +#define	DA732X_MCLK_VAL_0_10MHZ		0
> +#define	DA732X_MCLK_VAL_10_20MHZ	1
> +#define	DA732X_MCLK_VAL_20_40MHZ	2
> +#define	DA732X_MCLK_VAL_40_54MHZ	3
>  #define	DA732X_DAI_ID1			0
>  #define	DA732X_DAI_ID2			1
>  #define	DA732X_SRCCLK_PLL		0
> --
> 2.25.1


  reply	other threads:[~2021-04-15 16:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 22:16 [RFC PATCH 0/2] ASoC: remove cppchecks warnings on lm49453 and da732x Pierre-Louis Bossart
2021-03-26 22:16 ` [RFC PATCH 1/2] ASoC: lm49453: fix useless assignment before return Pierre-Louis Bossart
2021-03-26 22:16 ` [RFC PATCH 2/2] ASoC: da732x: simplify code Pierre-Louis Bossart
2021-04-15 16:00   ` Adam Thomson [this message]
2021-04-15 16:04     ` Mark Brown
2021-04-15 16:09       ` Adam Thomson
2021-04-01 10:16 ` [RFC PATCH 0/2] ASoC: remove cppchecks warnings on lm49453 and da732x Mark Brown

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=PR3PR10MB4142E8DBB9313E751DA52DD0804D9@PR3PR10MB4142.EURPRD10.PROD.OUTLOOK.COM \
    --to=adam.thomson.opensource@diasemi.com \
    --cc=Support.Opensource@diasemi.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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

all inboxes | Powered by JetHome®