diff mbox series

[10/11] ALSA: control: Take lock in snd_ctl_find_id() and snd_ctl_find_numid()

Message ID 20230718141304.1032-11-tiwai@suse.de (mailing list archive)
State New, archived
Headers show
Series ALSA: Make control API taking controls_rwsem consistently | expand

Commit Message

Takashi Iwai July 18, 2023, 2:13 p.m. UTC
Now all needed callers have been replaced with *_locked() versions,
let's turn on the locking in snd_ctl_find_id() and
snd_ctl_find_numid().

This patch also adds the lockdep assertions for debugging, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/control.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Oswald Buddenhagen July 19, 2023, 10:20 a.m. UTC | #1
On Tue, Jul 18, 2023 at 04:13:03PM +0200, Takashi Iwai wrote:
>Now all needed callers have been replaced with *_locked() versions,
>
i don't understand why you made that a separate patch, given that there 
is no separate conversion step in between. i'd just squash it into the 
parent, and also absorb the followup commit.

regards
Takashi Iwai July 19, 2023, 10:45 a.m. UTC | #2
On Wed, 19 Jul 2023 12:20:18 +0200,
Oswald Buddenhagen wrote:
> 
> On Tue, Jul 18, 2023 at 04:13:03PM +0200, Takashi Iwai wrote:
> > Now all needed callers have been replaced with *_locked() versions,
> > 
> i don't understand why you made that a separate patch, given that
> there is no separate conversion step in between. i'd just squash it
> into the parent, and also absorb the followup commit.

The logic is that the first patch does the API function rename and
replaces the existing calls in 1:1 manner, while the second patch
replaces the open code in emu10k1.


Takashi
diff mbox series

Patch

diff --git a/sound/core/control.c b/sound/core/control.c
index 30741293708d..e13e9d6b3b89 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -836,6 +836,7 @@  snd_ctl_find_numid_locked(struct snd_card *card, unsigned int numid)
 {
 	if (snd_BUG_ON(!card || !numid))
 		return NULL;
+	lockdep_assert_held(&card->controls_rwsem);
 #ifdef CONFIG_SND_CTL_FAST_LOOKUP
 	return xa_load(&card->ctl_numids, numid);
 #else
@@ -852,11 +853,18 @@  EXPORT_SYMBOL(snd_ctl_find_numid_locked);
  * Finds the control instance with the given number-id from the card.
  *
  * Return: The pointer of the instance if found, or %NULL if not.
+ *
+ * Note that this function takes card->controls_rwsem lock internally.
  */
 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card,
 					unsigned int numid)
 {
-	return snd_ctl_find_numid_locked(card, numid);
+	struct snd_kcontrol *kctl;
+
+	down_read(&card->controls_rwsem);
+	kctl = snd_ctl_find_numid_locked(card, numid);
+	up_read(&card->controls_rwsem);
+	return kctl;
 }
 EXPORT_SYMBOL(snd_ctl_find_numid);
 
@@ -879,6 +887,7 @@  struct snd_kcontrol *snd_ctl_find_id_locked(struct snd_card *card,
 
 	if (snd_BUG_ON(!card || !id))
 		return NULL;
+	lockdep_assert_held(&card->controls_rwsem);
 	if (id->numid != 0)
 		return snd_ctl_find_numid_locked(card, id->numid);
 #ifdef CONFIG_SND_CTL_FAST_LOOKUP
@@ -905,11 +914,18 @@  EXPORT_SYMBOL(snd_ctl_find_id_locked);
  * Finds the control instance with the given id from the card.
  *
  * Return: The pointer of the instance if found, or %NULL if not.
+ *
+ * Note that this function takes card->controls_rwsem lock internally.
  */
 struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
 				     const struct snd_ctl_elem_id *id)
 {
-	return snd_ctl_find_id_locked(card, id);
+	struct snd_kcontrol *kctl;
+
+	down_read(&card->controls_rwsem);
+	kctl = snd_ctl_find_id_locked(card, id);
+	up_read(&card->controls_rwsem);
+	return kctl;
 }
 EXPORT_SYMBOL(snd_ctl_find_id);