ALSA: firewire-motu: cease from delayed card registration
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 7 Jun 2021 08:12:48 +0000 (17:12 +0900)
committerTakashi Iwai <tiwai@suse.de>
Mon, 7 Jun 2021 15:14:42 +0000 (17:14 +0200)
The delayed registration of sound card instance brings less benefit than
complication of kobject management. This commit ceases from it.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20210607081250.13397-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/motu/motu.c
sound/firewire/motu/motu.h

index 2a8a6ea..531eeb3 100644 (file)
@@ -57,22 +57,31 @@ static void motu_card_free(struct snd_card *card)
 
        snd_motu_transaction_unregister(motu);
        snd_motu_stream_destroy_duplex(motu);
+
+       mutex_destroy(&motu->mutex);
+       fw_unit_put(motu->unit);
 }
 
-static void do_registration(struct work_struct *work)
+static int motu_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
 {
-       struct snd_motu *motu = container_of(work, struct snd_motu, dwork.work);
+       struct snd_card *card;
+       struct snd_motu *motu;
        int err;
 
-       if (motu->registered)
-               return;
-
-       err = snd_card_new(&motu->unit->device, -1, NULL, THIS_MODULE, 0,
-                          &motu->card);
+       err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*motu), &card);
        if (err < 0)
-               return;
-       motu->card->private_free = motu_card_free;
-       motu->card->private_data = motu;
+               return err;
+       card->private_free = motu_card_free;
+
+       motu = card->private_data;
+       motu->unit = fw_unit_get(unit);
+       dev_set_drvdata(&unit->device, motu);
+       motu->card = card;
+
+       motu->spec = (const struct snd_motu_spec *)entry->driver_data;
+       mutex_init(&motu->mutex);
+       spin_lock_init(&motu->lock);
+       init_waitqueue_head(&motu->hwdep_wait);
 
        name_card(motu);
 
@@ -103,71 +112,28 @@ static void do_registration(struct work_struct *work)
        if (err < 0)
                goto error;
 
-       err = snd_card_register(motu->card);
+       err = snd_card_register(card);
        if (err < 0)
                goto error;
 
-       motu->registered = true;
-
-       return;
-error:
-       snd_card_free(motu->card);
-       dev_info(&motu->unit->device,
-                "Sound card registration failed: %d\n", err);
-}
-
-static int motu_probe(struct fw_unit *unit,
-                     const struct ieee1394_device_id *entry)
-{
-       struct snd_motu *motu;
-
-       /* Allocate this independently of sound card instance. */
-       motu = devm_kzalloc(&unit->device, sizeof(struct snd_motu), GFP_KERNEL);
-       if (!motu)
-               return -ENOMEM;
-       motu->unit = fw_unit_get(unit);
-       dev_set_drvdata(&unit->device, motu);
-
-       motu->spec = (const struct snd_motu_spec *)entry->driver_data;
-       mutex_init(&motu->mutex);
-       spin_lock_init(&motu->lock);
-       init_waitqueue_head(&motu->hwdep_wait);
-
-       /* Allocate and register this sound card later. */
-       INIT_DEFERRABLE_WORK(&motu->dwork, do_registration);
-       snd_fw_schedule_registration(unit, &motu->dwork);
-
        return 0;
+error:
+       snd_card_free(card);
+       return err;
 }
 
 static void motu_remove(struct fw_unit *unit)
 {
        struct snd_motu *motu = dev_get_drvdata(&unit->device);
 
-       /*
-        * Confirm to stop the work for registration before the sound card is
-        * going to be released. The work is not scheduled again because bus
-        * reset handler is not called anymore.
-        */
-       cancel_delayed_work_sync(&motu->dwork);
-
-       if (motu->registered) {
-               // Block till all of ALSA character devices are released.
-               snd_card_free(motu->card);
-       }
-
-       mutex_destroy(&motu->mutex);
-       fw_unit_put(motu->unit);
+       // Block till all of ALSA character devices are released.
+       snd_card_free(motu->card);
 }
 
 static void motu_bus_update(struct fw_unit *unit)
 {
        struct snd_motu *motu = dev_get_drvdata(&unit->device);
 
-       /* Postpone a workqueue for deferred registration. */
-       if (!motu->registered)
-               snd_fw_schedule_registration(unit, &motu->dwork);
-
        /* The handler address register becomes initialized. */
        snd_motu_transaction_reregister(motu);
 }
index 674e3dc..c5c0e44 100644 (file)
@@ -54,9 +54,6 @@ struct snd_motu {
        struct mutex mutex;
        spinlock_t lock;
 
-       bool registered;
-       struct delayed_work dwork;
-
        /* Model dependent information. */
        const struct snd_motu_spec *spec;