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 434/806] staging: bcm2835-audio: Clean up mutex locks
6 commit ce4bb1aa271a97047b80ac917a5d91b54925913b upstream.
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
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
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.
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>
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(-)
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
34 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
36 - if (mutex_lock_interruptible(&chip->audio_mutex))
38 + mutex_lock(&chip->audio_mutex);
40 BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
42 @@ -99,8 +98,7 @@ static int snd_bcm2835_ctl_put(struct sn
43 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
46 - if (mutex_lock_interruptible(&chip->audio_mutex))
48 + mutex_lock(&chip->audio_mutex);
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);
56 - if (mutex_lock_interruptible(&chip->audio_mutex))
58 + mutex_lock(&chip->audio_mutex);
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
66 - if (mutex_lock_interruptible(&chip->audio_mutex))
68 + mutex_lock(&chip->audio_mutex);
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);
76 - if (mutex_lock_interruptible(&chip->audio_mutex))
78 + mutex_lock(&chip->audio_mutex);
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(
86 - if (mutex_lock_interruptible(&chip->audio_mutex))
88 + mutex_lock(&chip->audio_mutex);
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
98 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
99 - audio_error("Interrupted whilst waiting for lock\n");
102 + mutex_lock(&chip->audio_mutex);
103 audio_info("Alsa open (%d)\n", substream->number);
104 idx = substream->number;
106 @@ -194,10 +191,7 @@ static int snd_bcm2835_playback_close(st
107 struct bcm2835_alsa_stream *alsa_stream;
109 chip = snd_pcm_substream_chip(substream);
110 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
111 - audio_error("Interrupted whilst waiting for lock\n");
114 + mutex_lock(&chip->audio_mutex);
115 runtime = substream->runtime;
116 alsa_stream = runtime->private_data;
118 @@ -274,8 +268,7 @@ static int snd_bcm2835_pcm_prepare(struc
122 - if (mutex_lock_interruptible(&chip->audio_mutex))
124 + mutex_lock(&chip->audio_mutex);
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
132 - mutex_init(&chip->audio_mutex);
133 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
134 - audio_error("Interrupted whilst waiting for lock\n");
137 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm);
141 pcm->private_data = chip;
142 strcpy(pcm->name, "bcm2835 ALSA");
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);
149 - mutex_unlock(&chip->audio_mutex);
154 @@ -485,13 +470,9 @@ int snd_bcm2835_new_spdif_pcm(struct bcm
158 - if (mutex_lock_interruptible(&chip->audio_mutex)) {
159 - audio_error("Interrupted whilst waiting for lock\n");
162 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
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);
174 - mutex_unlock(&chip->audio_mutex);
178 @@ -518,8 +497,6 @@ int snd_bcm2835_new_simple_pcm(struct bc
182 - mutex_init(&chip->audio_mutex);
184 err = snd_pcm_new(chip->card, name, 0, numchannels,
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
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);
198 + mutex_lock(&instance->vchi_mutex);
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);
206 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
207 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
211 + mutex_lock(&instance->vchi_mutex);
212 vchi_service_use(instance->vchi_handle[0]);
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);
219 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
220 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
221 - instance->num_connections);
224 + mutex_lock(&instance->vchi_mutex);
225 vchi_service_use(instance->vchi_handle[0]);
227 instance->result = -1;
228 @@ -569,10 +557,7 @@ int bcm2835_audio_set_params(struct bcm2
232 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
233 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
236 + mutex_lock(&instance->vchi_mutex);
237 vchi_service_use(instance->vchi_handle[0]);
239 instance->result = -1;
240 @@ -629,11 +614,7 @@ static int bcm2835_audio_start_worker(st
244 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
245 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
246 - instance->num_connections);
249 + mutex_lock(&instance->vchi_mutex);
250 vchi_service_use(instance->vchi_handle[0]);
252 m.type = VC_AUDIO_MSG_TYPE_START;
253 @@ -665,11 +646,7 @@ static int bcm2835_audio_stop_worker(str
257 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
258 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
259 - instance->num_connections);
262 + mutex_lock(&instance->vchi_mutex);
263 vchi_service_use(instance->vchi_handle[0]);
265 m.type = VC_AUDIO_MSG_TYPE_STOP;
266 @@ -704,11 +681,7 @@ int bcm2835_audio_close(struct bcm2835_a
268 my_workqueue_quit(alsa_stream);
270 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
271 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
272 - instance->num_connections);
275 + mutex_lock(&instance->vchi_mutex);
276 vchi_service_use(instance->vchi_handle[0]);
278 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
279 @@ -761,11 +734,7 @@ static int bcm2835_audio_write_worker(st
281 LOG_INFO(" Writing %d bytes from %p\n", count, src);
283 - if (mutex_lock_interruptible(&instance->vchi_mutex)) {
284 - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
285 - instance->num_connections);
288 + mutex_lock(&instance->vchi_mutex);
289 vchi_service_use(instance->vchi_handle[0]);
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
298 + mutex_init(&chip->audio_mutex);
300 chip->vchi_ctx = devres_find(card->dev->parent,
301 bcm2835_devm_free_vchi_ctx, NULL, NULL);