* [PATCH] drm/radeon: fix dangling pointer kfree
@ 2014-10-11 12:37 Henning Schild
2014-10-11 12:51 ` [PATCH] drm/radeon: remove code that can never get executed Henning Schild
0 siblings, 1 reply; 6+ messages in thread
From: Henning Schild @ 2014-10-11 12:37 UTC (permalink / raw)
To: linux-kernel; +Cc: Henning Schild, Alex Deucher, Rafał Miłecki
If drm_edid_to_speaker_allocation returns a count of 0 sadb is not
initialized and should not get kfreed. Bail out like the other two
callers.
Signed-off-by: Henning Schild <henning@hennsch.de>
---
drivers/gpu/drm/radeon/dce3_1_afmt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index 51800e3..cb76074 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -48,7 +48,7 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
}
sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
- if (sad_count < 0) {
+ if (sad_count <= 0) {
DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
return;
}
--
2.0.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] drm/radeon: remove code that can never get executed
2014-10-11 12:37 [PATCH] drm/radeon: fix dangling pointer kfree Henning Schild
@ 2014-10-11 12:51 ` Henning Schild
2014-10-13 16:08 ` Deucher, Alexander
0 siblings, 1 reply; 6+ messages in thread
From: Henning Schild @ 2014-10-11 12:51 UTC (permalink / raw)
To: linux-kernel; +Cc: Henning Schild, Alex Deucher, Rafał Miłecki
Removing a code-path that can never be executed ... and its copies. If
drm_edid_to_speaker_allocation returns 0 the callers return. There is no
need to check that condition again.
Signed-off-by: Henning Schild <henning@hennsch.de>
---
drivers/gpu/drm/radeon/dce3_1_afmt.c | 5 +----
drivers/gpu/drm/radeon/dce6_afmt.c | 5 +----
drivers/gpu/drm/radeon/evergreen_hdmi.c | 5 +----
3 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index cb76074..6d31ed8 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -58,10 +58,7 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
/* set HDMI mode */
tmp |= HDMI_CONNECTION;
- if (sad_count)
- tmp |= SPEAKER_ALLOCATION(sadb[0]);
- else
- tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+ tmp |= SPEAKER_ALLOCATION(sadb[0]);
WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
kfree(sadb);
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index ab29f95..e6b2750 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -186,10 +186,7 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
/* set HDMI mode */
tmp |= HDMI_CONNECTION;
- if (sad_count)
- tmp |= SPEAKER_ALLOCATION(sadb[0]);
- else
- tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+ tmp |= SPEAKER_ALLOCATION(sadb[0]);
WREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
kfree(sadb);
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index 278c7a1..11a6b65 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -128,10 +128,7 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
/* set HDMI mode */
tmp |= HDMI_CONNECTION;
- if (sad_count)
- tmp |= SPEAKER_ALLOCATION(sadb[0]);
- else
- tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+ tmp |= SPEAKER_ALLOCATION(sadb[0]);
WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
kfree(sadb);
--
2.0.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/radeon: remove code that can never get executed
2014-10-11 12:51 ` [PATCH] drm/radeon: remove code that can never get executed Henning Schild
@ 2014-10-13 16:08 ` Deucher, Alexander
2014-10-13 16:44 ` Henning Schild
0 siblings, 1 reply; 6+ messages in thread
From: Deucher, Alexander @ 2014-10-13 16:08 UTC (permalink / raw)
To: Henning Schild, linux-kernel; +Cc: Rafał Miłecki
[-- Attachment #1: Type: text/plain, Size: 3022 bytes --]
> -----Original Message-----
> From: Henning Schild [mailto:henning@hennsch.de]
> Sent: Saturday, October 11, 2014 8:51 AM
> To: linux-kernel@vger.kernel.org
> Cc: Henning Schild; Deucher, Alexander; Rafał Miłecki
> Subject: [PATCH] drm/radeon: remove code that can never get executed
>
> Removing a code-path that can never be executed ... and its copies. If
> drm_edid_to_speaker_allocation returns 0 the callers return. There is no
> need to check that condition again.
I think we actually want to set the speaker allocation setup to stereo if the speaker allocation block is not present so I think the attached patch is probably the proper fix.
Alex
>
> Signed-off-by: Henning Schild <henning@hennsch.de>
> ---
> drivers/gpu/drm/radeon/dce3_1_afmt.c | 5 +----
> drivers/gpu/drm/radeon/dce6_afmt.c | 5 +----
> drivers/gpu/drm/radeon/evergreen_hdmi.c | 5 +----
> 3 files changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> index cb76074..6d31ed8 100644
> --- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> +++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> @@ -58,10 +58,7 @@ static void
> dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> /* set HDMI mode */
> tmp |= HDMI_CONNECTION;
> - if (sad_count)
> - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> - else
> - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
>
> kfree(sadb);
> diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c
> b/drivers/gpu/drm/radeon/dce6_afmt.c
> index ab29f95..e6b2750 100644
> --- a/drivers/gpu/drm/radeon/dce6_afmt.c
> +++ b/drivers/gpu/drm/radeon/dce6_afmt.c
> @@ -186,10 +186,7 @@ void dce6_afmt_write_speaker_allocation(struct
> drm_encoder *encoder)
> tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> /* set HDMI mode */
> tmp |= HDMI_CONNECTION;
> - if (sad_count)
> - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> - else
> - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> WREG32_ENDPOINT(offset,
> AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
>
> kfree(sadb);
> diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> index 278c7a1..11a6b65 100644
> --- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> +++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> @@ -128,10 +128,7 @@ static void
> dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> /* set HDMI mode */
> tmp |= HDMI_CONNECTION;
> - if (sad_count)
> - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> - else
> - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
>
> kfree(sadb);
> --
> 2.0.4
[-- Attachment #2: 0001-drm-radeon-fix-speaker-allocation-setup.patch --]
[-- Type: application/octet-stream, Size: 2636 bytes --]
From ab8d0add442bbd7d9b96a04909c8a233628cef2f Mon Sep 17 00:00:00 2001
From: Alex Deucher <alexander.deucher@amd.com>
Date: Mon, 13 Oct 2014 11:51:50 -0400
Subject: [PATCH] drm/radeon: fix speaker allocation setup
If the sad_count is 0, set the hw to stereo and change
the error message to a warn. A lot of monitors don't
set the speaker allocation block.
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
---
drivers/gpu/drm/radeon/dce3_1_afmt.c | 4 ++--
drivers/gpu/drm/radeon/dce6_afmt.c | 6 +++---
drivers/gpu/drm/radeon/evergreen_hdmi.c | 6 +++---
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index 950af15..adf65c0 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -49,8 +49,8 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
if (sad_count < 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index c0bbf68..bdc3333 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -176,9 +176,9 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
}
sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
- if (sad_count <= 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ if (sad_count < 0) {
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index 2514d65..ba942b0 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -149,9 +149,9 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
}
sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
- if (sad_count <= 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ if (sad_count < 0) {
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
--
1.8.3.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/radeon: remove code that can never get executed
2014-10-13 16:08 ` Deucher, Alexander
@ 2014-10-13 16:44 ` Henning Schild
2014-10-13 17:31 ` Deucher, Alexander
0 siblings, 1 reply; 6+ messages in thread
From: Henning Schild @ 2014-10-13 16:44 UTC (permalink / raw)
To: Deucher, Alexander, linux-kernel; +Cc: Rafał Miłecki
Well i am not sure what the code actually is supposed to do. That is up to you
because you know the hardware. I just wanted to point out that right now some
code can never be reached.
I ran into the whole thing because the pointer (sadp) that gets kfreed was never
initialized (in one of the three cases). My first fix was to initialize it to
NULL, that way the kfree did not fail even if the allocation did not do
anything. Then i found the other two copies and decided to follow their scheme.
In your patch you have to make kfree depend on (sad_count > 0) or sadp needs to
be initialized with NULL. Otherwise you will get the dangling pointer kfree that
lead me to read this code.
Henning
> On October 13, 2014 at 6:08 PM "Deucher, Alexander"
> <Alexander.Deucher@amd.com> wrote:
>
> > -----Original Message-----
> > From: Henning Schild [mailto:henning@hennsch.de]
> > Sent: Saturday, October 11, 2014 8:51 AM
> > To: linux-kernel@vger.kernel.org
> > Cc: Henning Schild; Deucher, Alexander; Rafał Miłecki
> > Subject: [PATCH] drm/radeon: remove code that can never get executed
> >
> > Removing a code-path that can never be executed ... and its copies. If
> > drm_edid_to_speaker_allocation returns 0 the callers return. There is no
> > need to check that condition again.
>
> I think we actually want to set the speaker allocation setup to stereo if the
> speaker allocation block is not present so I think the attached patch is
> probably the proper fix.
>
> Alex
>
> >
> > Signed-off-by: Henning Schild <henning@hennsch.de>
> > ---
> > drivers/gpu/drm/radeon/dce3_1_afmt.c | 5 +----
> > drivers/gpu/drm/radeon/dce6_afmt.c | 5 +----
> > drivers/gpu/drm/radeon/evergreen_hdmi.c | 5 +----
> > 3 files changed, 3 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > index cb76074..6d31ed8 100644
> > --- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > +++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > @@ -58,10 +58,7 @@ static void
> > dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > /* set HDMI mode */
> > tmp |= HDMI_CONNECTION;
> > - if (sad_count)
> > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > - else
> > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
> >
> > kfree(sadb);
> > diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c
> > b/drivers/gpu/drm/radeon/dce6_afmt.c
> > index ab29f95..e6b2750 100644
> > --- a/drivers/gpu/drm/radeon/dce6_afmt.c
> > +++ b/drivers/gpu/drm/radeon/dce6_afmt.c
> > @@ -186,10 +186,7 @@ void dce6_afmt_write_speaker_allocation(struct
> > drm_encoder *encoder)
> > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > /* set HDMI mode */
> > tmp |= HDMI_CONNECTION;
> > - if (sad_count)
> > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > - else
> > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > WREG32_ENDPOINT(offset,
> > AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
> >
> > kfree(sadb);
> > diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > index 278c7a1..11a6b65 100644
> > --- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > +++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > @@ -128,10 +128,7 @@ static void
> > dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > /* set HDMI mode */
> > tmp |= HDMI_CONNECTION;
> > - if (sad_count)
> > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > - else
> > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
> >
> > kfree(sadb);
> > --
> > 2.0.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/radeon: remove code that can never get executed
2014-10-13 16:44 ` Henning Schild
@ 2014-10-13 17:31 ` Deucher, Alexander
2014-10-13 17:54 ` Henning Schild
0 siblings, 1 reply; 6+ messages in thread
From: Deucher, Alexander @ 2014-10-13 17:31 UTC (permalink / raw)
To: Henning Schild, linux-kernel; +Cc: Rafał Miłecki
[-- Attachment #1: Type: text/plain, Size: 4514 bytes --]
> -----Original Message-----
> From: Henning Schild [mailto:henning@hennsch.de]
> Sent: Monday, October 13, 2014 12:44 PM
> To: Deucher, Alexander; linux-kernel@vger.kernel.org
> Cc: Rafał Miłecki
> Subject: RE: [PATCH] drm/radeon: remove code that can never get executed
>
> Well i am not sure what the code actually is supposed to do. That is up to you
> because you know the hardware. I just wanted to point out that right now
> some
> code can never be reached.
>
> I ran into the whole thing because the pointer (sadp) that gets kfreed was
> never
> initialized (in one of the three cases). My first fix was to initialize it to
> NULL, that way the kfree did not fail even if the allocation did not do
> anything. Then i found the other two copies and decided to follow their
> scheme.
>
> In your patch you have to make kfree depend on (sad_count > 0) or sadp
> needs to
> be initialized with NULL. Otherwise you will get the dangling pointer kfree
> that
> lead me to read this code.
>
Ah, ok. The attached patches should do the trick then.
Alex
> Henning
>
> > On October 13, 2014 at 6:08 PM "Deucher, Alexander"
> > <Alexander.Deucher@amd.com> wrote:
> >
> > > -----Original Message-----
> > > From: Henning Schild [mailto:henning@hennsch.de]
> > > Sent: Saturday, October 11, 2014 8:51 AM
> > > To: linux-kernel@vger.kernel.org
> > > Cc: Henning Schild; Deucher, Alexander; Rafał Miłecki
> > > Subject: [PATCH] drm/radeon: remove code that can never get executed
> > >
> > > Removing a code-path that can never be executed ... and its copies. If
> > > drm_edid_to_speaker_allocation returns 0 the callers return. There is no
> > > need to check that condition again.
> >
> > I think we actually want to set the speaker allocation setup to stereo if the
> > speaker allocation block is not present so I think the attached patch is
> > probably the proper fix.
> >
> > Alex
> >
> > >
> > > Signed-off-by: Henning Schild <henning@hennsch.de>
> > > ---
> > > drivers/gpu/drm/radeon/dce3_1_afmt.c | 5 +----
> > > drivers/gpu/drm/radeon/dce6_afmt.c | 5 +----
> > > drivers/gpu/drm/radeon/evergreen_hdmi.c | 5 +----
> > > 3 files changed, 3 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > > b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > > index cb76074..6d31ed8 100644
> > > --- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > > +++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
> > > @@ -58,10 +58,7 @@ static void
> > > dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> > > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > > /* set HDMI mode */
> > > tmp |= HDMI_CONNECTION;
> > > - if (sad_count)
> > > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > - else
> > > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
> > >
> > > kfree(sadb);
> > > diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c
> > > b/drivers/gpu/drm/radeon/dce6_afmt.c
> > > index ab29f95..e6b2750 100644
> > > --- a/drivers/gpu/drm/radeon/dce6_afmt.c
> > > +++ b/drivers/gpu/drm/radeon/dce6_afmt.c
> > > @@ -186,10 +186,7 @@ void dce6_afmt_write_speaker_allocation(struct
> > > drm_encoder *encoder)
> > > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > > /* set HDMI mode */
> > > tmp |= HDMI_CONNECTION;
> > > - if (sad_count)
> > > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > - else
> > > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > WREG32_ENDPOINT(offset,
> > > AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
> > >
> > > kfree(sadb);
> > > diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > > b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > > index 278c7a1..11a6b65 100644
> > > --- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > > +++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
> > > @@ -128,10 +128,7 @@ static void
> > > dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
> > > tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
> > > /* set HDMI mode */
> > > tmp |= HDMI_CONNECTION;
> > > - if (sad_count)
> > > - tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > - else
> > > - tmp |= SPEAKER_ALLOCATION(5); /* stereo */
> > > + tmp |= SPEAKER_ALLOCATION(sadb[0]);
> > > WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
> > >
> > > kfree(sadb);
> > > --
> > > 2.0.4
>
> >
[-- Attachment #2: 0001-drm-radeon-initialize-sadb-to-NULL-in-the-audio-code.patch --]
[-- Type: application/octet-stream, Size: 2113 bytes --]
From 432aefea7cf48d31ea665cac13de71af8036bb55 Mon Sep 17 00:00:00 2001
From: Alex Deucher <alexander.deucher@amd.com>
Date: Mon, 13 Oct 2014 13:23:48 -0400
Subject: [PATCH 1/2] drm/radeon: initialize sadb to NULL in the audio code
Fixes kfree of the sadb buffer when it's NULL.
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
drivers/gpu/drm/radeon/dce3_1_afmt.c | 2 +-
drivers/gpu/drm/radeon/dce6_afmt.c | 2 +-
drivers/gpu/drm/radeon/evergreen_hdmi.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index 950af15..6b1dbec 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -32,7 +32,7 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
struct drm_connector *connector;
struct radeon_connector *radeon_connector = NULL;
u32 tmp;
- u8 *sadb;
+ u8 *sadb = NULL;
int sad_count;
list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index c0bbf68..960a5f0 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -155,7 +155,7 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
struct drm_connector *connector;
struct radeon_connector *radeon_connector = NULL;
u32 offset, tmp;
- u8 *sadb;
+ u8 *sadb = NULL;
int sad_count;
if (!dig || !dig->afmt || !dig->afmt->pin)
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index 2514d65..f6a5c30 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -133,7 +133,7 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
struct drm_connector *connector;
struct radeon_connector *radeon_connector = NULL;
u32 tmp;
- u8 *sadb;
+ u8 *sadb = NULL;
int sad_count;
list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
--
1.8.3.1
[-- Attachment #3: 0002-drm-radeon-fix-speaker-allocation-setup.patch --]
[-- Type: application/octet-stream, Size: 2640 bytes --]
From 3412efaaf01eab20d5570f5b4818db928644f0db Mon Sep 17 00:00:00 2001
From: Alex Deucher <alexander.deucher@amd.com>
Date: Mon, 13 Oct 2014 11:51:50 -0400
Subject: [PATCH 2/2] drm/radeon: fix speaker allocation setup
If the sad_count is 0, set the hw to stereo and change
the error message to a warn. A lot of monitors don't
set the speaker allocation block.
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
---
drivers/gpu/drm/radeon/dce3_1_afmt.c | 4 ++--
drivers/gpu/drm/radeon/dce6_afmt.c | 6 +++---
drivers/gpu/drm/radeon/evergreen_hdmi.c | 6 +++---
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index 6b1dbec..2fe8cfc 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -49,8 +49,8 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
if (sad_count < 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index 960a5f0..f312edf 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -176,9 +176,9 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
}
sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
- if (sad_count <= 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ if (sad_count < 0) {
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index f6a5c30..53abd9b 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -149,9 +149,9 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
}
sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
- if (sad_count <= 0) {
- DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
- return;
+ if (sad_count < 0) {
+ DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
+ sad_count = 0;
}
/* program the speaker allocation */
--
1.8.3.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/radeon: remove code that can never get executed
2014-10-13 17:31 ` Deucher, Alexander
@ 2014-10-13 17:54 ` Henning Schild
0 siblings, 0 replies; 6+ messages in thread
From: Henning Schild @ 2014-10-13 17:54 UTC (permalink / raw)
To: Deucher, Alexander; +Cc: linux-kernel, Rafał Miłecki
On Mon, 13 Oct 2014 17:31:12 +0000
"Deucher, Alexander" <Alexander.Deucher@amd.com> wrote:
> Ah, ok. The attached patches should do the trick then.
Yes that would do the trick. But i suggest doing the NULL initialization
in drm_edid_to_speaker_allocation.
The kernel doc suggests that whatever drm_edid_to_speaker_allocation
returns should be freed. Depending on which version you prefer, the
doc might have to be changed as well.
Henning
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-10-13 17:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-11 12:37 [PATCH] drm/radeon: fix dangling pointer kfree Henning Schild
2014-10-11 12:51 ` [PATCH] drm/radeon: remove code that can never get executed Henning Schild
2014-10-13 16:08 ` Deucher, Alexander
2014-10-13 16:44 ` Henning Schild
2014-10-13 17:31 ` Deucher, Alexander
2014-10-13 17:54 ` Henning Schild
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome