All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Baluta <daniel.baluta@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Baluta <daniel.baluta@nxp.com>,
	alsa-devel@alsa-project.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	patches@opensource.wolfsonmicro.com,
	Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Subject: Re: [alsa-devel] [PATCH 1/2] ASoC: codec: wm9860: avoid maybe-uninitialized warning
Date: Tue, 25 Apr 2017 13:17:47 +0300	[thread overview]
Message-ID: <CAEnQRZCp6Xxpo+x2eRtM2wKTO_YXYZ84YAk12LTmijDjyuJQ2w@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a20+0sa0cZKoMu0SoqYtVMzJZumGzDpwEaSMJw_zbckfg@mail.gmail.com>

On Mon, Apr 24, 2017 at 6:27 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Mon, Apr 24, 2017 at 3:15 PM, Daniel Baluta <daniel.baluta@gmail.com> wrote:
>> On Fri, Apr 21, 2017 at 5:46 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>> On Fri, Apr 21, 2017 at 3:07 PM, Daniel Baluta <daniel.baluta@nxp.com> wrote:
>>>> The new PLL configuration code triggers a harmless warning:
>>>>
>>>> sound/soc/codecs/wm8960.c: In function 'wm8960_configure_clocking':
>>>> sound/soc/codecs/wm8960.c:735:3: error: 'best_freq_out' may be used
>>>> uninitialized in this function [-Werror=maybe-uninitialized]
>>>>    wm8960_set_pll(codec, freq_in, best_freq_out);
>>>>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> sound/soc/codecs/wm8960.c:699:12: note: 'best_freq_out' was declared
>>>> here
>>>>
>>>> Fixes: 84fdc00d519f ("ASoC: codec: wm9860: Refactor PLL out freq search")
>>>> Fixes: 303e8954af8d ("ASoC: codec: wm8960: Stop when a matching PLL freq is found")
>>>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
>>>> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
>>>> ---
>>>> Arnd,
>>>>
>>>> I agree that your code was more both humans and gcc anyhow
>>>> for consistency with wm8960_configure_sysclk function I preferred
>>>> to keep the "if(..) break" statements.
>>>
>>> How about changing both functions the same way then?
>>
>> I've tried but I couldn't find any solution. For clarity here is how
>> the code actually looks like.
>>
>> The git diff is a little bit misleading. Here is how wm8960_configure_pll code
>> looks like:
>>
>> https://pastebin.com/naGdVNQz
>>
>> static
>> int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in,
>> »       »       »        int *sysclk_idx, int *dac_idx, int *bclk_idx)
>> {
>> »       struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
>> »       int sysclk, bclk, lrclk, freq_out;
>> »       int diff, closest, best_freq_out;
>> »       int i, j, k;
>>
>> »       bclk = wm8960->bclk;
>> »       lrclk = wm8960->lrclk;
>> »       closest = freq_in;
>>
>> »       best_freq_out = -EINVAL;
>> »       *sysclk_idx = *dac_idx = *bclk_idx = -1;
>>
>> »       for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) {
>> »       »       if (sysclk_divs[i] == -1)
>> »       »       »       continue;
>> »       »       for (j = 0; j < ARRAY_SIZE(dac_divs); ++j) {
>> »       »       »       sysclk = lrclk * dac_divs[j];
>> »       »       »       freq_out = sysclk * sysclk_divs[i];
>>
>> »       »       »       for (k = 0; k < ARRAY_SIZE(bclk_divs); ++k) {
>> »       »       »       »       if (!is_pll_freq_available(freq_in, freq_out))
>> »       »       »       »       »       continue;
>>
>> »       »       »       »       diff = sysclk - bclk * bclk_divs[k] / 10;
>> »       »       »       »       if (diff == 0) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       »       break;
>> »       »       »       »       }
>> »       »       »       »       if (diff > 0 && closest > diff) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       closest = diff;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       }
>> »       »       »       }
>> »       »       »       if (k != ARRAY_SIZE(bclk_divs))
>> »       »       »       »       break;
>> »       »       }
>> »       »       if (j != ARRAY_SIZE(dac_divs))
>> »       »       »       break;
>> »       }
>>
>> »       return best_freq_out;
>> }
>>
>> In my opinion this is a compiler false positive. Any clue on how to rework this
>> would be welcomed :). I couldn't find any decent solution.
>
> Actually I think in this case the compiler is supposed to warn if
> best_freq_out is not initialized, as we would never set it
> in case is_pll_freq_available() returns false for all inputs or
> sysclk_divs[] is -1 for all fields.
> I'd leave the initialization then, and only replace the breaks
> with a goto (not tested):
>
>> »       for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) {
>> »       »       if (sysclk_divs[i] == -1)
>> »       »       »       continue;
>> »       »       for (j = 0; j < ARRAY_SIZE(dac_divs); ++j) {
>> »       »       »       sysclk = lrclk * dac_divs[j];
>> »       »       »       freq_out = sysclk * sysclk_divs[i];
>>
>> »       »       »       for (k = 0; k < ARRAY_SIZE(bclk_divs); ++k) {
>> »       »       »       »       if (!is_pll_freq_available(freq_in, freq_out))
>> »       »       »       »       »       continue;
>>
>> »       »       »       »       diff = sysclk - bclk * bclk_divs[k] / 10;
>> »       »       »       »       if (diff == 0) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       »       goto out;
>> »       »       »       »       }
>> »       »       »       »       if (diff > 0 && closest > diff) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       closest = diff;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       }
>> »       »       »       }
>> »       »       }
>> »       }
>>out:
>> »       return best_freq_out;
>> }

Sure, this looks reasonable. I will send v2.

Daniel.

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Baluta <daniel.baluta@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	Liam Girdwood <lgirdwood@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.com>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Subject: Re: [PATCH 1/2] ASoC: codec: wm9860: avoid maybe-uninitialized warning
Date: Tue, 25 Apr 2017 13:17:47 +0300	[thread overview]
Message-ID: <CAEnQRZCp6Xxpo+x2eRtM2wKTO_YXYZ84YAk12LTmijDjyuJQ2w@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a20+0sa0cZKoMu0SoqYtVMzJZumGzDpwEaSMJw_zbckfg@mail.gmail.com>

On Mon, Apr 24, 2017 at 6:27 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Mon, Apr 24, 2017 at 3:15 PM, Daniel Baluta <daniel.baluta@gmail.com> wrote:
>> On Fri, Apr 21, 2017 at 5:46 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>> On Fri, Apr 21, 2017 at 3:07 PM, Daniel Baluta <daniel.baluta@nxp.com> wrote:
>>>> The new PLL configuration code triggers a harmless warning:
>>>>
>>>> sound/soc/codecs/wm8960.c: In function 'wm8960_configure_clocking':
>>>> sound/soc/codecs/wm8960.c:735:3: error: 'best_freq_out' may be used
>>>> uninitialized in this function [-Werror=maybe-uninitialized]
>>>>    wm8960_set_pll(codec, freq_in, best_freq_out);
>>>>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> sound/soc/codecs/wm8960.c:699:12: note: 'best_freq_out' was declared
>>>> here
>>>>
>>>> Fixes: 84fdc00d519f ("ASoC: codec: wm9860: Refactor PLL out freq search")
>>>> Fixes: 303e8954af8d ("ASoC: codec: wm8960: Stop when a matching PLL freq is found")
>>>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
>>>> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
>>>> ---
>>>> Arnd,
>>>>
>>>> I agree that your code was more both humans and gcc anyhow
>>>> for consistency with wm8960_configure_sysclk function I preferred
>>>> to keep the "if(..) break" statements.
>>>
>>> How about changing both functions the same way then?
>>
>> I've tried but I couldn't find any solution. For clarity here is how
>> the code actually looks like.
>>
>> The git diff is a little bit misleading. Here is how wm8960_configure_pll code
>> looks like:
>>
>> https://pastebin.com/naGdVNQz
>>
>> static
>> int wm8960_configure_pll(struct snd_soc_codec *codec, int freq_in,
>> »       »       »        int *sysclk_idx, int *dac_idx, int *bclk_idx)
>> {
>> »       struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
>> »       int sysclk, bclk, lrclk, freq_out;
>> »       int diff, closest, best_freq_out;
>> »       int i, j, k;
>>
>> »       bclk = wm8960->bclk;
>> »       lrclk = wm8960->lrclk;
>> »       closest = freq_in;
>>
>> »       best_freq_out = -EINVAL;
>> »       *sysclk_idx = *dac_idx = *bclk_idx = -1;
>>
>> »       for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) {
>> »       »       if (sysclk_divs[i] == -1)
>> »       »       »       continue;
>> »       »       for (j = 0; j < ARRAY_SIZE(dac_divs); ++j) {
>> »       »       »       sysclk = lrclk * dac_divs[j];
>> »       »       »       freq_out = sysclk * sysclk_divs[i];
>>
>> »       »       »       for (k = 0; k < ARRAY_SIZE(bclk_divs); ++k) {
>> »       »       »       »       if (!is_pll_freq_available(freq_in, freq_out))
>> »       »       »       »       »       continue;
>>
>> »       »       »       »       diff = sysclk - bclk * bclk_divs[k] / 10;
>> »       »       »       »       if (diff == 0) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       »       break;
>> »       »       »       »       }
>> »       »       »       »       if (diff > 0 && closest > diff) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       closest = diff;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       }
>> »       »       »       }
>> »       »       »       if (k != ARRAY_SIZE(bclk_divs))
>> »       »       »       »       break;
>> »       »       }
>> »       »       if (j != ARRAY_SIZE(dac_divs))
>> »       »       »       break;
>> »       }
>>
>> »       return best_freq_out;
>> }
>>
>> In my opinion this is a compiler false positive. Any clue on how to rework this
>> would be welcomed :). I couldn't find any decent solution.
>
> Actually I think in this case the compiler is supposed to warn if
> best_freq_out is not initialized, as we would never set it
> in case is_pll_freq_available() returns false for all inputs or
> sysclk_divs[] is -1 for all fields.
> I'd leave the initialization then, and only replace the breaks
> with a goto (not tested):
>
>> »       for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) {
>> »       »       if (sysclk_divs[i] == -1)
>> »       »       »       continue;
>> »       »       for (j = 0; j < ARRAY_SIZE(dac_divs); ++j) {
>> »       »       »       sysclk = lrclk * dac_divs[j];
>> »       »       »       freq_out = sysclk * sysclk_divs[i];
>>
>> »       »       »       for (k = 0; k < ARRAY_SIZE(bclk_divs); ++k) {
>> »       »       »       »       if (!is_pll_freq_available(freq_in, freq_out))
>> »       »       »       »       »       continue;
>>
>> »       »       »       »       diff = sysclk - bclk * bclk_divs[k] / 10;
>> »       »       »       »       if (diff == 0) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       »       goto out;
>> »       »       »       »       }
>> »       »       »       »       if (diff > 0 && closest > diff) {
>> »       »       »       »       »       *sysclk_idx = i;
>> »       »       »       »       »       *dac_idx = j;
>> »       »       »       »       »       *bclk_idx = k;
>> »       »       »       »       »       closest = diff;
>> »       »       »       »       »       best_freq_out = freq_out;
>> »       »       »       »       }
>> »       »       »       }
>> »       »       }
>> »       }
>>out:
>> »       return best_freq_out;
>> }

Sure, this looks reasonable. I will send v2.

Daniel.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2017-04-25 10:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 13:07 [PATCH 0/2] Relax bitclk computation when using PLL Daniel Baluta
2017-04-21 13:07 ` Daniel Baluta
2017-04-21 13:07 ` [PATCH 1/2] ASoC: codec: wm9860: avoid maybe-uninitialized warning Daniel Baluta
2017-04-21 13:07   ` Daniel Baluta
2017-04-21 14:46   ` Arnd Bergmann
2017-04-21 14:46     ` Arnd Bergmann
2017-04-24 13:15     ` [alsa-devel] " Daniel Baluta
2017-04-24 13:15       ` Daniel Baluta
2017-04-24 15:27       ` [alsa-devel] " Arnd Bergmann
2017-04-24 15:27         ` Arnd Bergmann
2017-04-25 10:17         ` Daniel Baluta [this message]
2017-04-25 10:17           ` Daniel Baluta
2017-04-21 13:07 ` [PATCH 2/2] ASoC: codec: wm8960: Relax bit clock computation when using PLL Daniel Baluta
2017-04-21 13:07   ` Daniel Baluta
2017-04-21 14:44   ` Arnd Bergmann
2017-04-21 14:44     ` Arnd Bergmann

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=CAEnQRZCp6Xxpo+x2eRtM2wKTO_YXYZ84YAk12LTmijDjyuJQ2w@mail.gmail.com \
    --to=daniel.baluta@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=daniel.baluta@nxp.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=tiwai@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.