Skip to content

Commit 87978e6

Browse files
crojewsk-inteltiwai
authored andcommitted
ALSA: hda: Do not unset preset when cleaning up codec
Several functions that take part in codec's initialization and removal are re-used by ASoC codec drivers implementations. Drivers mimic the behavior of hda_codec_driver_probe/remove() found in sound/pci/hda/hda_bind.c with their component->probe/remove() instead. One of the reasons for that is the expectation of snd_hda_codec_device_new() to receive a valid pointer to an instance of struct snd_card. This expectation can be met only once sound card components probing commences. As ASoC sound card may be unbound without codec device being actually removed from the system, unsetting ->preset in snd_hda_codec_cleanup_for_unbind() interferes with module unload -> load scenario causing null-ptr-deref. Preset is assigned only once, during device/driver matching whereas ASoC codec driver's module reloading may occur several times throughout the lifetime of an audio stack. Suggested-by: Takashi Iwai <[email protected]> Signed-off-by: Cezary Rojewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent b9cee50 commit 87978e6

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

sound/pci/hda/hda_bind.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static int hda_codec_driver_probe(struct device *dev)
144144

145145
error:
146146
snd_hda_codec_cleanup_for_unbind(codec);
147+
codec->preset = NULL;
147148
return err;
148149
}
149150

@@ -166,6 +167,7 @@ static int hda_codec_driver_remove(struct device *dev)
166167
if (codec->patch_ops.free)
167168
codec->patch_ops.free(codec);
168169
snd_hda_codec_cleanup_for_unbind(codec);
170+
codec->preset = NULL;
169171
module_put(dev->driver->owner);
170172
return 0;
171173
}

sound/pci/hda/hda_codec.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
795795
snd_array_free(&codec->cvt_setups);
796796
snd_array_free(&codec->spdif_out);
797797
snd_array_free(&codec->verbs);
798-
codec->preset = NULL;
799798
codec->follower_dig_outs = NULL;
800799
codec->spdif_status_reset = 0;
801800
snd_array_free(&codec->mixers);

0 commit comments

Comments
 (0)