linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used.
@ 2020-08-11  3:38 kernel test robot
  2020-08-11 15:04 ` Pierre-Louis Bossart
  0 siblings, 1 reply; 2+ messages in thread
From: kernel test robot @ 2020-08-11  3:38 UTC (permalink / raw)
  To: Ryan Lee
  Cc: kbuild-all, linux-kernel, Mark Brown, Naveen Manohar,
	Pierre-Louis Bossart, Rander Wang, Kai Vehmanen

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   086ba2ec163b638abd2a90ef3e8bab0238d02e56
commit: 56a5b7910e965c6905d112ce94fd9a9f5561f326 ASoC: codecs: max98373: add SoundWire support
date:   5 weeks ago
compiler: mipsel-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


cppcheck warnings: (new ones prefixed by >>)

>> sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]
    i = 0;
      ^
   sound/soc/codecs/max98373-sdw.c:313:4: note: Variable 'i' is reassigned a value before the old one has been used.
     i++;
      ^
   sound/soc/codecs/max98373-sdw.c:325:4: note: Variable 'i' is reassigned a value before the old one has been used.
    i = 0;
      ^
   sound/soc/codecs/max98373-sdw.c:344:9: warning: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]
    for (i = 0; i < num_of_ports; i++)
           ^
   sound/soc/codecs/max98373-sdw.c:333:4: note: Variable 'i' is reassigned a value before the old one has been used.
     i++;
      ^
   sound/soc/codecs/max98373-sdw.c:344:9: note: Variable 'i' is reassigned a value before the old one has been used.
    for (i = 0; i < num_of_ports; i++)
           ^

vim +/i +325 sound/soc/codecs/max98373-sdw.c

   281	
   282	static int max98373_read_prop(struct sdw_slave *slave)
   283	{
   284		struct sdw_slave_prop *prop = &slave->prop;
   285		int nval, i, num_of_ports;
   286		u32 bit;
   287		unsigned long addr;
   288		struct sdw_dpn_prop *dpn;
   289	
   290		/* BITMAP: 00001000  Dataport 3 is active */
   291		prop->source_ports = BIT(3);
   292		/* BITMAP: 00000010  Dataport 1 is active */
   293		prop->sink_ports = BIT(1);
   294		prop->paging_support = true;
   295		prop->clk_stop_timeout = 20;
   296	
   297		nval = hweight32(prop->source_ports);
   298		num_of_ports = nval;
   299		prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
   300						  sizeof(*prop->src_dpn_prop),
   301						  GFP_KERNEL);
   302		if (!prop->src_dpn_prop)
   303			return -ENOMEM;
   304	
   305		i = 0;
   306		dpn = prop->src_dpn_prop;
   307		addr = prop->source_ports;
   308		for_each_set_bit(bit, &addr, 32) {
   309			dpn[i].num = bit;
   310			dpn[i].type = SDW_DPN_FULL;
   311			dpn[i].simple_ch_prep_sm = true;
   312			dpn[i].ch_prep_timeout = 10;
   313			i++;
   314		}
   315	
   316		/* do this again for sink now */
   317		nval = hweight32(prop->sink_ports);
   318		num_of_ports += nval;
   319		prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
   320						   sizeof(*prop->sink_dpn_prop),
   321						   GFP_KERNEL);
   322		if (!prop->sink_dpn_prop)
   323			return -ENOMEM;
   324	
 > 325		i = 0;
   326		dpn = prop->sink_dpn_prop;
   327		addr = prop->sink_ports;
   328		for_each_set_bit(bit, &addr, 32) {
   329			dpn[i].num = bit;
   330			dpn[i].type = SDW_DPN_FULL;
   331			dpn[i].simple_ch_prep_sm = true;
   332			dpn[i].ch_prep_timeout = 10;
   333			i++;
   334		}
   335	
   336		/* Allocate port_ready based on num_of_ports */
   337		slave->port_ready = devm_kcalloc(&slave->dev, num_of_ports,
   338						 sizeof(*slave->port_ready),
   339						 GFP_KERNEL);
   340		if (!slave->port_ready)
   341			return -ENOMEM;
   342	
   343		/* Initialize completion */
   344		for (i = 0; i < num_of_ports; i++)
   345			init_completion(&slave->port_ready[i]);
   346	
   347		/* set the timeout values */
   348		prop->clk_stop_timeout = 20;
   349	
   350		return 0;
   351	}
   352	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used.
  2020-08-11  3:38 sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used kernel test robot
@ 2020-08-11 15:04 ` Pierre-Louis Bossart
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Louis Bossart @ 2020-08-11 15:04 UTC (permalink / raw)
  To: kernel test robot, Ryan Lee
  Cc: kbuild-all, linux-kernel, Mark Brown, Naveen Manohar,
	Rander Wang, Kai Vehmanen


> cppcheck warnings: (new ones prefixed by >>)
> 
>>> sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]
>      i = 0;
>        ^
>     sound/soc/codecs/max98373-sdw.c:313:4: note: Variable 'i' is reassigned a value before the old one has been used.
>       i++;
>        ^

the variable is incremented at the end of the loop, and reset at the 
start of a new loop, not sure how to avoid this warning.

>     sound/soc/codecs/max98373-sdw.c:325:4: note: Variable 'i' is reassigned a value before the old one has been used.
>      i = 0;
>        ^
>     sound/soc/codecs/max98373-sdw.c:344:9: warning: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]
>      for (i = 0; i < num_of_ports; i++)
>             ^
>     sound/soc/codecs/max98373-sdw.c:333:4: note: Variable 'i' is reassigned a value before the old one has been used.
>       i++;
>        ^
>     sound/soc/codecs/max98373-sdw.c:344:9: note: Variable 'i' is reassigned a value before the old one has been used.
>      for (i = 0; i < num_of_ports; i++)
>             ^

Same problem, the variable is reset at the start of a new loop, but the 
problem is solved - that code was removed in the latest code (to be 
submitted after the merge window).

> vim +/i +325 sound/soc/codecs/max98373-sdw.c
> 
>     281	
>     282	static int max98373_read_prop(struct sdw_slave *slave)
>     283	{
>     284		struct sdw_slave_prop *prop = &slave->prop;
>     285		int nval, i, num_of_ports;
>     286		u32 bit;
>     287		unsigned long addr;
>     288		struct sdw_dpn_prop *dpn;
>     289	
>     290		/* BITMAP: 00001000  Dataport 3 is active */
>     291		prop->source_ports = BIT(3);
>     292		/* BITMAP: 00000010  Dataport 1 is active */
>     293		prop->sink_ports = BIT(1);
>     294		prop->paging_support = true;
>     295		prop->clk_stop_timeout = 20;
>     296	
>     297		nval = hweight32(prop->source_ports);
>     298		num_of_ports = nval;
>     299		prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
>     300						  sizeof(*prop->src_dpn_prop),
>     301						  GFP_KERNEL);
>     302		if (!prop->src_dpn_prop)
>     303			return -ENOMEM;
>     304	
>     305		i = 0;
>     306		dpn = prop->src_dpn_prop;
>     307		addr = prop->source_ports;
>     308		for_each_set_bit(bit, &addr, 32) {
>     309			dpn[i].num = bit;
>     310			dpn[i].type = SDW_DPN_FULL;
>     311			dpn[i].simple_ch_prep_sm = true;
>     312			dpn[i].ch_prep_timeout = 10;
>     313			i++;
>     314		}
>     315	
>     316		/* do this again for sink now */
>     317		nval = hweight32(prop->sink_ports);
>     318		num_of_ports += nval;
>     319		prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
>     320						   sizeof(*prop->sink_dpn_prop),
>     321						   GFP_KERNEL);
>     322		if (!prop->sink_dpn_prop)
>     323			return -ENOMEM;
>     324	
>   > 325		i = 0;
>     326		dpn = prop->sink_dpn_prop;
>     327		addr = prop->sink_ports;
>     328		for_each_set_bit(bit, &addr, 32) {
>     329			dpn[i].num = bit;
>     330			dpn[i].type = SDW_DPN_FULL;
>     331			dpn[i].simple_ch_prep_sm = true;
>     332			dpn[i].ch_prep_timeout = 10;
>     333			i++;
>     334		}
>     335	
>     336		/* Allocate port_ready based on num_of_ports */
>     337		slave->port_ready = devm_kcalloc(&slave->dev, num_of_ports,
>     338						 sizeof(*slave->port_ready),
>     339						 GFP_KERNEL);
>     340		if (!slave->port_ready)
>     341			return -ENOMEM;
>     342	
>     343		/* Initialize completion */
>     344		for (i = 0; i < num_of_ports; i++)
>     345			init_completion(&slave->port_ready[i]);
>     346	
>     347		/* set the timeout values */
>     348		prop->clk_stop_timeout = 20;
>     349	
>     350		return 0;
>     351	}
>     352	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-11 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11  3:38 sound/soc/codecs/max98373-sdw.c:325:4: warning: Variable 'i' is reassigned a value before the old one has been used kernel test robot
2020-08-11 15:04 ` Pierre-Louis Bossart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).