All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
	Sriram Periyasamy <sriramx.periyasamy@intel.com>
Cc: alsa-devel@alsa-project.org, Jani Nikula <jani.nikula@intel.com>,
	Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>,
	Guneshwor Singh <guneshwor.o.singh@intel.com>,
	Takashi Iwai <tiwai@suse.com>, Vinod Koul <vinod.koul@intel.com>,
	kernel-janitors@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	Senthilnathan Veppur <senthilnathanx.veppur@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"Subhransu S. Prusty" <subhransu.s.prusty@intel.com>
Subject: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning
Date: Fri, 08 Dec 2017 11:54:25 +0000	[thread overview]
Message-ID: <20171208115425.rqclgmhcph5gn47j@mwanda> (raw)

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

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;

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
	Sriram Periyasamy <sriramx.periyasamy@intel.com>
Cc: alsa-devel@alsa-project.org, Jani Nikula <jani.nikula@intel.com>,
	Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>,
	Guneshwor Singh <guneshwor.o.singh@intel.com>,
	Takashi Iwai <tiwai@suse.com>, Vinod Koul <vinod.koul@intel.com>,
	kernel-janitors@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	Senthilnathan Veppur <senthilnathanx.veppur@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"Subhransu S. Prusty" <subhransu.s.prusty@intel.com>
Subject: [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning
Date: Fri, 8 Dec 2017 14:54:25 +0300	[thread overview]
Message-ID: <20171208115425.rqclgmhcph5gn47j@mwanda> (raw)

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

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;

             reply	other threads:[~2017-12-08 11:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 11:54 Dan Carpenter [this message]
2017-12-08 11:54 ` [PATCH] ASoC: Intel: Skylake: Re-order some code to silence a warning Dan Carpenter
2017-12-11 10:39 ` Vinod Koul
2017-12-11 10:51   ` Vinod Koul
2017-12-11 10:33   ` Sriram Periyasamy
2017-12-11 10:45     ` Sriram Periyasamy
2017-12-11 11:20 ` Andy Shevchenko
2017-12-11 11:20   ` Andy Shevchenko
2017-12-11 11:33   ` Dan Carpenter
2017-12-11 11:33     ` Dan Carpenter
2017-12-11 11:54     ` Andy Shevchenko
2017-12-11 11:54       ` Andy Shevchenko
2017-12-11 12:13 ` Applied "ASoC: Intel: Skylake: Re-order some code to silence a warning" to the asoc tree Mark Brown
2017-12-11 12:13   ` Mark Brown

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=20171208115425.rqclgmhcph5gn47j@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=guneshwor.o.singh@intel.com \
    --cc=jani.nikula@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=pankaj.laxminarayan.bharadiya@intel.com \
    --cc=senthilnathanx.veppur@intel.com \
    --cc=sriramx.periyasamy@intel.com \
    --cc=subhransu.s.prusty@intel.com \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@intel.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.