ALSA: hda - Make snd_hda_jack_detect_enable_callback() returning the jack object
authorTakashi Iwai <tiwai@suse.de>
Thu, 11 Sep 2014 12:39:09 +0000 (14:39 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 15 Sep 2014 09:50:48 +0000 (11:50 +0200)
STAC/IDT driver calls snd_hda_jack_tbl_get() again after calling
snd_hda_jack_detect_enable_callback().  For simplifying this, let's
make snd_hda_jack_detect_enable_callback() returning the pointer while
handling the error with the standard IS_ERR() & co.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_jack.c
sound/pci/hda/hda_jack.h
sound/pci/hda/patch_sigmatel.c

index 7f332794993fa3396fbc490bc19ae9b0ac5f592f..a5fe1b42801521de29e5f6d82332c74f314dbaf8 100644 (file)
@@ -214,29 +214,39 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state);
 
 /**
  * snd_hda_jack_detect_enable - enable the jack-detection
+ *
+ * In the case of error, the return value will be a pointer embedded with
+ * errno.  Check and handle the return value appropriately with standard
+ * macros such as @IS_ERR() and @PTR_ERR().
  */
-int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
-                                       hda_jack_callback cb)
+struct hda_jack_tbl *
+snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
+                                   hda_jack_callback cb)
 {
        struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
+       int err;
+
        if (!jack)
-               return -ENOMEM;
+               return ERR_PTR(-ENOMEM);
        if (jack->jack_detect)
-               return 0; /* already registered */
+               return jack; /* already registered */
        jack->jack_detect = 1;
        if (cb)
                jack->callback = cb;
        if (codec->jackpoll_interval > 0)
-               return 0; /* No unsol if we're polling instead */
-       return snd_hda_codec_write_cache(codec, nid, 0,
+               return jack; /* No unsol if we're polling instead */
+       err = snd_hda_codec_write_cache(codec, nid, 0,
                                         AC_VERB_SET_UNSOLICITED_ENABLE,
                                         AC_USRSP_EN | jack->tag);
+       if (err < 0)
+               return ERR_PTR(err);
+       return jack;
 }
 EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback);
 
 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid)
 {
-       return snd_hda_jack_detect_enable_callback(codec, nid, NULL);
+       return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback(codec, nid, NULL));
 }
 EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);
 
index 67f42db9c89c4cd7e5680ca204598b71a4337a05..668669ce3e527f2176596a8b28c14bdd8dda444b 100644 (file)
@@ -47,8 +47,9 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec);
 void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
 
 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid);
-int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
-                                       hda_jack_callback cb);
+struct hda_jack_tbl *
+snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
+                                   hda_jack_callback cb);
 
 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
                                 hda_nid_t gating_nid);
index bc371cfb5d8404d9141cc384ea6283c1a28cba5c..4b338beb9449fb4d3667ef02c031cd5a0f8ba4ae 100644 (file)
@@ -3019,10 +3019,9 @@ static void stac92hd71bxx_fixup_hp_m4(struct hda_codec *codec,
        /* Enable VREF power saving on GPIO1 detect */
        snd_hda_codec_write_cache(codec, codec->afg, 0,
                                  AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
-       snd_hda_jack_detect_enable_callback(codec, codec->afg,
-                                           stac_vref_event);
-       jack = snd_hda_jack_tbl_get(codec, codec->afg);
-       if (jack)
+       jack = snd_hda_jack_detect_enable_callback(codec, codec->afg,
+                                                  stac_vref_event);
+       if (!IS_ERR(jack))
                jack->private_data = 0x02;
 
        spec->gpio_mask |= 0x02;
@@ -4042,10 +4041,9 @@ static void stac9205_fixup_dell_m43(struct hda_codec *codec,
                /* Enable unsol response for GPIO4/Dock HP connection */
                snd_hda_codec_write_cache(codec, codec->afg, 0,
                        AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
-               snd_hda_jack_detect_enable_callback(codec, codec->afg,
-                                                   stac_vref_event);
-               jack = snd_hda_jack_tbl_get(codec, codec->afg);
-               if (jack)
+               jack = snd_hda_jack_detect_enable_callback(codec, codec->afg,
+                                                          stac_vref_event);
+               if (!IS_ERR(jack))
                        jack->private_data = 0x01;
 
                spec->gpio_dir = 0x0b;