From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vinod Koul Date: Mon, 11 Dec 2017 10:51:44 +0000 Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Message-Id: <20171211103944.GQ18649@localhost> List-Id: References: <20171208115425.rqclgmhcph5gn47j@mwanda> In-Reply-To: <20171208115425.rqclgmhcph5gn47j@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Dan Carpenter Cc: Liam Girdwood , Sriram Periyasamy , Mark Brown , Jaroslav Kysela , Takashi Iwai , "Subhransu S. Prusty" , Jani Nikula , Guneshwor Singh , Pankaj Bharadiya , Andy Shevchenko , Senthilnathan Veppur , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org On Fri, Dec 08, 2017 at 02:54:25PM +0300, Dan Carpenter wrote: > I get a Smatch warning here: > > sound/soc/intel/skylake/skl-nhlt.c:335 skl_get_ssp_clks() > error: testing array offset 'j' after use. > > The code is harmless, but the checker is right that we should swap these > two conditions so we verify that the offset is within bounds before we > use it. Acked-By: Vinod Koul > Signed-off-by: Dan Carpenter > > diff --git a/sound/soc/intel/skylake/skl-nhlt.c b/sound/soc/intel/skylake/skl-nhlt.c > index afa557a1c031..54f9bd630f4f 100644 > --- a/sound/soc/intel/skylake/skl-nhlt.c > +++ b/sound/soc/intel/skylake/skl-nhlt.c > @@ -331,8 +331,8 @@ static void skl_get_ssp_clks(struct skl *skl, struct skl_ssp_clk *ssp_clks, > rate = channels * bps * fs; > > /* check if the rate is added already to the given SSP's sclk */ > - for (j = 0; (sclk[id].rate_cfg[j].rate != 0) && > - (j < SKL_MAX_CLK_RATES); j++) { > + for (j = 0; (j < SKL_MAX_CLK_RATES) && > + (sclk[id].rate_cfg[j].rate != 0); j++) { > if (sclk[id].rate_cfg[j].rate = rate) { > present = true; > break; -- ~Vinod From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vinod Koul Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Date: Mon, 11 Dec 2017 16:09:44 +0530 Message-ID: <20171211103944.GQ18649@localhost> References: <20171208115425.rqclgmhcph5gn47j@mwanda> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20171208115425.rqclgmhcph5gn47j@mwanda> Sender: kernel-janitors-owner@vger.kernel.org To: Dan Carpenter Cc: Liam Girdwood , Sriram Periyasamy , Mark Brown , Jaroslav Kysela , Takashi Iwai , "Subhransu S. Prusty" , Jani Nikula , Guneshwor Singh , Pankaj Bharadiya , Andy Shevchenko , Senthilnathan Veppur , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org List-Id: alsa-devel@alsa-project.org On Fri, Dec 08, 2017 at 02:54:25PM +0300, Dan Carpenter wrote: > I get a Smatch warning here: > > sound/soc/intel/skylake/skl-nhlt.c:335 skl_get_ssp_clks() > error: testing array offset 'j' after use. > > The code is harmless, but the checker is right that we should swap these > two conditions so we verify that the offset is within bounds before we > use it. Acked-By: Vinod Koul > Signed-off-by: Dan Carpenter > > diff --git a/sound/soc/intel/skylake/skl-nhlt.c b/sound/soc/intel/skylake/skl-nhlt.c > index afa557a1c031..54f9bd630f4f 100644 > --- a/sound/soc/intel/skylake/skl-nhlt.c > +++ b/sound/soc/intel/skylake/skl-nhlt.c > @@ -331,8 +331,8 @@ static void skl_get_ssp_clks(struct skl *skl, struct skl_ssp_clk *ssp_clks, > rate = channels * bps * fs; > > /* check if the rate is added already to the given SSP's sclk */ > - for (j = 0; (sclk[id].rate_cfg[j].rate != 0) && > - (j < SKL_MAX_CLK_RATES); j++) { > + for (j = 0; (j < SKL_MAX_CLK_RATES) && > + (sclk[id].rate_cfg[j].rate != 0); j++) { > if (sclk[id].rate_cfg[j].rate == rate) { > present = true; > break; -- ~Vinod