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

ALSA: firewire: simplify cleanup process when failing to register sound card

In former commits, .private_free callback releases resources just for
data transmission. This release function can be called without the
resources are actually allocated in error paths.

This commit applies a small refactoring to clean up codes in error
paths.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Takashi Sakamoto and committed by
Takashi Iwai
3babca45 873608dc

+49 -143
+7 -20
sound/firewire/bebob/bebob.c
··· 126 126 return err; 127 127 } 128 128 129 - static void bebob_free(struct snd_bebob *bebob) 129 + static void 130 + bebob_card_free(struct snd_card *card) 130 131 { 132 + struct snd_bebob *bebob = card->private_data; 133 + 131 134 mutex_lock(&devices_mutex); 132 135 clear_bit(bebob->card_index, devices_used); 133 136 mutex_unlock(&devices_mutex); 134 137 135 138 snd_bebob_stream_destroy_duplex(bebob); 136 - } 137 - 138 - /* 139 - * This module releases the FireWire unit data after all ALSA character devices 140 - * are released by applications. This is for releasing stream data or finishing 141 - * transactions safely. Thus at returning from .remove(), this module still keep 142 - * references for the unit. 143 - */ 144 - static void 145 - bebob_card_free(struct snd_card *card) 146 - { 147 - bebob_free(card->private_data); 148 139 } 149 140 150 141 static const struct snd_bebob_spec * ··· 193 202 set_bit(card_index, devices_used); 194 203 mutex_unlock(&devices_mutex); 195 204 205 + bebob->card->private_free = bebob_card_free; 206 + bebob->card->private_data = bebob; 207 + 196 208 err = name_device(bebob); 197 209 if (err < 0) 198 210 goto error; ··· 235 241 if (err < 0) 236 242 goto error; 237 243 238 - /* 239 - * After registered, bebob instance can be released corresponding to 240 - * releasing the sound card instance. 241 - */ 242 - bebob->card->private_free = bebob_card_free; 243 - bebob->card->private_data = bebob; 244 244 bebob->registered = true; 245 245 246 246 return; 247 247 error: 248 - snd_bebob_stream_destroy_duplex(bebob); 249 248 snd_card_free(bebob->card); 250 249 dev_info(&bebob->unit->device, 251 250 "Sound card registration failed: %d\n", err);
+6 -22
sound/firewire/dice/dice.c
··· 122 122 strcpy(card->mixername, "DICE"); 123 123 } 124 124 125 - static void dice_free(struct snd_dice *dice) 126 - { 127 - snd_dice_stream_destroy_duplex(dice); 128 - snd_dice_transaction_destroy(dice); 129 - } 130 - 131 - /* 132 - * This module releases the FireWire unit data after all ALSA character devices 133 - * are released by applications. This is for releasing stream data or finishing 134 - * transactions safely. Thus at returning from .remove(), this module still keep 135 - * references for the unit. 136 - */ 137 125 static void dice_card_free(struct snd_card *card) 138 126 { 139 - dice_free(card->private_data); 127 + struct snd_dice *dice = card->private_data; 128 + 129 + snd_dice_stream_destroy_duplex(dice); 130 + snd_dice_transaction_destroy(dice); 140 131 } 141 132 142 133 static void do_registration(struct work_struct *work) ··· 142 151 &dice->card); 143 152 if (err < 0) 144 153 return; 154 + dice->card->private_free = dice_card_free; 155 + dice->card->private_data = dice; 145 156 146 157 err = snd_dice_transaction_init(dice); 147 158 if (err < 0) ··· 181 188 if (err < 0) 182 189 goto error; 183 190 184 - /* 185 - * After registered, dice instance can be released corresponding to 186 - * releasing the sound card instance. 187 - */ 188 - dice->card->private_free = dice_card_free; 189 - dice->card->private_data = dice; 190 191 dice->registered = true; 191 192 192 193 return; 193 194 error: 194 - snd_dice_stream_destroy_duplex(dice); 195 - snd_dice_transaction_destroy(dice); 196 - snd_dice_stream_destroy_duplex(dice); 197 195 snd_card_free(dice->card); 198 196 dev_info(&dice->unit->device, 199 197 "Sound card registration failed: %d\n", err);
+6 -11
sound/firewire/digi00x/digi00x.c
··· 41 41 return 0; 42 42 } 43 43 44 - static void dg00x_free(struct snd_dg00x *dg00x) 45 - { 46 - snd_dg00x_stream_destroy_duplex(dg00x); 47 - snd_dg00x_transaction_unregister(dg00x); 48 - } 49 - 50 44 static void dg00x_card_free(struct snd_card *card) 51 45 { 52 - dg00x_free(card->private_data); 46 + struct snd_dg00x *dg00x = card->private_data; 47 + 48 + snd_dg00x_stream_destroy_duplex(dg00x); 49 + snd_dg00x_transaction_unregister(dg00x); 53 50 } 54 51 55 52 static void do_registration(struct work_struct *work) ··· 62 65 &dg00x->card); 63 66 if (err < 0) 64 67 return; 68 + dg00x->card->private_free = dg00x_card_free; 69 + dg00x->card->private_data = dg00x; 65 70 66 71 err = name_card(dg00x); 67 72 if (err < 0) ··· 95 96 if (err < 0) 96 97 goto error; 97 98 98 - dg00x->card->private_free = dg00x_card_free; 99 - dg00x->card->private_data = dg00x; 100 99 dg00x->registered = true; 101 100 102 101 return; 103 102 error: 104 - snd_dg00x_transaction_unregister(dg00x); 105 - snd_dg00x_stream_destroy_duplex(dg00x); 106 103 snd_card_free(dg00x->card); 107 104 dev_info(&dg00x->unit->device, 108 105 "Sound card registration failed: %d\n", err);
+6 -11
sound/firewire/fireface/ff.c
··· 27 27 dev_name(&ff->unit->device), 100 << fw_dev->max_speed); 28 28 } 29 29 30 - static void ff_free(struct snd_ff *ff) 31 - { 32 - snd_ff_stream_destroy_duplex(ff); 33 - snd_ff_transaction_unregister(ff); 34 - } 35 - 36 30 static void ff_card_free(struct snd_card *card) 37 31 { 38 - ff_free(card->private_data); 32 + struct snd_ff *ff = card->private_data; 33 + 34 + snd_ff_stream_destroy_duplex(ff); 35 + snd_ff_transaction_unregister(ff); 39 36 } 40 37 41 38 static void do_registration(struct work_struct *work) ··· 47 50 &ff->card); 48 51 if (err < 0) 49 52 return; 53 + ff->card->private_free = ff_card_free; 54 + ff->card->private_data = ff; 50 55 51 56 err = snd_ff_transaction_register(ff); 52 57 if (err < 0) ··· 78 79 if (err < 0) 79 80 goto error; 80 81 81 - ff->card->private_free = ff_card_free; 82 - ff->card->private_data = ff; 83 82 ff->registered = true; 84 83 85 84 return; 86 85 error: 87 - snd_ff_transaction_unregister(ff); 88 - snd_ff_stream_destroy_duplex(ff); 89 86 snd_card_free(ff->card); 90 87 dev_info(&ff->unit->device, 91 88 "Sound card registration failed: %d\n", err);
+7 -21
sound/firewire/fireworks/fireworks.c
··· 184 184 return err; 185 185 } 186 186 187 - static void efw_free(struct snd_efw *efw) 187 + static void 188 + efw_card_free(struct snd_card *card) 188 189 { 190 + struct snd_efw *efw = card->private_data; 191 + 189 192 mutex_lock(&devices_mutex); 190 193 clear_bit(efw->card_index, devices_used); 191 194 mutex_unlock(&devices_mutex); 192 195 193 196 snd_efw_stream_destroy_duplex(efw); 194 197 snd_efw_transaction_remove_instance(efw); 195 - } 196 - 197 - /* 198 - * This module releases the FireWire unit data after all ALSA character devices 199 - * are released by applications. This is for releasing stream data or finishing 200 - * transactions safely. Thus at returning from .remove(), this module still keep 201 - * references for the unit. 202 - */ 203 - static void 204 - efw_card_free(struct snd_card *card) 205 - { 206 - efw_free(card->private_data); 207 198 } 208 199 209 200 static void ··· 226 235 } 227 236 set_bit(card_index, devices_used); 228 237 mutex_unlock(&devices_mutex); 238 + 239 + efw->card->private_free = efw_card_free; 240 + efw->card->private_data = efw; 229 241 230 242 /* prepare response buffer */ 231 243 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, ··· 270 276 if (err < 0) 271 277 goto error; 272 278 273 - /* 274 - * After registered, efw instance can be released corresponding to 275 - * releasing the sound card instance. 276 - */ 277 - efw->card->private_free = efw_card_free; 278 - efw->card->private_data = efw; 279 279 efw->registered = true; 280 280 281 281 return; 282 282 error: 283 - snd_efw_transaction_remove_instance(efw); 284 - snd_efw_stream_destroy_duplex(efw); 285 283 snd_card_free(efw->card); 286 284 dev_info(&efw->unit->device, 287 285 "Sound card registration failed: %d\n", err);
+6 -22
sound/firewire/motu/motu.c
··· 52 52 dev_name(&motu->unit->device), 100 << fw_dev->max_speed); 53 53 } 54 54 55 - static void motu_free(struct snd_motu *motu) 56 - { 57 - snd_motu_transaction_unregister(motu); 58 - 59 - snd_motu_stream_destroy_duplex(motu); 60 - } 61 - 62 - /* 63 - * This module releases the FireWire unit data after all ALSA character devices 64 - * are released by applications. This is for releasing stream data or finishing 65 - * transactions safely. Thus at returning from .remove(), this module still keep 66 - * references for the unit. 67 - */ 68 55 static void motu_card_free(struct snd_card *card) 69 56 { 70 - motu_free(card->private_data); 57 + struct snd_motu *motu = card->private_data; 58 + 59 + snd_motu_transaction_unregister(motu); 60 + snd_motu_stream_destroy_duplex(motu); 71 61 } 72 62 73 63 static void do_registration(struct work_struct *work) ··· 72 82 &motu->card); 73 83 if (err < 0) 74 84 return; 85 + motu->card->private_free = motu_card_free; 86 + motu->card->private_data = motu; 75 87 76 88 name_card(motu); 77 89 ··· 108 116 if (err < 0) 109 117 goto error; 110 118 111 - /* 112 - * After registered, motu instance can be released corresponding to 113 - * releasing the sound card instance. 114 - */ 115 - motu->card->private_free = motu_card_free; 116 - motu->card->private_data = motu; 117 119 motu->registered = true; 118 120 119 121 return; 120 122 error: 121 - snd_motu_transaction_unregister(motu); 122 - snd_motu_stream_destroy_duplex(motu); 123 123 snd_card_free(motu->card); 124 124 dev_info(&motu->unit->device, 125 125 "Sound card registration failed: %d\n", err);
+5 -21
sound/firewire/oxfw/oxfw.c
··· 113 113 return err; 114 114 } 115 115 116 - static void oxfw_free(struct snd_oxfw *oxfw) 116 + static void oxfw_card_free(struct snd_card *card) 117 117 { 118 + struct snd_oxfw *oxfw = card->private_data; 119 + 118 120 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); 119 121 if (oxfw->has_output) 120 122 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); 121 - } 122 - 123 - /* 124 - * This module releases the FireWire unit data after all ALSA character devices 125 - * are released by applications. This is for releasing stream data or finishing 126 - * transactions safely. Thus at returning from .remove(), this module still keep 127 - * references for the unit. 128 - */ 129 - static void oxfw_card_free(struct snd_card *card) 130 - { 131 - oxfw_free(card->private_data); 132 123 } 133 124 134 125 static int detect_quirks(struct snd_oxfw *oxfw) ··· 195 204 &oxfw->card); 196 205 if (err < 0) 197 206 return; 207 + oxfw->card->private_free = oxfw_card_free; 208 + oxfw->card->private_data = oxfw; 198 209 199 210 err = name_card(oxfw); 200 211 if (err < 0) ··· 237 244 if (err < 0) 238 245 goto error; 239 246 240 - /* 241 - * After registered, oxfw instance can be released corresponding to 242 - * releasing the sound card instance. 243 - */ 244 - oxfw->card->private_free = oxfw_card_free; 245 - oxfw->card->private_data = oxfw; 246 247 oxfw->registered = true; 247 248 248 249 return; 249 250 error: 250 - snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); 251 - if (oxfw->has_output) 252 - snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); 253 251 snd_card_free(oxfw->card); 254 252 dev_info(&oxfw->unit->device, 255 253 "Sound card registration failed: %d\n", err);
+6 -15
sound/firewire/tascam/tascam.c
··· 85 85 return 0; 86 86 } 87 87 88 - static void tscm_free(struct snd_tscm *tscm) 89 - { 90 - snd_tscm_transaction_unregister(tscm); 91 - snd_tscm_stream_destroy_duplex(tscm); 92 - } 93 - 94 88 static void tscm_card_free(struct snd_card *card) 95 89 { 96 - tscm_free(card->private_data); 90 + struct snd_tscm *tscm = card->private_data; 91 + 92 + snd_tscm_transaction_unregister(tscm); 93 + snd_tscm_stream_destroy_duplex(tscm); 97 94 } 98 95 99 96 static void do_registration(struct work_struct *work) ··· 102 105 &tscm->card); 103 106 if (err < 0) 104 107 return; 108 + tscm->card->private_free = tscm_card_free; 109 + tscm->card->private_data = tscm; 105 110 106 111 err = identify_model(tscm); 107 112 if (err < 0) ··· 135 136 if (err < 0) 136 137 goto error; 137 138 138 - /* 139 - * After registered, tscm instance can be released corresponding to 140 - * releasing the sound card instance. 141 - */ 142 - tscm->card->private_free = tscm_card_free; 143 - tscm->card->private_data = tscm; 144 139 tscm->registered = true; 145 140 146 141 return; 147 142 error: 148 - snd_tscm_transaction_unregister(tscm); 149 - snd_tscm_stream_destroy_duplex(tscm); 150 143 snd_card_free(tscm->card); 151 144 dev_info(&tscm->unit->device, 152 145 "Sound card registration failed: %d\n", err);