diff mbox

[1/1] drm/radeon: Make r100_cp_ring_info() and radeon_ring_gfx() safe

Message ID F489A0B0-4FFC-4486-97CE-C55167D73C22@p0n4ik.tk (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Ivanov Sept. 20, 2013, 1:36 p.m. UTC
Prevent NULL pointer dereference in case when radeon_ring_fini() did it's job.

Reading of r100_cp_ring_info and radeon_ring_gfx debugfs entries will lead to a KP if ring buffer was deallocated, e.g. on failed ring test. 
Seen on PA-RISC machine having "radeon: ring test failed (scratch(0x8504)=0xCAFEDEAD)" issue.

Signed-off-by: Alex Ivanov <gnidorah@p0n4ik.tk>
---

Comments

Alex Deucher Sept. 20, 2013, 6:33 p.m. UTC | #1
On Fri, Sep 20, 2013 at 9:36 AM, Alex Ivanov <gnidorah@p0n4ik.tk> wrote:
> Prevent NULL pointer dereference in case when radeon_ring_fini() did it's job.
>
> Reading of r100_cp_ring_info and radeon_ring_gfx debugfs entries will lead to a KP if ring buffer was deallocated, e.g. on failed ring test.
> Seen on PA-RISC machine having "radeon: ring test failed (scratch(0x8504)=0xCAFEDEAD)" issue.
>
> Signed-off-by: Alex Ivanov <gnidorah@p0n4ik.tk>

Applied.  thanks!

Alex

> ---
> diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
> index 2417571..413cdd1 100644
> --- a/drivers/gpu/drm/radeon/r100.c
> +++ b/drivers/gpu/drm/radeon/r100.c
> @@ -2933,10 +2933,11 @@ static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data)
>         seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp);
>         seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
>         seq_printf(m, "%u dwords in ring\n", count);
> -       for (j = 0; j <= count; j++) {
> -               i = (rdp + j) & ring->ptr_mask;
> -               seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
> -       }
> +       if (ring->ready)
> +               for (j = 0; j <= count; j++) {
> +                       i = (rdp + j) & ring->ptr_mask;
> +                       seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
> +               }
>         return 0;
>  }
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
> index 46a25f0..a890756 100644
> --- a/drivers/gpu/drm/radeon/radeon_ring.c
> +++ b/drivers/gpu/drm/radeon/radeon_ring.c
> @@ -839,10 +839,11 @@ static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
>          * packet that is the root issue
>          */
>         i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
> -       for (j = 0; j <= (count + 32); j++) {
> -               seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
> -               i = (i + 1) & ring->ptr_mask;
> -       }
> +       if (ring->ready)
> +               for (j = 0; j <= (count + 32); j++) {
> +                       seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
> +                       i = (i + 1) & ring->ptr_mask;
> +               }
>         return 0;
>  }
>
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 2417571..413cdd1 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -2933,10 +2933,11 @@  static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data)
 	seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp);
 	seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
 	seq_printf(m, "%u dwords in ring\n", count);
-	for (j = 0; j <= count; j++) {
-		i = (rdp + j) & ring->ptr_mask;
-		seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
-	}
+	if (ring->ready)
+		for (j = 0; j <= count; j++) {
+			i = (rdp + j) & ring->ptr_mask;
+			seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
+		}
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 46a25f0..a890756 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -839,10 +839,11 @@  static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
 	 * packet that is the root issue
 	 */
 	i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
-	for (j = 0; j <= (count + 32); j++) {
-		seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
-		i = (i + 1) & ring->ptr_mask;
-	}
+	if (ring->ready)
+		for (j = 0; j <= (count + 32); j++) {
+			seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
+			i = (i + 1) & ring->ptr_mask;
+		}
 	return 0;
 }