Skip to contentSkip to conversation

Some issues found with Klockwork

PATCH In review Martin Peres 4 participants 23 messages Feb 12, 2016 – Feb 16, 2016

lore
Share & tools
lore
#0 lore raw

cover Some issues found with Klockwork

The DDX clearly is making Klockwork unhappy but I found those potential issues. Let's use them as a basis for discussion on the real code that should be written.

Martin Peres (7):
device: prevent a NULL pointer dereference in __intel_peek_fd
display: prevent a NULL pointer dereference in
intel_set_scanout_pixmap
sna: check for NULL before dereferencing a pointer
sna: assert a pointer is non-NULL before dereferencing it sna/cursor: add an assert on cursor->image
sna_video_sprite: add asserts to catch invalid pipe#
sna: add an assert in the lengthy sna_drawable_use_bo

 src/intel_device.c         | 5 ++++-
 src/sna/sna_accel.c        | 5 ++++-
 src/sna/sna_display.c      | 3 ++-
 src/sna/sna_video_sprite.c | 3 +++
 src/uxa/intel_display.c    | 5 +++++
 5 files changed, 18 insertions(+), 3 deletions(-)
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/7 device: prevent a NULL pointer dereference in __intel_peek_fd

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
 src/intel_device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/intel_device.c +4 -1
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
 	dev = intel_device(scrn);
 	assert(dev && dev->fd != -1);
 
-	return dev->fd;
+	if (!dev)
+		return -1;
+	else
+		return dev->fd;
 }
 
 int intel_has_render_node(struct intel_device *dev)
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 2 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Impossible.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

In reply to Martin Peres
Quoted 15 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
src/intel_device.c +0 -0
index 54c1443..35e652a 100644

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 2 lines
src/intel_device.c +0 -0
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
  	dev = intel_device(scrn);
  	assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

.Dave.

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 659

Quoted 8 lines
src/intel_device.c +4 -1
-	return dev->fd;
+	if (!dev)
+		return -1;
+	else
+		return dev->fd;
  }
 
  int intel_has_render_node(struct intel_device *dev)

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
      dev = intel_device(scrn);
      assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

It does not, I had to close many false positives related to this...
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 23 lines · Martin Peres
Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
      dev = intel_device(scrn);
      assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

Quoted 1 line

It does not, I had to close many false positives related to this...

Hmmm .. elsewhere (e.g. [4/7]) you have /added/ an assert, which I thought must be so that Klocwork stops complaining that something might be NULL ... maybe it can't handle the composite assertion? Does it silence the complaint if you change:

    assert(dev && dev->fd != -1);
into:
    assert(dev);
    assert(dev->fd != -1);

?

.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 30 lines · Dave Gordon
Quoted 23 lines · Martin Peres
Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
      dev = intel_device(scrn);
      assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

Quoted 1 line

It does not, I had to close many false positives related to this...

Hmmm .. elsewhere (e.g. [4/7]) you have /added/ an assert, which I thought must be so that Klocwork stops complaining that something might be NULL ... maybe it can't handle the composite assertion? Does it silence the complaint if you change:

Quoted 5 lines
     assert(dev && dev->fd != -1);
into:
     assert(dev);
     assert(dev->fd != -1);

?

Sure, I added an assert, but not to silence patchwork, just to make sure we have no problem. I cannot run klokwork myself and my goal was not to silence but instead to check the reported issues.

David is right, I think Klokwork only cares about runtime checks and wants to make sure that we never de-reference a NULL pointer.

Martin
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 37 lines · Martin Peres
Quoted 30 lines · Dave Gordon
Quoted 23 lines · Martin Peres
Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
      dev = intel_device(scrn);
      assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

Quoted 1 line

It does not, I had to close many false positives related to this...

Hmmm .. elsewhere (e.g. [4/7]) you have /added/ an assert, which I thought must be so that Klocwork stops complaining that something might be NULL ... maybe it can't handle the composite assertion? Does it silence the complaint if you change:

Quoted 5 lines
     assert(dev && dev->fd != -1);
into:
     assert(dev);
     assert(dev->fd != -1);

?

Quoted 8 lines

Sure, I added an assert, but not to silence patchwork, just to make sure we have no problem. I cannot run klokwork myself and my goal was not to silence but instead to check the reported issues.

David is right, I think Klokwork only cares about runtime checks and wants to make sure that we never de-reference a NULL pointer.

Martin

Klocwork is trying (by static analysis) to find all reachable code, with all possible parameter values at each point. It's configured with various checkers that examine each expression reached for things such as dereferencing a possibly-NULL pointer, or indexing beyond the bounds of an array, or integer overflow, or many other things ...

The standard definition of assert() is something like:

    #define assert(x) do { if(!(x)) abort(); } while (0)

and Klocwork knows that abort() doesn't return, so in the block

    dev = intel_device(scrn);
    assert(dev);
    return dev->fd;

it can deduce that the 'return' is reached only if the abort() was not, hence only if 'dev' is non-NULL. Therefore, this doesn't produce a complaint about a possibly-NULL pointer, because Klocwork knows it isn't because of the assert().

Of course there are potentially multiple definitions of assert(), typically including a null one, for production code, and a debug version that gives more detail. So the usual thing is to ensure that there's a Klocwork-specific version that allows KW to do the analysis above, even if that version isn't something you would ever run:

#if defined(__KLOCWORK__)
#define assert(x) do { if(!(x)) abort(); } while (0)
#elif defined(NO_DEBUG)
#define assert(x) do { /* nothing */ ; } while (0)
#elif defined(EXTRA_DEBUG)
#define assert(x) do { my_assert(x, #x, __LINE__, __FILE__); } while (0) #else
// ... etc ...
#endif

If we don't have something like this, Klocwork may not be able to make effective deductions about the possible values of variables at specific points, so it would be worth checking that we're using macros that it understands.

.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 75 lines · Dave Gordon
Quoted 38 lines · Martin Peres
Quoted 31 lines · Dave Gordon
Quoted 24 lines · Martin Peres
Quoted 12 lines · Dave Gordon
Quoted 11 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses
it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
      dev = intel_device(scrn);
      assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

Quoted 1 line

It does not, I had to close many false positives related to this...

Hmmm .. elsewhere (e.g. [4/7]) you have /added/ an assert, which I thought must be so that Klocwork stops complaining that something might be NULL ... maybe it can't handle the composite assertion? Does it silence the complaint if you change:

Quoted 5 lines
     assert(dev && dev->fd != -1);
into:
     assert(dev);
     assert(dev->fd != -1);

?

Quoted 8 lines

Sure, I added an assert, but not to silence patchwork, just to make sure we have no problem. I cannot run klokwork myself and my goal was not to silence but instead to check the reported issues.

David is right, I think Klokwork only cares about runtime checks and wants to make sure that we never de-reference a NULL pointer.

Martin

Klocwork is trying (by static analysis) to find all reachable code, with all possible parameter values at each point. It's configured with various checkers that examine each expression reached for things such as dereferencing a possibly-NULL pointer, or indexing beyond the bounds of an array, or integer overflow, or many other things ...

The standard definition of assert() is something like:

     #define assert(x) do { if(!(x)) abort(); } while (0)

and Klocwork knows that abort() doesn't return, so in the block

     dev = intel_device(scrn);
     assert(dev);
     return dev->fd;

it can deduce that the 'return' is reached only if the abort() was not, hence only if 'dev' is non-NULL. Therefore, this doesn't produce a complaint about a possibly-NULL pointer, because Klocwork knows it isn't because of the assert().

Of course there are potentially multiple definitions of assert(), typically including a null one, for production code, and a debug version that gives more detail. So the usual thing is to ensure that there's a Klocwork-specific version that allows KW to do the analysis above, even if that version isn't something you would ever run:

Quoted 9 lines

#if defined(__KLOCWORK__)
#define assert(x) do { if(!(x)) abort(); } while (0)
#elif defined(NO_DEBUG)
#define assert(x) do { /* nothing */ ; } while (0)
#elif defined(EXTRA_DEBUG)
#define assert(x) do { my_assert(x, #x, __LINE__, __FILE__); } while (0) #else
// ... etc ...
#endif

That sounds like a good idea, yes.

Here is the current definition: https://cgit.freedesktop.org/xorg/driver/xf86-video-intel/tree/src/sna/xassert.h

Quoted 5 lines

If we don't have something like this, Klocwork may not be able to make effective deductions about the possible values of variables at specific points, so it would be worth checking that we're using macros that it understands.

We don't, because there is a test on NDEBUG which Klokwork cannot make assumptions on, as David said.

I will hold on to this idea a little as there are talks internally on to which static analysis tool needs to be used.

Thanks for your feedback,
Martin
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

In reply to Dave Gordon
Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
 src/intel_device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
 	dev = intel_device(scrn);
 	assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

My guess is that klockwork recognises that assert() can be a no-op if NDEBUG is defined and in such case won't generate code. In such a case neither of those two checks are performed.

Kind regards, David
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw

Re: [PATCH 1/7] device: prevent a NULL pointer dereference in __intel_peek_fd

Quoted 23 lines · David Weinehall
Quoted 11 lines · Dave Gordon
Quoted 10 lines · Martin Peres

This is not a big issue to return -1 since the only codepath that uses it is for display purposes.

Caught by Klockwork.

---
  src/intel_device.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines

src/intel_device.c int __intel_peek_fd(ScrnInfoPtr scrn) · line 651

Quoted 7 lines
src/intel_device.c +0 -0
index 54c1443..35e652a 100644
@@ -650,7 +650,10 @@ int __intel_peek_fd(ScrnInfoPtr scrn)
  	dev = intel_device(scrn);
  	assert(dev && dev->fd != -1);

Doesn't Klocwork recognise the assert() above? I thought that would tell it that dev can't be NULL.

Quoted 5 lines

My guess is that klockwork recognises that assert() can be a no-op if NDEBUG is defined and in such case won't generate code. In such a case neither of those two checks are performed.

Kind regards, David

Klocwork is a static analysis tool, it doesn't generate code at all.
It's supposed to recognise assert() and similar macros as constraints on what values particular expressions may have; in particular, it knows that if a code path ends with a call to abort(), that path *should* never be taken and it will assume (for static analysis purposes) that it *will* not be taken. Thus any combination of values that leads to an abort() is considered "impossible" and need not be further checked. Then assert() is typically defined as:

    #define assert(x) do { if(!(x)) abort(); } while (0)

and then

    int foo(char *s)
    {
        assert(s);
        return *s;
    }

should not cause Klocwork to complain, whereas without the assert() it should say that 's' might be NULL when dereferenced. If it's getting false positives it may be that Klocwork hasn't been told the proper (conditional) definition for assert()?

.Dave.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#11 lore raw

PATCH 2/7 display: prevent a NULL pointer dereference in intel_set_scanout_pixmap

In reply to Martin Peres

Caught by Klockwork.

---
 src/uxa/intel_display.c | 5 +++++
 1 file changed, 5 insertions(+)
src/uxa/intel_display.c +5 -0
index 8bf0184..44744a5 100644
@@ -688,6 +688,11 @@ intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	}
 
 	bo = intel_get_pixmap_bo(ppix);
+	if (!bo) {
+		ErrorF("pixmap is not backed by a BO\n");
+		return FALSE;
+	}
+
 	if (intel->front_buffer) {
 		ErrorF("have front buffer\n");
 	}
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

Re: [PATCH 2/7] display: prevent a NULL pointer dereference in intel_set_scanout_pixmap

Quoted 12 lines · Martin Peres

Caught by Klockwork.

---
 src/uxa/intel_display.c | 5 +++++
 1 file changed, 5 insertions(+)
src/uxa/intel_display.c +0 -0
index 8bf0184..44744a5 100644

src/uxa/intel_display.c intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) · line 692

Quoted 5 lines
src/uxa/intel_display.c +2 -0
@@ -688,6 +688,11 @@ intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	}
 
 	bo = intel_get_pixmap_bo(ppix);
+	if (!bo) {
+		ErrorF("pixmap is not backed by a BO\n");

Just return FALSE.

src/uxa/intel_display.c intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) · line 697

Quoted 5 lines
src/uxa/intel_display.c +3 -0
+		return FALSE;
+	}
+
 	if (intel->front_buffer) {
 		ErrorF("have front buffer\n");

And let's add the return here as well instead of the ErrorF

If the caller does make the mistake of passing in an invalid Pixmap, what's the likelihood of them checking the return? ;) -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

PATCH 3/7 sna: check for NULL before dereferencing a pointer

In reply to Martin Peres

Caught by Klockwork and I genuinely can't tell if it is safe without it, especially since all the surrounding code is checking for NULL.

---
 src/sna/sna_accel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/sna/sna_accel.c +2 -1
index 71a6207..8ceb1e1 100644
@@ -3688,7 +3688,8 @@ sna_drawable_use_bo(DrawablePtr drawable, unsigned flags, const BoxRec *box,
 	     __FUNCTION__, priv->flush, priv->shm, priv->cpu, flags));
 
 	if ((flags & PREFER_GPU) == 0 &&
-	    (flags & (REPLACES | IGNORE_DAMAGE) || !priv->gpu_damage || !kgem_bo_is_busy(priv->gpu_bo))) {
+	    (flags & (REPLACES | IGNORE_DAMAGE) || !priv->gpu_damage ||
+	     (priv->gpu_bo && !kgem_bo_is_busy(priv->gpu_bo)))) {
 		DBG(("%s: try cpu as GPU bo is idle\n", __FUNCTION__));
 		goto use_cpu_bo;
 	}
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

Re: [PATCH 3/7] sna: check for NULL before dereferencing a pointer

Quoted 2 lines · Martin Peres

Caught by Klockwork and I genuinely can't tell if it is safe without it, especially since all the surrounding code is checking for NULL.

Impossible.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#15 lore raw

PATCH 4/7 sna: assert a pointer is non-NULL before dereferencing it

In reply to Martin Peres

Caught by Klockwork.

---
 src/sna/sna_accel.c | 1 +
 1 file changed, 1 insertion(+)
src/sna/sna_accel.c +1 -0
index 8ceb1e1..f1c136a 100644
@@ -4376,6 +4376,7 @@ sna_pixmap_move_to_gpu(PixmapPtr pixmap, unsigned flags)
 
 	if (priv->shm) {
 		assert(!priv->flush);
+		assert(priv->cpu_bo);
 		sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
 	}
 
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#16 lore raw

Re: [PATCH 4/7] sna: assert a pointer is non-NULL before dereferencing it

Quoted 1 line · Martin Peres

Caught by Klockwork.

Impossible.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

PATCH 5/7 sna/cursor: add an assert on cursor->image

In reply to Martin Peres

Caught by Klockwork, but it was a false positive. However, better safe than sorry.

---
 src/sna/sna_display.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/sna/sna_display.c +2 -1
index 9215b23..78937c2 100644
@@ -5573,8 +5573,9 @@ static struct sna_cursor *__sna_get_cursor(struct sna *sna, xf86CrtcPtr crtc)
 	argb = get_cursor_argb(sna->cursor.ref);
 	pitch = BitmapBytePad(width);
 
+	assert(cursor->image);
 	image = cursor->image;
-	if (image == NULL || transformed) {
+	if (transformed) {
 		image = sna->cursor.scratch;
 		cursor->last_width = cursor->last_height = size;
 	}
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

Re: [PATCH 5/7] sna/cursor: add an assert on cursor->image

Quoted 2 lines · Martin Peres

Caught by Klockwork, but it was a false positive. However, better safe than sorry.

No. cursor->image can be NULL for old gen/kernels. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#19 lore raw

PATCH 6/7 sna_video_sprite: add asserts to catch invalid pipe#

In reply to Martin Peres

Caught by Klockwork. This will be enough to catch those issues during bringup.

---
 src/sna/sna_video_sprite.c | 3 +++
 1 file changed, 3 insertions(+)
src/sna/sna_video_sprite.c +3 -0
index 9e85049..ae08ef7 100644
@@ -86,6 +86,7 @@ static int sna_video_sprite_stop(ddStopVideo_ARGS)
 		int pipe;
 
 		pipe = sna_crtc_pipe(crtc);
+		assert(pipe < ARRAY_SIZE(video->bo));
 		if (video->bo[pipe] == NULL)
 			continue;
 
@@ -260,6 +261,7 @@ sna_video_sprite_show(struct sna *sna,
 		video->color_key_changed &= ~(1 << pipe);
 	}
 
+	assert(pipe < ARRAY_SIZE(video->bo));
 	if (video->bo[pipe] == frame->bo)
 		return true;
 
@@ -415,6 +417,7 @@ static int sna_video_sprite_put_image(ddPutImage_ARGS)
 		RegionIntersect(&reg, &reg, &clip);
 		if (RegionNil(&reg)) {
 off:
+			assert(pipe < ARRAY_SIZE(video->bo));
 			if (video->bo[pipe]) {
 				struct local_mode_set_plane s;
 				memset(&s, 0, sizeof(s));
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 6/7
#20 lore raw

Re: [PATCH 6/7] sna_video_sprite: add asserts to catch invalid pipe#

Quoted 2 lines · Martin Peres

Caught by Klockwork. This will be enough to catch those issues during bringup.

But you just said that klockwork didn't find a bug... :-p

I did contemplate having this stored on the CRTC instead.

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#21 lore raw

PATCH 7/7 sna: add an assert in the lengthy sna_drawable_use_bo

In reply to Martin Peres

I got lost in all the changes done on priv->flush and gpu_bo enough not to be able to guarantee that if flush is non-null, so is gpu_bo.

Caught by Klockwork.

---
 src/sna/sna_accel.c | 1 +
 1 file changed, 1 insertion(+)
src/sna/sna_accel.c +1 -0
index f1c136a..595faa6 100644
@@ -4074,6 +4074,7 @@ prefer_gpu_bo:
 	}
 	if (priv->flush) {
 		assert(!priv->shm);
+		assert(priv->gpu_bo);
 		sna_add_flush_pixmap(sna, priv, priv->gpu_bo);
 	}
 
Signature · 6 lines
2.7.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#22 lore raw

Re: [PATCH 7/7] sna: add an assert in the lengthy sna_drawable_use_bo

Quoted 4 lines · Martin Peres

I got lost in all the changes done on priv->flush and gpu_bo enough not to be able to guarantee that if flush is non-null, so is gpu_bo.

Caught by Klockwork.

Nope, impossible.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx