[bug report] ASoC: codecs: wcd938x: add capture dapm widgets

Dan Carpenter dan.carpenter at oracle.com
Fri Jun 18 08:25:47 CEST 2021


Hello Srinivas Kandagatla,

The patch d5add08fcbce: "ASoC: codecs: wcd938x: add capture dapm
widgets" from Jun 9, 2021, leads to the following static checker
warning:

	sound/soc/codecs/wcd938x.c:2092 wcd938x_tx_swr_ctrl()
	error: uninitialized symbol 'rate'.

sound/soc/codecs/wcd938x.c
  2064          switch (event) {
  2065          case SND_SOC_DAPM_PRE_PMU:
  2066                  if (strnstr(w->name, "ADC", sizeof("ADC"))) {

Use strncmp() here instead of strnstr().

The sizeof() will include the NUL terminator so it's size 4 and you
wanted 3.  The off by one means that strnstr() will do two memcmp()s.
The equivalent of:

	if (memcmp(w->name, "ADC", 3) == 0)
		return w->name;
	if (memcmp(w->name + 1, "ADC", 3) == 0)
		return w->name + 1;
	return NULL;

  2067                          int i = 0, mode = 0;
  2068  
  2069                          if (test_bit(WCD_ADC1, &wcd938x->status_mask))
  2070                                  mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC1]];
  2071                          if (test_bit(WCD_ADC2, &wcd938x->status_mask))
  2072                                  mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC2]];
  2073                          if (test_bit(WCD_ADC3, &wcd938x->status_mask))
  2074                                  mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC3]];
  2075                          if (test_bit(WCD_ADC4, &wcd938x->status_mask))
  2076                                  mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC4]];
  2077  
  2078                          if (mode != 0) {
  2079                                  for (i = 0; i < ADC_MODE_ULP2; i++) {
  2080                                          if (mode & (1 << i)) {
  2081                                                  i++;
  2082                                                  break;
  2083                                          }
  2084                                  }
  2085                          }
  2086                          rate = wcd938x_get_clk_rate(i);
  2087                          wcd938x_set_swr_clk_rate(component, rate, bank);
  2088                  }
  2089  
  2090                  if (strnstr(w->name, "ADC", sizeof("ADC")))
  2091                          /* Copy clk settings to active bank */
  2092                          wcd938x_set_swr_clk_rate(component, rate, !bank);

This a false positive, but you could silence it by combining it with the
previous if block.

  2093                  break;
  2094          case SND_SOC_DAPM_POST_PMD:
  2095                  if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  2096                          rate = wcd938x_get_clk_rate(ADC_MODE_INVALID);
  2097                          wcd938x_set_swr_clk_rate(component, rate, !bank);
  2098                          wcd938x_set_swr_clk_rate(component, rate, bank);
  2099                  }
  2100                  break;
  2101          }

regards,
dan carpenter


More information about the Alsa-devel mailing list