From: Takashi Iwai Date: Wed, 10 Jun 2026 15:45:33 +0000 (+0200) Subject: ALSA: hda: Use the new helper for PCM instance refcount X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=53af356c45b22c2410b08ad947e62105a137f680;p=thirdparty%2Fkernel%2Flinux.git ALSA: hda: Use the new helper for PCM instance refcount HD-audio core driver has some open-code for managing the refcount for PCM instances, and it can be replaced gracefully with the new helpers. Only a code cleanup, no functional changes. Signed-off-by: Takashi Iwai Link: https://patch.msgid.link/20260610154538.51076-4-tiwai@suse.de --- diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h index 1a1fe7a904c36..17945ab5e6e25 100644 --- a/include/sound/hda_codec.h +++ b/include/sound/hda_codec.h @@ -188,8 +188,7 @@ struct hda_codec { /* PCM to create, set by hda_codec_ops.build_pcms callback */ struct list_head pcm_list_head; - refcount_t pcm_ref; - wait_queue_head_t remove_sleep; + struct snd_refcount pcm_ref; /* codec specific info */ void *spec; @@ -439,9 +438,12 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec); static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm) { - refcount_inc(&pcm->codec->pcm_ref); + snd_refcount_get(&pcm->codec->pcm_ref); +} +static inline void snd_hda_codec_pcm_put(struct hda_pcm *pcm) +{ + snd_refcount_put(&pcm->codec->pcm_ref); } -void snd_hda_codec_pcm_put(struct hda_pcm *pcm); int snd_hda_codec_prepare(struct hda_codec *codec, struct hda_pcm_stream *hinfo, diff --git a/sound/hda/common/bind.c b/sound/hda/common/bind.c index bb1090b656990..6a728a7735560 100644 --- a/sound/hda/common/bind.c +++ b/sound/hda/common/bind.c @@ -162,8 +162,7 @@ static int hda_codec_driver_remove(struct device *dev) snd_hda_codec_disconnect_pcms(codec); snd_hda_jack_tbl_disconnect(codec); - if (!refcount_dec_and_test(&codec->pcm_ref)) - wait_event(codec->remove_sleep, !refcount_read(&codec->pcm_ref)); + snd_refcount_sync(&codec->pcm_ref); snd_power_sync_ref(codec->bus->card); if (driver->ops->remove) diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c index 81f266b9b850f..ef533770179b4 100644 --- a/sound/hda/common/codec.c +++ b/sound/hda/common/codec.c @@ -689,13 +689,6 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) /* * PCM device */ -void snd_hda_codec_pcm_put(struct hda_pcm *pcm) -{ - if (refcount_dec_and_test(&pcm->codec->pcm_ref)) - wake_up(&pcm->codec->remove_sleep); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put); - struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, const char *fmt, ...) { @@ -716,7 +709,7 @@ struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, } list_add_tail(&pcm->list, &codec->pcm_list_head); - refcount_inc(&codec->pcm_ref); + snd_hda_codec_pcm_get(pcm); return pcm; } EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new); @@ -787,7 +780,7 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) remove_conn_list(codec); snd_hdac_regmap_exit(&codec->core); codec->configured = 0; - refcount_set(&codec->pcm_ref, 1); /* reset refcount */ + snd_refcount_init(&codec->pcm_ref); /* reset refcount */ } EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind); @@ -927,8 +920,7 @@ snd_hda_codec_device_init(struct hda_bus *bus, unsigned int codec_addr, INIT_LIST_HEAD(&codec->conn_list); INIT_LIST_HEAD(&codec->pcm_list_head); INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); - refcount_set(&codec->pcm_ref, 1); - init_waitqueue_head(&codec->remove_sleep); + snd_refcount_init(&codec->pcm_ref); return codec; }