From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Date: Mon, 11 Dec 2017 11:20:23 +0000 Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Message-Id: <1512991223.25007.590.camel@linux.intel.com> 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 , Liam Girdwood , Sriram Periyasamy Cc: Mark Brown , Jaroslav Kysela , Takashi Iwai , "Subhransu S. Prusty" , Jani Nikula , Guneshwor Singh , Pankaj Bharadiya , Senthilnathan Veppur , Vinod Koul , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org On Fri, 2017-12-08 at 14:54 +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. > - 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; I would rather remove also redundant parens and move the condition into the loop. -- Andy Shevchenko Intel Finland Oy From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Date: Mon, 11 Dec 2017 13:20:23 +0200 Message-ID: <1512991223.25007.590.camel@linux.intel.com> References: <20171208115425.rqclgmhcph5gn47j@mwanda> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20171208115425.rqclgmhcph5gn47j@mwanda> Sender: kernel-janitors-owner@vger.kernel.org To: Dan Carpenter , Liam Girdwood , Sriram Periyasamy Cc: Mark Brown , Jaroslav Kysela , Takashi Iwai , "Subhransu S. Prusty" , Jani Nikula , Guneshwor Singh , Pankaj Bharadiya , Senthilnathan Veppur , Vinod Koul , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org List-Id: alsa-devel@alsa-project.org On Fri, 2017-12-08 at 14:54 +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. > - 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; I would rather remove also redundant parens and move the condition into the loop. -- Andy Shevchenko Intel Finland Oy