]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: hda: Use the new helper for PCM instance refcount
authorTakashi Iwai <tiwai@suse.de>
Wed, 10 Jun 2026 15:45:33 +0000 (17:45 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 11 Jun 2026 07:34:09 +0000 (09:34 +0200)
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 <tiwai@suse.de>
Link: https://patch.msgid.link/20260610154538.51076-4-tiwai@suse.de
include/sound/hda_codec.h
sound/hda/common/bind.c
sound/hda/common/codec.c

index 1a1fe7a904c367c26048057f8d4ce098a8f8727a..17945ab5e6e256cfd4c9b345b29168f39c8c7e11 100644 (file)
@@ -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,
index bb1090b656990fa715cb1ab3eae3e66b111606bf..6a728a773556070aed394ec430433e9a943147c5 100644 (file)
@@ -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)
index 81f266b9b850f7e542922ba7eb9d06d1d849043b..ef533770179b490afca55a9c0af695fba976d6dd 100644 (file)
@@ -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;
 }