Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: firewire-digi00x: cease from delayed card registration

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-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Takashi Sakamoto and committed by
Takashi Iwai
9067c181 9536c751

+29 -75
+29 -72
sound/firewire/digi00x/digi00x.c
··· 47 47 48 48 snd_dg00x_stream_destroy_duplex(dg00x); 49 49 snd_dg00x_transaction_unregister(dg00x); 50 + 51 + mutex_destroy(&dg00x->mutex); 52 + fw_unit_put(dg00x->unit); 50 53 } 51 54 52 - static void do_registration(struct work_struct *work) 55 + static int snd_dg00x_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry) 53 56 { 54 - struct snd_dg00x *dg00x = 55 - container_of(work, struct snd_dg00x, dwork.work); 57 + struct snd_card *card; 58 + struct snd_dg00x *dg00x; 56 59 int err; 57 60 58 - if (dg00x->registered) 59 - return; 60 - 61 - err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0, 62 - &dg00x->card); 61 + err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*dg00x), &card); 63 62 if (err < 0) 64 - return; 65 - dg00x->card->private_free = dg00x_card_free; 66 - dg00x->card->private_data = dg00x; 63 + return err; 64 + card->private_free = dg00x_card_free; 65 + 66 + dg00x = card->private_data; 67 + dg00x->unit = fw_unit_get(unit); 68 + dev_set_drvdata(&unit->device, dg00x); 69 + dg00x->card = card; 70 + 71 + mutex_init(&dg00x->mutex); 72 + spin_lock_init(&dg00x->lock); 73 + init_waitqueue_head(&dg00x->hwdep_wait); 74 + 75 + dg00x->is_console = entry->model_id == MODEL_CONSOLE; 67 76 68 77 err = name_card(dg00x); 69 78 if (err < 0) ··· 100 91 if (err < 0) 101 92 goto error; 102 93 103 - err = snd_card_register(dg00x->card); 94 + err = snd_card_register(card); 104 95 if (err < 0) 105 96 goto error; 106 97 107 - dg00x->registered = true; 108 - 109 - return; 110 - error: 111 - snd_card_free(dg00x->card); 112 - dev_info(&dg00x->unit->device, 113 - "Sound card registration failed: %d\n", err); 114 - } 115 - 116 - static int snd_dg00x_probe(struct fw_unit *unit, 117 - const struct ieee1394_device_id *entry) 118 - { 119 - struct snd_dg00x *dg00x; 120 - 121 - /* Allocate this independent of sound card instance. */ 122 - dg00x = devm_kzalloc(&unit->device, sizeof(struct snd_dg00x), 123 - GFP_KERNEL); 124 - if (!dg00x) 125 - return -ENOMEM; 126 - 127 - dg00x->unit = fw_unit_get(unit); 128 - dev_set_drvdata(&unit->device, dg00x); 129 - 130 - mutex_init(&dg00x->mutex); 131 - spin_lock_init(&dg00x->lock); 132 - init_waitqueue_head(&dg00x->hwdep_wait); 133 - 134 - dg00x->is_console = entry->model_id == MODEL_CONSOLE; 135 - 136 - /* Allocate and register this sound card later. */ 137 - INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration); 138 - snd_fw_schedule_registration(unit, &dg00x->dwork); 139 - 140 98 return 0; 99 + error: 100 + snd_card_free(card); 101 + return err; 141 102 } 142 103 143 104 static void snd_dg00x_update(struct fw_unit *unit) 144 105 { 145 106 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); 146 107 147 - /* Postpone a workqueue for deferred registration. */ 148 - if (!dg00x->registered) 149 - snd_fw_schedule_registration(unit, &dg00x->dwork); 150 - 151 108 snd_dg00x_transaction_reregister(dg00x); 152 109 153 - /* 154 - * After registration, userspace can start packet streaming, then this 155 - * code block works fine. 156 - */ 157 - if (dg00x->registered) { 158 - mutex_lock(&dg00x->mutex); 159 - snd_dg00x_stream_update_duplex(dg00x); 160 - mutex_unlock(&dg00x->mutex); 161 - } 110 + mutex_lock(&dg00x->mutex); 111 + snd_dg00x_stream_update_duplex(dg00x); 112 + mutex_unlock(&dg00x->mutex); 162 113 } 163 114 164 115 static void snd_dg00x_remove(struct fw_unit *unit) 165 116 { 166 117 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); 167 118 168 - /* 169 - * Confirm to stop the work for registration before the sound card is 170 - * going to be released. The work is not scheduled again because bus 171 - * reset handler is not called anymore. 172 - */ 173 - cancel_delayed_work_sync(&dg00x->dwork); 174 - 175 - if (dg00x->registered) { 176 - // Block till all of ALSA character devices are released. 177 - snd_card_free(dg00x->card); 178 - } 179 - 180 - mutex_destroy(&dg00x->mutex); 181 - fw_unit_put(dg00x->unit); 119 + // Block till all of ALSA character devices are released. 120 + snd_card_free(dg00x->card); 182 121 } 183 122 184 123 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
-3
sound/firewire/digi00x/digi00x.h
··· 37 37 struct mutex mutex; 38 38 spinlock_t lock; 39 39 40 - bool registered; 41 - struct delayed_work dwork; 42 - 43 40 struct amdtp_stream tx_stream; 44 41 struct fw_iso_resources tx_resources; 45 42