From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sriram Periyasamy Date: Mon, 11 Dec 2017 10:45:07 +0000 Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Message-Id: <20171211103307.GA14288@intel.com> List-Id: References: <20171208115425.rqclgmhcph5gn47j@mwanda> <20171211103944.GQ18649@localhost> In-Reply-To: <20171211103944.GQ18649@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Vinod Koul Cc: Dan Carpenter , Liam Girdwood , 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 Mon, Dec 11, 2017 at 04:09:44PM +0530, Vinod Koul wrote: > 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 Reviewed-by: Sriram Periyasamy > > > 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: Sriram Periyasamy Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Date: Mon, 11 Dec 2017 16:03:07 +0530 Message-ID: <20171211103307.GA14288@intel.com> References: <20171208115425.rqclgmhcph5gn47j@mwanda> <20171211103944.GQ18649@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20171211103944.GQ18649@localhost> Sender: kernel-janitors-owner@vger.kernel.org To: Vinod Koul Cc: Dan Carpenter , Liam Girdwood , 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 Mon, Dec 11, 2017 at 04:09:44PM +0530, Vinod Koul wrote: > 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 Reviewed-by: Sriram Periyasamy > > > 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 --