ALSA: core: Warn on empty module

Message ID
State Accepted
Commit 81033c6b584b44514cbb16fffc26ca29a0fa6270
Headers show
  • ALSA: core: Warn on empty module
Related show

Commit Message

Takashi Iwai June 24, 2020, 4:03 p.m.
The module argument passed to snd_card_new() must be a valid non-NULL
pointer when the module support is enabled.  Since ASoC driver passes
the argument from each snd_soc_card definition, one may forget to set
the owner field and lead to a NULL module easily.

For catching such an overlook, add a WARN_ON() in snd_card_new().
Also, put the card->module assignment in the ifdef block for a very
minor optimization.

Signed-off-by: Takashi Iwai <>
 sound/core/init.c | 3 +++
 1 file changed, 3 insertions(+)


diff --git a/sound/core/init.c b/sound/core/init.c
index b02a99766351..0478847ba2b8 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -203,7 +203,10 @@  int snd_card_new(struct device *parent, int idx, const char *xid,
 	card->dev = parent;
 	card->number = idx;
+#ifdef MODULE
+	WARN_ON(!module);
 	card->module = module;