# [solved] Distorted sound over HDMI with kernel-5.4.3

## donmartio

Hi there, 

since i updated to kernel-5.4.3 (gentoo-sources) the sound coming over hdmi is distorted, loud and comes just from on speaker.

I did a little investigation in the kernel changes between 5.4.2 and 5.4.3, and found the commit e38e486d66e2a3b902768fd71c32dbf10f77e1cb.

As a shot in the dark i created a patch which reverted this commit and the problem was gone.

I'll try to reply to this patch to find out whats going wrong here.

Since then here is the patch i put into /etc/portage/patches/sys-kernel/gentoo-sources-5.4.3/hdmi-strip.patch, just in case someone trip over the same problem.

```

diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h

index e05b95e83d5a..b260c5fd2337 100644

--- a/include/sound/hdaudio.h

+++ b/include/sound/hdaudio.h

@@ -493,7 +493,6 @@ struct hdac_stream {

        bool prepared:1;

        bool no_period_wakeup:1;

        bool locked:1;

-       bool stripe:1;                  /* apply stripe control */

 

        /* timestamp */

        unsigned long start_wallclk;    /* start + minimum wallclk */

diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c

index f9707fb05efe..d8fe7ff0cd58 100644

--- a/sound/hda/hdac_stream.c

+++ b/sound/hda/hdac_stream.c

@@ -96,14 +96,12 @@ void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start)

                              1 << azx_dev->index,

                              1 << azx_dev->index);

        /* set stripe control */

-       if (azx_dev->stripe) {

-               if (azx_dev->substream)

-                       stripe_ctl = snd_hdac_get_stream_stripe_ctl(bus, azx_dev->substream);

-               else

-                       stripe_ctl = 0;

-               snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK,

-                                       stripe_ctl);

-       }

+       if (azx_dev->substream)

+               stripe_ctl = snd_hdac_get_stream_stripe_ctl(bus, azx_dev->substream);

+       else

+               stripe_ctl = 0;

+       snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK,

+                               stripe_ctl);

        /* set DMA start and interrupt mask */

        snd_hdac_stream_updateb(azx_dev, SD_CTL,

                                0, SD_CTL_DMA_START | SD_INT_MASK);

@@ -120,10 +118,7 @@ void snd_hdac_stream_clear(struct hdac_stream *azx_dev)

        snd_hdac_stream_updateb(azx_dev, SD_CTL,

                                SD_CTL_DMA_START | SD_INT_MASK, 0);

        snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */

-       if (azx_dev->stripe) {

-               snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 0);

-               azx_dev->stripe = 0;

-       }

+       snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 0);

        azx_dev->running = false;

 }

 EXPORT_SYMBOL_GPL(snd_hdac_stream_clear);

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c

index 78647ee02339..8e7e773b6518 100644

--- a/sound/pci/hda/patch_hdmi.c

+++ b/sound/pci/hda/patch_hdmi.c

@@ -32,7 +32,6 @@

 #include <sound/hda_codec.h>

 #include "hda_local.h"

 #include "hda_jack.h"

-#include "hda_controller.h"

 

 static bool static_hdmi_pcm;

 module_param(static_hdmi_pcm, bool, 0644);

@@ -1250,10 +1249,6 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,

        per_pin->cvt_nid = per_cvt->cvt_nid;

        hinfo->nid = per_cvt->cvt_nid;

 

-       /* flip stripe flag for the assigned stream if supported */

-       if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE)

-               azx_stream(get_azx_dev(substream))->stripe = 1;

-

        snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);

        snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,

                            AC_VERB_SET_CONNECT_SEL,

```

----------

## donmartio

After a little bit of research the patch boiled down to the following:

```

--- a/sound/hda/hdac_stream.c   2019-12-15 19:15:37.512583523 +0100

+++ b/sound/hda/hdac_stream.c   2019-12-15 19:15:48.976584590 +0100

@@ -122,7 +122,6 @@

    snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */

    if (azx_dev->stripe) {

        snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 0);

-       azx_dev->stripe = 0;

    }

    azx_dev->running = false;

 }

```

Update: had to remove the patch of the hdaudio.h since this wont compile.

----------

## donmartio

So my explanation is this. The stripe property was initially set to 1 and set to 0 in the function snd_hdac_stream_clear.

With this patch the property is set to 1 if the AC_WCAP_STRIPE flag is set and never touched again.

I can't test this on another machine. 

After all since nobody has issues with this, there is maybe something else wrong with my machine/config.

----------

## papas

same problem for me,  my solution was to revert all the patches for " /sound/hda" and "/sound/pci" files.

Thank you for your explanation.   :Very Happy: 

----------

## donmartio

I got an answer from the dev, he already fixed that yesterday. I adjusted my patch according to his changes:

```

diff -ru a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c

--- a/sound/hda/hdac_stream.c   2019-12-15 19:15:37.512583523 +0100

+++ b/sound/hda/hdac_stream.c   2019-12-15 21:36:32.786855989 +0100

@@ -120,10 +120,8 @@

    snd_hdac_stream_updateb(azx_dev, SD_CTL,

                SD_CTL_DMA_START | SD_INT_MASK, 0);

    snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */

-   if (azx_dev->stripe) {

+   if (azx_dev->stripe)

        snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 0);

-       azx_dev->stripe = 0;

-   }

    azx_dev->running = false;

 }

 EXPORT_SYMBOL_GPL(snd_hdac_stream_clear);

diff -ru a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c

--- a/sound/pci/hda/patch_hdmi.c    2019-12-15 21:37:39.791854848 +0100

+++ b/sound/pci/hda/patch_hdmi.c    2019-12-15 22:01:29.397830504 +0100

@@ -1983,6 +1983,8 @@

        per_cvt->assigned = 0;

        hinfo->nid = 0;

+       azx_stream(get_azx_dev(substream))->stripe = 0;

+

        mutex_lock(&spec->pcm_lock);

        snd_hda_spdif_ctls_unassign(codec, pcm_idx);

        clear_bit(pcm_idx, &spec->pcm_in_use);

```

----------

## rommel

how was this fixed? for next kernel update?  can you post complete patch that applied and compiled for you

----------

## donmartio

The above patch is the one i have applied on my system.

----------

## papas

kernel 5.4.4 still exist the problem

----------

## Ionen

Yeah, 5.4.4 had no change regarding this. It's "apparently" set to be merged in 5.5-rc3 and will likely end up in 5.4.5 whenever that releases. 5.4.4 came out too early to get it I guess.

While waiting, the patch (from post #5 or here) still applies cleanly given nothing in those files changed since 5.4.3 (if anyone in doubt, just stick to the working as-is 5.4.2 for now).

Edit: 5.4.5 came out earlier than I thought, and situation seem unchanged (as-in, doesn't look fixed and patch should still work).Last edited by Ionen on Thu Dec 19, 2019 2:45 am; edited 1 time in total

----------

## papas

worked, thank you

----------

## rommel

thanks for the link lonen, that patch applied and compiled cleanly  and sound in 5.4.4 is working properly

[edit] so this is still the case with 5.4.5 but the patch applies and sound is working with it

----------

## Ionen

It's fixed in 5.4.6.

----------

## RayDude

Is anyone having problems with pulse crashing when driving HDMI audio?

It dies for me periodically (several times a day) and I have to restart pulse with pulseaudio -k.

----------

## Anton Gubarkov

I also experience this on 5.3.18. Apparently some patches from 5.4 were backported. However I don't have hdac_* files in sound/pci/hda to patch.

clean 5.3 doesn't have the problem. Can you share how you came down to the  commit to blame? I have troubles starting the bisect since I can't run 5.4 on my machine (I have root on ZFS) and 5.3.18 is not a tag in the kernel git tree.

----------

## Ionen

Are you sure you don't? I just tried the patch from above, and it applied on clean 5.3.18 for me (with an offset), not that I've booted it to see.

----------

## Anton Gubarkov

@Ionen, thanks for the link. This patch applies cleanly indeed.

----------

## donmartio

 *Quote:*   

> Can you share how you came down to the commit to blame?

 

I searched the git log  between 5.4.2 and 5.4.3 for changes to anything regarding audio/hdmi.

Luckily the first commit i found and created a revert patch from, did do the trick.

----------

