ALSA: x86: Drop had_get_hwstate()
authorTakashi Iwai <tiwai@suse.de>
Tue, 31 Jan 2017 15:46:44 +0000 (16:46 +0100)
committerTakashi Iwai <tiwai@suse.de>
Fri, 3 Feb 2017 16:34:17 +0000 (17:34 +0100)
The helper function isn't clearer than the plain condition check
"if (drv_status == HDA_DRV_DISCONNECTED)".  By expanding this, the
compiler could even catch the possible uninitialized cases, so we
could fix them, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/x86/intel_hdmi_audio.c

index 835e0f2c4f0be3cf3657aa1c6b122751d1049d59..7c6549a10c1c0065ff977991cbe99b98cbcdf846 100644 (file)
@@ -155,15 +155,6 @@ static const struct snd_pcm_hardware snd_intel_hadstream = {
 };
 
 /* Register access functions */
-static int had_get_hwstate(struct snd_intelhad *intelhaddata)
-{
-       /* Check for device presence -SW state */
-       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
-               return -ENODEV;
-
-       return 0;
-}
-
 static inline void
 mid_hdmi_audio_read(struct snd_intelhad *ctx, u32 reg, u32 *val)
 {
@@ -179,11 +170,8 @@ mid_hdmi_audio_write(struct snd_intelhad *ctx, u32 reg, u32 val)
 static int had_read_register(struct snd_intelhad *intelhaddata,
                             u32 offset, u32 *data)
 {
-       int retval;
-
-       retval = had_get_hwstate(intelhaddata);
-       if (retval)
-               return retval;
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
+               return -ENODEV;
 
        mid_hdmi_audio_read(intelhaddata, offset, data);
        return 0;
@@ -201,11 +189,8 @@ static void fixup_dp_config(struct snd_intelhad *intelhaddata,
 static int had_write_register(struct snd_intelhad *intelhaddata,
                              u32 offset, u32 data)
 {
-       int retval;
-
-       retval = had_get_hwstate(intelhaddata);
-       if (retval)
-               return retval;
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
+               return -ENODEV;
 
        fixup_dp_config(intelhaddata, offset, &data);
        mid_hdmi_audio_write(intelhaddata, offset, data);
@@ -216,11 +201,9 @@ static int had_read_modify(struct snd_intelhad *intelhaddata, u32 offset,
                           u32 data, u32 mask)
 {
        u32 val_tmp;
-       int retval;
 
-       retval = had_get_hwstate(intelhaddata);
-       if (retval)
-               return retval;
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
+               return -ENODEV;
 
        mid_hdmi_audio_read(intelhaddata, offset, &val_tmp);
        val_tmp &= ~mask;
@@ -930,7 +913,7 @@ static int snd_intelhad_prog_n(u32 aud_samp_freq, u32 *n_param,
 
 static void snd_intelhad_handle_underrun(struct snd_intelhad *intelhaddata)
 {
-       u32 hdmi_status, i = 0;
+       u32 hdmi_status = 0, i = 0;
 
        /* Handle Underrun interrupt within Audio Unit */
        had_write_register(intelhaddata, AUD_CONFIG, 0);
@@ -977,7 +960,7 @@ static int snd_intelhad_open(struct snd_pcm_substream *substream)
 
        pm_runtime_get(intelhaddata->dev);
 
-       if (had_get_hwstate(intelhaddata)) {
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
                dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n",
                        __func__);
                retval = -ENODEV;
@@ -1185,7 +1168,7 @@ static int snd_intelhad_pcm_trigger(struct snd_pcm_substream *substream,
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
                /* Disable local INTRs till register prgmng is done */
-               if (had_get_hwstate(intelhaddata)) {
+               if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
                        dev_dbg(intelhaddata->dev,
                                "_START: HDMI cable plugged-out\n");
                        retval = -ENODEV;
@@ -1245,7 +1228,7 @@ static int snd_intelhad_pcm_prepare(struct snd_pcm_substream *substream)
        runtime = substream->runtime;
        had_stream = &intelhaddata->stream_data;
 
-       if (had_get_hwstate(intelhaddata)) {
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
                dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n",
                        __func__);
                retval = -ENODEV;
@@ -1329,6 +1312,9 @@ static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
 
        intelhaddata = snd_pcm_substream_chip(substream);
 
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
+               return SNDRV_PCM_POS_XRUN;
+
        if (intelhaddata->flag_underrun) {
                intelhaddata->flag_underrun = false;
                return SNDRV_PCM_POS_XRUN;
@@ -1614,7 +1600,7 @@ static int had_process_buffer_done(struct snd_intelhad *intelhaddata)
 
        spin_unlock_irqrestore(&intelhaddata->had_spinlock, flag_irqs);
 
-       if (had_get_hwstate(intelhaddata)) {
+       if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
                dev_dbg(intelhaddata->dev, "HDMI cable plugged-out\n");
                return 0;
        }