Skip to contentSkip to conversation

drm: fsl-dcu: Fix no fb check bug

PATCH RESEND In review Meng Yi 3 participants 6 messages Jan 6, 2016 – Jan 28, 2016

Subsystems (3)
lore
Share & tools
lore

Meng Yi

author
#0 lore raw

PATCH RESEND v2 1/1 drm: fsl-dcu: Fix no fb check bug

For state->fb or state->crtc may be NULL in fsl_dcu_drm_plane_atomic_check function, if so, return 0.

---

change in v2:
-Add state->crtc check
-return 0 when state->fb or state->crtc is NULL, instead of -EINVAL Adviced by Daniel Stone

 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +3 -3
index 4b13cf9..8965580 100644
@@ -41,6 +41,9 @@ static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane,
 {
 	struct drm_framebuffer *fb = state->fb;
 
+	if (!state->fb || !state->crtc)
+		return 0;
+
 	switch (fb->pixel_format) {
 	case DRM_FORMAT_RGB565:
 	case DRM_FORMAT_RGB888:
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane,
 	unsigned int alpha, bpp;
 	int index, ret;
 
-	if (!fb)
-		return;
-
 	index = fsl_dcu_drm_plane_index(plane);
 	if (index < 0)
 		return;
Signature · 6 lines
2.1.0.27.g96db324

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi guys,

Am I loosing the plot here or something feels amiss here ?

Quoted 21 lines · Meng Yi

For state->fb or state->crtc may be NULL in fsl_dcu_drm_plane_atomic_check function, if so, return 0.

---

change in v2:

(quoted diff) +0 -2
-Add state->crtc check
-return 0 when state->fb or state->crtc is NULL, instead of -EINVAL

Adviced by Daniel Stone

 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -0
index 4b13cf9..8965580 100644

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane, · line 46

Quoted 6 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +3 -0
@@ -41,6 +41,9 @@ static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane,
 {
        struct drm_framebuffer *fb = state->fb;
 
+       if (!state->fb || !state->crtc)
+               return 0;
+

Namely: if we return success here core drm will end up calling the atomic_update...

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, · line 90

Quoted 10 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane,
        unsigned int alpha, bpp;
        int index, ret;
 
-       if (!fb)
-               return;
-

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#2 lore raw
Quoted 29 lines · Emil Velikov

Hi guys,

Am I loosing the plot here or something feels amiss here ?

Quoted 24 lines · Meng Yi

For state->fb or state->crtc may be NULL in fsl_dcu_drm_plane_atomic_check function, if so, return 0.

---

change in v2:

(quoted diff) +0 -2
-Add state->crtc check
-return 0 when state->fb or state->crtc is NULL, instead of -EINVAL

Adviced by Daniel Stone

 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -0
index 4b13cf9..8965580 100644
@@ -41,6 +41,9 @@ static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane,
 {
        struct drm_framebuffer *fb = state->fb;
 
Quoted 6 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane, · line 46

Quoted 3 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +3 -0
+       if (!state->fb || !state->crtc)
+               return 0;
+

Namely: if we return success here core drm will end up calling the atomic_update...

After atomic_check atomic_disable could be called too. However, this seem not directly depend on state'>fb, but more on plane->state->crtc.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -0
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane,
        unsigned int alpha, bpp;
        int index, ret;
 
Quoted 5 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, · line 90

Quoted 3 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
-       if (!fb)
-               return;
-

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

If there is a legitimate situation where fb is null which also ultimately leads to a atomic_commit, I guess we should keep the return here...

--
Stefan
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#3 lore raw
Quoted 11 lines
Quoted 4 lines

Review static void fsl_dcu_drm_plane_atomic_update(struct

Quoted 4 lines
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
(quoted diff) +0 -0
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct

drm_plane *plane,

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
        unsigned int alpha, bpp;
        int index, ret;
 
-       if (!fb)
-               return;
-
Quoted 6 lines
Quoted 2 lines

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

If there is a legitimate situation where fb is null which also ultimately leads to a atomic_commit, I guess we should keep the return here...

I think I made a mistake here, fb check should not be removed . As Stefan mentioned, if fb check in fsl_dcu_drm_plane_atomic_check return 0, fsl_dcu_drm_plane_atomic_update will ultimately called, and we'll crash since plane->state->fb is NULL.

Quoted 66 lines

-----Original Message-----
From: Stefan Agner [mailto:[email protected]]
Sent: Thursday, January 14, 2016 1:54 PM
To: Emil Velikov <[email protected]>
Cc: Meng Yi <[email protected]>; ML dri-devel <dri- [email protected]>
Subject: Re: [RESEND,V2] drm: fsl-dcu: Fix no fb check bug

Quoted 30 lines · Emil Velikov

Hi guys,

Am I loosing the plot here or something feels amiss here ?

Quoted 25 lines · Meng Yi

For state->fb or state->crtc may be NULL in fsl_dcu_drm_plane_atomic_check function, if so, return 0.

---

change in v2:

(quoted diff) +0 -2
-Add state->crtc check
-return 0 when state->fb or state->crtc is NULL, instead of -EINVAL

Adviced by Daniel Stone

 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -0
index 4b13cf9..8965580 100644
@@ -41,6 +41,9 @@ static int fsl_dcu_drm_plane_atomic_check(struct
 drm_plane *plane,  {
        struct drm_framebuffer *fb = state->fb;
 
Quoted 6 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane, · line 46

Quoted 3 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +3 -0
+       if (!state->fb || !state->crtc)
+               return 0;
+

Namely: if we return success here core drm will end up calling the atomic_update...

After atomic_check atomic_disable could be called too. However, this seem not directly depend on state'>fb, but more on plane->state->crtc.

Quoted 4 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static void fsl_dcu_drm_plane_atomic_update(struct

Quoted 4 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -0
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct

drm_plane *plane,

Quoted 8 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, · line 90

Quoted 6 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
        unsigned int alpha, bpp;
        int index, ret;
 
-       if (!fb)
-               return;
-

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

Quoted 5 lines

If there is a legitimate situation where fb is null which also ultimately leads to a atomic_commit, I guess we should keep the return here...

--
Stefan

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 11 lines · Meng Yi
Quoted 11 lines
Quoted 4 lines

Review static void fsl_dcu_drm_plane_atomic_update(struct

Quoted 4 lines
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
(quoted diff) +0 -0
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct

drm_plane *plane,

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
        unsigned int alpha, bpp;
        int index, ret;
 
-       if (!fb)
-               return;
-
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

If there is a legitimate situation where fb is null which also ultimately leads to a atomic_commit, I guess we should keep the return here...

I think I made a mistake here, fb check should not be removed . As Stefan mentioned, if fb check in fsl_dcu_drm_plane_atomic_check return 0, fsl_dcu_drm_plane_atomic_update will ultimately called, and we'll crash since plane->state->fb is NULL.

I believe you meant "Emil" in the above ;-) But seriously... afaict a fair few drivers do a similar !fb (even !state->crtc) check(s)... which makes me wonder if core DRM isn't the better place for it ? Or perhaps that's intentional as core provides the flexibility for each driver to mangle with the fb between .check and .disable ?

Cheers
Emil

P.S. Please don't top post, use interleaved style [1]

[1] https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#5 lore raw
Quoted 19 lines · Emil Velikov
Quoted 18 lines · Meng Yi
Quoted 17 lines
Quoted 4 lines

Review static void fsl_dcu_drm_plane_atomic_update(struct

Quoted 4 lines
        switch (fb->pixel_format) {
        case DRM_FORMAT_RGB565:
        case DRM_FORMAT_RGB888:
(quoted diff) +0 -0
@@ -85,9 +88,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct

drm_plane *plane,

Quoted 8 lines

drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, · line 90

Quoted 6 lines
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +0 -3
        unsigned int alpha, bpp;
        int index, ret;
 
-       if (!fb)
-               return;
-

... which no longer has the !fb check, and we'll crash with null deref a few lines below ?

If there is a legitimate situation where fb is null which also ultimately leads to a atomic_commit, I guess we should keep the return here...

Quoted 8 lines
Quoted 2 lines

I think I made a mistake here, fb check should not be removed . As Stefan mentioned, if fb check in fsl_dcu_drm_plane_atomic_check return 0, fsl_dcu_drm_plane_atomic_update will ultimately called, and we'll crash since plane->state->fb is NULL.

I believe you meant "Emil" in the above ;-) But seriously... afaict a fair few drivers do a similar !fb (even !state->crtc) check(s)... which makes me wonder if core DRM isn't the better place for it ? Or perhaps that's intentional as core provides the flexibility for each driver to mangle with the fb between .check and .disable ?

There seem to be a consensus to check crtc and fb on atomic_check.

However, in atomic_update, some drives do a NULL check on crtc only, and some on both, crtc and fb.

The comment in drm_atomic_plane_disabling says CRTC and FB should always be NULL together... So I guess it does not really matter all that much, unless there is anyway a bug.

Furthermore, it seems that in the null case, atomic_disable is called anyway (which this driver implements). Not sure if there is another case in which either of this two could be NULL and atomic_update could be called.

Since this patch is mainly addressing the null check in atomic_check, I will apply it without the change in atomic_update for now.

--
Stefan

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel