[esmil:visionfive 46/61] sound/soc/starfive/pwmdac-pcm.c:84:6: warning: variable 'substream' is used uninitialized whenever 'if' condition is false
From: kernel test robot
Date: Tue Mar 22 2022 - 11:57:56 EST
tree: https://github.com/esmil/linux visionfive
head: 243ce759ed5821edf38bf93ce7325e232b805547
commit: 7c3b27a272448a123087494f7ade3e84a92543c6 [46/61] ASoC: starfive: Add StarFive JH7100 audio drivers
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20220322/202203222347.77QCVbYU-lkp@xxxxxxxxx/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 85e9b2687a13d1908aa86d1b89c5ce398a06cd39)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/esmil/linux/commit/7c3b27a272448a123087494f7ade3e84a92543c6
git remote add esmil https://github.com/esmil/linux
git fetch --no-tags esmil visionfive
git checkout 7c3b27a272448a123087494f7ade3e84a92543c6
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash sound/soc/starfive/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
All warnings (new ones prefixed by >>):
>> sound/soc/starfive/pwmdac-pcm.c:84:6: warning: variable 'substream' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (push)
^~~~
sound/soc/starfive/pwmdac-pcm.c:87:11: note: uninitialized use occurs here
active = substream && snd_pcm_running(substream);
^~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:84:2: note: remove the 'if' if its condition is always true
if (push)
^~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:80:37: note: initialize the variable 'substream' to silence this warning
struct snd_pcm_substream *substream;
^
= NULL
>> sound/soc/starfive/pwmdac-pcm.c:92:7: warning: variable 'period_elapsed' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (push) {
^~~~
sound/soc/starfive/pwmdac-pcm.c:99:7: note: uninitialized use occurs here
if (period_elapsed)
^~~~~~~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:92:3: note: remove the 'if' if its condition is always true
if (push) {
^~~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:81:29: note: initialize the variable 'period_elapsed' to silence this warning
bool active, period_elapsed;
^
= 0
>> sound/soc/starfive/pwmdac-pcm.c:202:6: warning: variable 'pos' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:205:9: note: uninitialized use occurs here
return pos < runtime->buffer_size ? pos : 0;
^~~
sound/soc/starfive/pwmdac-pcm.c:202:2: note: remove the 'if' if its condition is always true
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/starfive/pwmdac-pcm.c:200:23: note: initialize the variable 'pos' to silence this warning
snd_pcm_uframes_t pos;
^
= 0
3 warnings generated.
vim +84 sound/soc/starfive/pwmdac-pcm.c
77
78 static void sf_pcm_transfer(struct sf_pwmdac_dev *dev, bool push)
79 {
80 struct snd_pcm_substream *substream;
81 bool active, period_elapsed;
82
83 rcu_read_lock();
> 84 if (push)
85 substream = rcu_dereference(dev->tx_substream);
86
87 active = substream && snd_pcm_running(substream);
88 if (active) {
89 unsigned int ptr;
90 unsigned int new_ptr;
91
> 92 if (push) {
93 ptr = READ_ONCE(dev->tx_ptr);
94 new_ptr = dev->tx_fn(dev, substream->runtime, ptr,
95 &period_elapsed);
96 cmpxchg(&dev->tx_ptr, ptr, new_ptr);
97 }
98
99 if (period_elapsed)
100 snd_pcm_period_elapsed(substream);
101 }
102 rcu_read_unlock();
103 }
104
105 void sf_pwmdac_pcm_push_tx(struct sf_pwmdac_dev *dev)
106 {
107 sf_pcm_transfer(dev, true);
108 }
109
110
111 static int sf_pcm_open(struct snd_soc_component *component,
112 struct snd_pcm_substream *substream)
113 {
114 struct snd_pcm_runtime *runtime = substream->runtime;
115 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
116 struct sf_pwmdac_dev *dev = snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0));
117
118 snd_soc_set_runtime_hwparams(substream, &sf_pcm_hardware);
119 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
120 runtime->private_data = dev;
121
122 return 0;
123 }
124
125
126 static int sf_pcm_close(struct snd_soc_component *component,
127 struct snd_pcm_substream *substream)
128 {
129 synchronize_rcu();
130 return 0;
131 }
132
133 static int sf_pcm_hw_params(struct snd_soc_component *component,
134 struct snd_pcm_substream *substream,
135 struct snd_pcm_hw_params *hw_params)
136 {
137 struct snd_pcm_runtime *runtime = substream->runtime;
138 struct sf_pwmdac_dev *dev = runtime->private_data;
139
140 switch (params_channels(hw_params)) {
141 case 2:
142 break;
143 default:
144 dev_err(dev->dev, "invalid channels number\n");
145 return -EINVAL;
146 }
147
148 switch (params_format(hw_params)) {
149 case SNDRV_PCM_FORMAT_U8:
150 case SNDRV_PCM_FORMAT_S8:
151 dev->tx_fn = sf_pwmdac_pcm_tx_8;
152 break;
153 case SNDRV_PCM_FORMAT_S16_LE:
154 dev->tx_fn = sf_pwmdac_pcm_tx_16;
155 break;
156 default:
157 dev_err(dev->dev, "invalid format\n");
158 return -EINVAL;
159 }
160
161 return 0;
162 }
163
164
165 static int sf_pcm_trigger(struct snd_soc_component *component,
166 struct snd_pcm_substream *substream, int cmd)
167 {
168 struct snd_pcm_runtime *runtime = substream->runtime;
169 struct sf_pwmdac_dev *dev = runtime->private_data;
170 int ret = 0;
171
172 switch (cmd) {
173 case SNDRV_PCM_TRIGGER_START:
174 case SNDRV_PCM_TRIGGER_RESUME:
175 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
176 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
177 WRITE_ONCE(dev->tx_ptr, 0);
178 rcu_assign_pointer(dev->tx_substream, substream);
179 }
180 break;
181 case SNDRV_PCM_TRIGGER_STOP:
182 case SNDRV_PCM_TRIGGER_SUSPEND:
183 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
184 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
185 rcu_assign_pointer(dev->tx_substream, NULL);
186 break;
187 default:
188 ret = -EINVAL;
189 break;
190 }
191
192 return ret;
193 }
194
195 static snd_pcm_uframes_t sf_pcm_pointer(struct snd_soc_component *component,
196 struct snd_pcm_substream *substream)
197 {
198 struct snd_pcm_runtime *runtime = substream->runtime;
199 struct sf_pwmdac_dev *dev = runtime->private_data;
200 snd_pcm_uframes_t pos;
201
> 202 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
203 pos = READ_ONCE(dev->tx_ptr);
204
205 return pos < runtime->buffer_size ? pos : 0;
206 }
207
--
0-DAY CI Kernel Test Service
https://01.org/lkp