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

ALSA: hda - Clear pcm pointer assigned to hda_pcm at device removal

We leave the pcm field of struct hda_pcm at removal of each device, so
far. This hasn't been a problem since unbinding the codec driver
isn't supposed to happen and another route via snd_hda_codec_reset()
clears all the once. However, for a proper unbind implementation, we
need to care about it.

This patch does the thing above properly:

- Include struct hda_pcm pointer instead of struct hda_pcm_stream
pointers in struct azx_dev. This allows us to point the hda_pcm
object at dev_free callback.

- Introduce to_hda_pcm_stream() macro for better readability.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+16 -8
+15 -7
sound/pci/hda/hda_controller.c
··· 258 258 tc->cycle_last = last; 259 259 } 260 260 261 + static inline struct hda_pcm_stream * 262 + to_hda_pcm_stream(struct snd_pcm_substream *substream) 263 + { 264 + struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 265 + return &apcm->info->stream[substream->stream]; 266 + } 267 + 261 268 static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, 262 269 u64 nsec) 263 270 { 264 271 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 265 - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 272 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 266 273 u64 codec_frames, codec_nsecs; 267 274 268 275 if (!hinfo->ops.get_delay) ··· 405 398 static int azx_pcm_close(struct snd_pcm_substream *substream) 406 399 { 407 400 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 408 - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 401 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 409 402 struct azx *chip = apcm->chip; 410 403 struct azx_dev *azx_dev = get_azx_dev(substream); 411 404 unsigned long flags; ··· 447 440 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 448 441 struct azx_dev *azx_dev = get_azx_dev(substream); 449 442 struct azx *chip = apcm->chip; 450 - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 443 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 451 444 int err; 452 445 453 446 /* reset BDL address */ ··· 474 467 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 475 468 struct azx *chip = apcm->chip; 476 469 struct azx_dev *azx_dev = get_azx_dev(substream); 477 - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 470 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 478 471 struct snd_pcm_runtime *runtime = substream->runtime; 479 472 unsigned int bufsize, period_bytes, format_val, stream_tag; 480 473 int err; ··· 714 707 715 708 if (substream->runtime) { 716 709 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 717 - struct hda_pcm_stream *hinfo = apcm->hinfo[stream]; 710 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 718 711 719 712 if (chip->get_delay[stream]) 720 713 delay += chip->get_delay[stream](chip, azx_dev, pos); ··· 797 790 static int azx_pcm_open(struct snd_pcm_substream *substream) 798 791 { 799 792 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 800 - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 793 + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); 801 794 struct azx *chip = apcm->chip; 802 795 struct azx_dev *azx_dev; 803 796 struct snd_pcm_runtime *runtime = substream->runtime; ··· 911 904 struct azx_pcm *apcm = pcm->private_data; 912 905 if (apcm) { 913 906 list_del(&apcm->list); 907 + apcm->info->pcm = NULL; 914 908 kfree(apcm); 915 909 } 916 910 } ··· 948 940 apcm->chip = chip; 949 941 apcm->pcm = pcm; 950 942 apcm->codec = codec; 943 + apcm->info = cpcm; 951 944 pcm->private_data = apcm; 952 945 pcm->private_free = azx_pcm_free; 953 946 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) ··· 956 947 list_add_tail(&apcm->list, &chip->pcm_list); 957 948 cpcm->pcm = pcm; 958 949 for (s = 0; s < 2; s++) { 959 - apcm->hinfo[s] = &cpcm->stream[s]; 960 950 if (cpcm->stream[s].substreams) 961 951 snd_pcm_set_ops(pcm, s, &azx_pcm_ops); 962 952 }
+1 -1
sound/pci/hda/hda_controller.h
··· 283 283 struct azx *chip; 284 284 struct snd_pcm *pcm; 285 285 struct hda_codec *codec; 286 - struct hda_pcm_stream *hinfo[2]; 286 + struct hda_pcm *info; 287 287 struct list_head list; 288 288 }; 289 289