Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: Arnd Bergmann Newsgroups: linux.kernel Subject: Re: [alsa-devel] [PATCH 1/2] ASoC: codec: wm9860: avoid maybe-uninitialized warning Date: Mon, 24 Apr 2017 17:30:01 +0200 Message-ID: References: X-Original-To: Daniel Baluta Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=tA7I7uKyTqm75gdS6tjOAWjDUKAvXb+rwrtVHXGmvFM=; b=BMhuk+6WtYLGLX/grEhpD7sdI40GXwLflUXHuDGgs/Ec/uGUPb/6rHM2zk5R7DTYZg 8IS6SjKetuyx43qyJJJdtfKEkba+Yp67mlmWMHpbehe1O/0rdW2/QG7VT3sJ1fRbpWje tp3UJE2yT/j6MB4xUOn8iEhpXxDlshkbUnbv4I9fklBRb2mjp/Jl6NChIyAWaXcOkLza Ozo4NXsBwQHsBgvJ5qDUub197JBMHLk2rgmIAsPJyMQfC37r3ogpr9l1n36kYkM6ucW4 2XDrcGMcg/xs0BpGLzdmdqEqCorHJOIhy+x3PXbzJJxZaA3GBwLXnOQkV7Njz0MpKdRz CP5g== X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=tA7I7uKyTqm75gdS6tjOAWjDUKAvXb+rwrtVHXGmvFM=; b=UjYPuIAhc6qOVyakXcxIBoUPmxtVTm99EC5bnCsCJg3zOaY0KniztHEjWK4TxvzagZ xjP2cokITRAN3tCB6iHUwiW2jYcx/ZHncpglpOhXMAgvXWC5rhLPdlDfTLAEE/s4FQXS OE9A7rVZcmhigMs09bILdrME0DX+GqOjmvrvYvfNrDIaHtVp1IpVyeMuny3+lwkoXo8Q Kkumz6CCR2IsSRAFaUeXaJn79Ahdkx27kNhhRni9y7PUcUeFUVJevjpGLPrkCdTAt3Rn w1Wykkt60Zeds5jUvq73JCTd8Ic++8wiTgXkAMigyfUKmClAa+4EaigHe/DQUg+RiXrJ neCQ== X-Gm-Message-State: AN3rC/5fZPYkFi238kN3WGx8+x5lkkIDruEaxURO0K8t4vR+aCrBIkL2 6pgHQL2xcncly2mo/FrVet09KGZ4/w== X-Received: by 10.202.217.85 with SMTP id q82mr13570287oig.92.1493047645716; Mon, 24 Apr 2017 08:27:25 -0700 (PDT) MIME-Version: 1.0 X-Google-Sender-Auth: rlKDz2glv_rNAZUNCSRHrTp1tQ8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 172 Organization: linux.* mail to news gateway X-Original-Cc: Daniel Baluta , alsa-devel@alsa-project.org, Linux Kernel Mailing List , patches@opensource.wolfsonmicro.com, Takashi Iwai , Liam Girdwood , Mark Brown , Charles Keepax X-Original-Date: Mon, 24 Apr 2017 17:27:25 +0200 X-Original-Message-ID: X-Original-References: <1492780055-4892-1-git-send-email-daniel.baluta@nxp.com> <1492780055-4892-2-git-send-email-daniel.baluta@nxp.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1629669 On Mon, Apr 24, 2017 at 3:15 PM, Daniel Baluta wr= ote: > On Fri, Apr 21, 2017 at 5:46 PM, Arnd Bergmann wrote: >> On Fri, Apr 21, 2017 at 3:07 PM, Daniel Baluta w= rote: >>> 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=3Dmaybe-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 fre= q is found") >>> Suggested-by: Arnd Bergmann >>> Signed-off-by: Daniel Baluta >>> --- >>> 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, > =C2=BB =C2=BB =C2=BB int *sysclk_idx, int *dac_idx, in= t *bclk_idx) > { > =C2=BB struct wm8960_priv *wm8960 =3D snd_soc_codec_get_drvdata(cod= ec); > =C2=BB int sysclk, bclk, lrclk, freq_out; > =C2=BB int diff, closest, best_freq_out; > =C2=BB int i, j, k; > > =C2=BB bclk =3D wm8960->bclk; > =C2=BB lrclk =3D wm8960->lrclk; > =C2=BB closest =3D freq_in; > > =C2=BB best_freq_out =3D -EINVAL; > =C2=BB *sysclk_idx =3D *dac_idx =3D *bclk_idx =3D -1; > > =C2=BB for (i =3D 0; i < ARRAY_SIZE(sysclk_divs); ++i) { > =C2=BB =C2=BB if (sysclk_divs[i] =3D=3D -1) > =C2=BB =C2=BB =C2=BB continue; > =C2=BB =C2=BB for (j =3D 0; j < ARRAY_SIZE(dac_divs); ++j) { > =C2=BB =C2=BB =C2=BB sysclk =3D lrclk * dac_divs[j]; > =C2=BB =C2=BB =C2=BB freq_out =3D sysclk * sysclk_divs[= i]; > > =C2=BB =C2=BB =C2=BB for (k =3D 0; k < ARRAY_SIZE(bclk_= divs); ++k) { > =C2=BB =C2=BB =C2=BB =C2=BB if (!is_pll_freq_avai= lable(freq_in, freq_out)) > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB continue= ; > > =C2=BB =C2=BB =C2=BB =C2=BB diff =3D sysclk - bcl= k * bclk_divs[k] / 10; > =C2=BB =C2=BB =C2=BB =C2=BB if (diff =3D=3D 0) { > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *sysclk_= idx =3D i; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *dac_idx= =3D j; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *bclk_id= x =3D k; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB best_fre= q_out =3D freq_out; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB break; > =C2=BB =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB =C2=BB =C2=BB if (diff > 0 && close= st > diff) { > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *sysclk_= idx =3D i; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *dac_idx= =3D j; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *bclk_id= x =3D k; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB closest = =3D diff; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB best_fre= q_out =3D freq_out; > =C2=BB =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB =C2=BB if (k !=3D ARRAY_SIZE(bclk_divs)) > =C2=BB =C2=BB =C2=BB =C2=BB break; > =C2=BB =C2=BB } > =C2=BB =C2=BB if (j !=3D ARRAY_SIZE(dac_divs)) > =C2=BB =C2=BB =C2=BB break; > =C2=BB } > > =C2=BB return best_freq_out; > } > > In my opinion this is a compiler false positive. Any clue on how to rewor= k 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): > =C2=BB for (i =3D 0; i < ARRAY_SIZE(sysclk_divs); ++i) { > =C2=BB =C2=BB if (sysclk_divs[i] =3D=3D -1) > =C2=BB =C2=BB =C2=BB continue; > =C2=BB =C2=BB for (j =3D 0; j < ARRAY_SIZE(dac_divs); ++j) { > =C2=BB =C2=BB =C2=BB sysclk =3D lrclk * dac_divs[j]; > =C2=BB =C2=BB =C2=BB freq_out =3D sysclk * sysclk_divs[= i]; > > =C2=BB =C2=BB =C2=BB for (k =3D 0; k < ARRAY_SIZE(bclk_= divs); ++k) { > =C2=BB =C2=BB =C2=BB =C2=BB if (!is_pll_freq_avai= lable(freq_in, freq_out)) > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB continue= ; > > =C2=BB =C2=BB =C2=BB =C2=BB diff =3D sysclk - bcl= k * bclk_divs[k] / 10; > =C2=BB =C2=BB =C2=BB =C2=BB if (diff =3D=3D 0) { > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *sysclk_= idx =3D i; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *dac_idx= =3D j; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *bclk_id= x =3D k; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB best_fre= q_out =3D freq_out; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB goto out= ; > =C2=BB =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB =C2=BB =C2=BB if (diff > 0 && close= st > diff) { > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *sysclk_= idx =3D i; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *dac_idx= =3D j; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB *bclk_id= x =3D k; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB closest = =3D diff; > =C2=BB =C2=BB =C2=BB =C2=BB =C2=BB best_fre= q_out =3D freq_out; > =C2=BB =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB =C2=BB } > =C2=BB =C2=BB } > =C2=BB } >out: > =C2=BB return best_freq_out; > } Arnd