Skip to contentSkip to conversation

ALSA: seq: bind seq driver automatically

PATCH New Takashi Iwai 1 participant 4 messages Oct 17, 2014 Sound

lore
Share & tools
lore
#0 lore raw

v2 cover ALSA: seq: bind seq driver automatically

Hi,

this is a patchset split from the previous patch for fixing the autoloading issue of sequencer stuff. The end result is the exactly same changes.

[PATCH 1/3] ALSA: seq: Use atomic ops for autoload refcount [PATCH 2/3] ALSA: seq: bind seq driver automatically [PATCH 3/3] Subject: ALSA: seq: Remove autoload locks in driver

Takashi

#1 lore raw

PATCH v2 1/3 ALSA: seq: Use atomic ops for autoload refcount

... just to robustify for races.

---
 sound/core/seq/seq_device.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/core/seq/seq_device.c +4 -4
index 91a786a783e1..775ea9390110 100644
@@ -127,15 +127,15 @@ static void snd_seq_device_info(struct snd_info_entry *entry,
 
 #ifdef CONFIG_MODULES
 /* avoid auto-loading during module_init() */
-static int snd_seq_in_init;
+static atomic_t snd_seq_in_init = ATOMIC_INIT(0);
 void snd_seq_autoload_lock(void)
 {
-	snd_seq_in_init++;
+	atomic_inc(&snd_seq_in_init);
 }
 
 void snd_seq_autoload_unlock(void)
 {
-	snd_seq_in_init--;
+	atomic_dec(&snd_seq_in_init);
 }
 #endif
 
@@ -147,7 +147,7 @@ void snd_seq_device_load_drivers(void)
 	/* Calling request_module during module_init()
 	 * may cause blocking.
 	 */
-	if (snd_seq_in_init)
+	if (atomic_read(&snd_seq_in_init))
 		return;
 
 	mutex_lock(&ops_mutex);
Signature · 1 line
2.1.2
#2 lore raw

PATCH v2 2/3 ALSA: seq: bind seq driver automatically

In reply to Takashi Iwai

Currently the sequencer module binding is performed independently from the card module itself. The reason behind it is to keep the sequencer stuff optional and allow the system running without it (e.g. for using PCM or rawmidi only). This works in most cases, but a remaining problem is that the binding isn't done automatically when a new driver module is probed. Typically this becomes visible when a hotplug driver like usb audio is used.

This patch tries to address this and other potential issues. First, the seq-binder (seq_device.c) tries to load a missing driver module at creating a new device object. This is done asynchronously in a workq for avoiding the deadlock (modprobe call in module init path).

This action, however, should be enabled only when the sequencer stuff was already initialized, i.e. snd-seq module was already loaded. For that, a new function, snd_seq_autoload_init() is introduced here; this clears the blocking of autoloading, and also tries to load all pending driver modules.

---
 include/sound/seq_kernel.h  |  4 ++
 sound/core/seq/seq.c        |  3 ++
 sound/core/seq/seq_device.c | 92 +++++++++++++++++++++++++++++++++------------
 3 files changed, 76 insertions(+), 23 deletions(-)
include/sound/seq_kernel.h +4 -0
index 2398521f0998..eea5400fe373 100644
@@ -108,9 +108,13 @@ int snd_seq_event_port_detach(int client, int port);
 #ifdef CONFIG_MODULES
 void snd_seq_autoload_lock(void);
 void snd_seq_autoload_unlock(void);
+void snd_seq_autoload_init(void);
+#define snd_seq_autoload_exit()	snd_seq_autoload_lock()
 #else
 #define snd_seq_autoload_lock()
 #define snd_seq_autoload_unlock()
+#define snd_seq_autoload_init()
+#define snd_seq_autoload_exit()
 #endif
 
 #endif /* __SOUND_SEQ_KERNEL_H */
sound/core/seq/seq.c +3 -0
index 712110561082..bebdd2e920ca 100644
@@ -110,6 +110,7 @@ static int __init alsa_seq_init(void)
 	if ((err = snd_seq_system_client_init()) < 0)
 		goto error;
 
+	snd_seq_autoload_init();
  error:
 	snd_seq_autoload_unlock();
 	return err;
@@ -131,6 +132,8 @@ static void __exit alsa_seq_exit(void)
 
 	/* release event memory */
 	snd_sequencer_memory_done();
+
+	snd_seq_autoload_exit();
 }
 
 module_init(alsa_seq_init)
sound/core/seq/seq_device.c +69 -23

139 lines not on this page · raw message

Signature · 1 line
2.1.2
#3 lore raw

PATCH v2 3/3 Subject: ALSA: seq: Remove autoload locks in driver registration

In reply to Takashi Iwai

Since we're calling request_module() asynchronously now, we can get rid of the autoload lock in snd_seq_device_register_driver(), as well as in the snd-seq driver registration itself. This enables the automatic loading of dependent sequencer modules, such as snd-seq-virmidi from snd-emu10k1-synth.

---
 sound/core/seq/seq.c        | 2 --
 sound/core/seq/seq_device.c | 7 +------
 2 files changed, 1 insertion(+), 8 deletions(-)
sound/core/seq/seq.c +0 -2
index bebdd2e920ca..7e0aabb808a6 100644
@@ -86,7 +86,6 @@ static int __init alsa_seq_init(void)
 {
 	int err;
 
-	snd_seq_autoload_lock();
 	if ((err = client_init_data()) < 0)
 		goto error;
 
@@ -112,7 +111,6 @@ static int __init alsa_seq_init(void)
 
 	snd_seq_autoload_init();
  error:
-	snd_seq_autoload_unlock();
 	return err;
 }
 
sound/core/seq/seq_device.c +1 -6
index ebee034f8ab5..6b31ca09caf7 100644
@@ -360,16 +360,12 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
 	    entry->init_device == NULL || entry->free_device == NULL)
 		return -EINVAL;
 
-	snd_seq_autoload_lock();
 	ops = find_driver(id, 1);
-	if (ops == NULL) {
-		snd_seq_autoload_unlock();
+	if (ops == NULL)
 		return -ENOMEM;
-	}
 	if (ops->driver & DRIVER_LOADED) {
 		pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id);
 		unlock_driver(ops);
-		snd_seq_autoload_unlock();
 		return -EBUSY;
 	}
 
@@ -386,7 +382,6 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
 	mutex_unlock(&ops->reg_mutex);
 
 	unlock_driver(ops);
-	snd_seq_autoload_unlock();
 
 	return 0;
 }
Signature · 1 line
2.1.2