ath79: add support for COMFAST CF-E130N v2
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0372-staging-bcm2835-audio-Clean-up-mutex-locks.patch
1 From 96588b9ccaddd69a832a07e2e3f2f3299e6d6c3a Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:30 +0200
4 Subject: [PATCH] staging: bcm2835-audio: Clean up mutex locks
5
6 commit ce4bb1aa271a97047b80ac917a5d91b54925913b upstream.
7
8 snd-bcm2835 driver takes the lock with mutex_lock_interruptible() in
9 all places, which don't make sense. Replace them with the simple
10 mutex_lock().
11
12 Also taking a mutex lock right after creating it for each PCM object
13 is nonsense, too. It cannot be racy at that point. We can get rid of
14 it.
15
16 Last but not least, initializing chip->audio_mutex at each place is
17 error-prone. Initialize properly at creating the chip object in
18 snd_bcm2835_create() instead.
19
20 Signed-off-by: Takashi Iwai <tiwai@suse.de>
21 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 ---
24 .../vc04_services/bcm2835-audio/bcm2835-ctl.c | 18 +++----
25 .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 33 ++-----------
26 .../bcm2835-audio/bcm2835-vchiq.c | 47 ++++---------------
27 .../vc04_services/bcm2835-audio/bcm2835.c | 1 +
28 4 files changed, 20 insertions(+), 79 deletions(-)
29
30 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
31 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
32 @@ -77,8 +77,7 @@ static int snd_bcm2835_ctl_get(struct sn
33 {
34 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
35
36 - if (mutex_lock_interruptible(&chip->audio_mutex))
37 - return -EINTR;
38 + mutex_lock(&chip->audio_mutex);
39
40 BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
41
42 @@ -99,8 +98,7 @@ static int snd_bcm2835_ctl_put(struct sn
43 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
44 int changed = 0;
45
46 - if (mutex_lock_interruptible(&chip->audio_mutex))
47 - return -EINTR;
48 + mutex_lock(&chip->audio_mutex);
49
50 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
51 audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
52 @@ -187,8 +185,7 @@ static int snd_bcm2835_spdif_default_get
53 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
54 int i;
55
56 - if (mutex_lock_interruptible(&chip->audio_mutex))
57 - return -EINTR;
58 + mutex_lock(&chip->audio_mutex);
59
60 for (i = 0; i < 4; i++)
61 ucontrol->value.iec958.status[i] =
62 @@ -205,8 +202,7 @@ static int snd_bcm2835_spdif_default_put
63 unsigned int val = 0;
64 int i, change;
65
66 - if (mutex_lock_interruptible(&chip->audio_mutex))
67 - return -EINTR;
68 + mutex_lock(&chip->audio_mutex);
69
70 for (i = 0; i < 4; i++)
71 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
72 @@ -251,8 +247,7 @@ static int snd_bcm2835_spdif_stream_get(
73 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
74 int i;
75
76 - if (mutex_lock_interruptible(&chip->audio_mutex))
77 - return -EINTR;
78 + mutex_lock(&chip->audio_mutex);
79
80 for (i = 0; i < 4; i++)
81 ucontrol->value.iec958.status[i] =
82 @@ -269,8 +264,7 @@ static int snd_bcm2835_spdif_stream_put(
83 unsigned int val = 0;
84 int i, change;
85
86 - if (mutex_lock_interruptible(&chip->audio_mutex))
87 - return -EINTR;
88 + mutex_lock(&chip->audio_mutex);
89
90 for (i = 0; i < 4; i++)
91 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
92 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
93 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
94 @@ -99,10 +99,7 @@ static int snd_bcm2835_playback_open_gen
95 int idx;
96 int err;
97
98 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
99 - audio_error("Interrupted whilst waiting for lock\n");
100 - return -EINTR;
101 - }
102 + mutex_lock(&chip->audio_mutex);
103 audio_info("Alsa open (%d)\n", substream->number);
104 idx = substream->number;
105
106 @@ -194,10 +191,7 @@ static int snd_bcm2835_playback_close(st
107 struct bcm2835_alsa_stream *alsa_stream;
108
109 chip = snd_pcm_substream_chip(substream);
110 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
111 - audio_error("Interrupted whilst waiting for lock\n");
112 - return -EINTR;
113 - }
114 + mutex_lock(&chip->audio_mutex);
115 runtime = substream->runtime;
116 alsa_stream = runtime->private_data;
117
118 @@ -274,8 +268,7 @@ static int snd_bcm2835_pcm_prepare(struc
119 int channels;
120 int err;
121
122 - if (mutex_lock_interruptible(&chip->audio_mutex))
123 - return -EINTR;
124 + mutex_lock(&chip->audio_mutex);
125
126 /* notify the vchiq that it should enter spdif passthrough mode by
127 * setting channels=0 (see
128 @@ -449,14 +442,9 @@ int snd_bcm2835_new_pcm(struct bcm2835_c
129 struct snd_pcm *pcm;
130 int err;
131
132 - mutex_init(&chip->audio_mutex);
133 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
134 - audio_error("Interrupted whilst waiting for lock\n");
135 - return -EINTR;
136 - }
137 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm);
138 if (err < 0)
139 - goto out;
140 + return err;
141 pcm->private_data = chip;
142 strcpy(pcm->name, "bcm2835 ALSA");
143 chip->pcm = pcm;
144 @@ -474,9 +462,6 @@ int snd_bcm2835_new_pcm(struct bcm2835_c
145 snd_bcm2835_playback_hw.buffer_bytes_max,
146 snd_bcm2835_playback_hw.buffer_bytes_max);
147
148 -out:
149 - mutex_unlock(&chip->audio_mutex);
150 -
151 return 0;
152 }
153
154 @@ -485,13 +470,9 @@ int snd_bcm2835_new_spdif_pcm(struct bcm
155 struct snd_pcm *pcm;
156 int err;
157
158 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
159 - audio_error("Interrupted whilst waiting for lock\n");
160 - return -EINTR;
161 - }
162 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
163 if (err < 0)
164 - goto out;
165 + return err;
166
167 pcm->private_data = chip;
168 strcpy(pcm->name, "bcm2835 IEC958/HDMI");
169 @@ -504,8 +485,6 @@ int snd_bcm2835_new_spdif_pcm(struct bcm
170 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
171 snd_dma_continuous_data(GFP_KERNEL),
172 snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max);
173 -out:
174 - mutex_unlock(&chip->audio_mutex);
175
176 return 0;
177 }
178 @@ -518,8 +497,6 @@ int snd_bcm2835_new_simple_pcm(struct bc
179 struct snd_pcm *pcm;
180 int err;
181
182 - mutex_init(&chip->audio_mutex);
183 -
184 err = snd_pcm_new(chip->card, name, 0, numchannels,
185 0, &pcm);
186 if (err)
187 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
188 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
189 @@ -319,11 +319,7 @@ static int vc_vchi_audio_deinit(struct b
190 }
191
192 LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
193 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
194 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
195 - instance->num_connections);
196 - return -EINTR;
197 - }
198 + mutex_lock(&instance->vchi_mutex);
199
200 /* Close all VCHI service connections */
201 for (i = 0; i < instance->num_connections; i++) {
202 @@ -434,11 +430,7 @@ int bcm2835_audio_open(struct bcm2835_al
203 instance = alsa_stream->instance;
204 LOG_DBG(" instance (%p)\n", instance);
205
206 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
207 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
208 - ret = -EINTR;
209 - goto free_wq;
210 - }
211 + mutex_lock(&instance->vchi_mutex);
212 vchi_service_use(instance->vchi_handle[0]);
213
214 m.type = VC_AUDIO_MSG_TYPE_OPEN;
215 @@ -479,11 +471,7 @@ static int bcm2835_audio_set_ctls_chan(s
216 LOG_INFO(" Setting ALSA dest(%d), volume(%d)\n",
217 chip->dest, chip->volume);
218
219 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
220 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
221 - instance->num_connections);
222 - return -EINTR;
223 - }
224 + mutex_lock(&instance->vchi_mutex);
225 vchi_service_use(instance->vchi_handle[0]);
226
227 instance->result = -1;
228 @@ -569,10 +557,7 @@ int bcm2835_audio_set_params(struct bcm2
229 return -EINVAL;
230 }
231
232 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
233 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
234 - return -EINTR;
235 - }
236 + mutex_lock(&instance->vchi_mutex);
237 vchi_service_use(instance->vchi_handle[0]);
238
239 instance->result = -1;
240 @@ -629,11 +614,7 @@ static int bcm2835_audio_start_worker(st
241 int status;
242 int ret;
243
244 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
245 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
246 - instance->num_connections);
247 - return -EINTR;
248 - }
249 + mutex_lock(&instance->vchi_mutex);
250 vchi_service_use(instance->vchi_handle[0]);
251
252 m.type = VC_AUDIO_MSG_TYPE_START;
253 @@ -665,11 +646,7 @@ static int bcm2835_audio_stop_worker(str
254 int status;
255 int ret;
256
257 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
258 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
259 - instance->num_connections);
260 - return -EINTR;
261 - }
262 + mutex_lock(&instance->vchi_mutex);
263 vchi_service_use(instance->vchi_handle[0]);
264
265 m.type = VC_AUDIO_MSG_TYPE_STOP;
266 @@ -704,11 +681,7 @@ int bcm2835_audio_close(struct bcm2835_a
267
268 my_workqueue_quit(alsa_stream);
269
270 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
271 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
272 - instance->num_connections);
273 - return -EINTR;
274 - }
275 + mutex_lock(&instance->vchi_mutex);
276 vchi_service_use(instance->vchi_handle[0]);
277
278 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
279 @@ -761,11 +734,7 @@ static int bcm2835_audio_write_worker(st
280
281 LOG_INFO(" Writing %d bytes from %p\n", count, src);
282
283 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
284 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
285 - instance->num_connections);
286 - return -EINTR;
287 - }
288 + mutex_lock(&instance->vchi_mutex);
289 vchi_service_use(instance->vchi_handle[0]);
290
291 if (instance->peer_version == 0 &&
292 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
293 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
294 @@ -149,6 +149,7 @@ static int snd_bcm2835_create(struct snd
295 return -ENOMEM;
296
297 chip->card = card;
298 + mutex_init(&chip->audio_mutex);
299
300 chip->vchi_ctx = devres_find(card->dev->parent,
301 bcm2835_devm_free_vchi_ctx, NULL, NULL);