OSDN Git Service

winsys/amdgpu: avoid potential segfault in amdgpu_bo_map()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 2 Feb 2017 17:40:18 +0000 (18:40 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 8 Feb 2017 14:30:50 +0000 (14:30 +0000)
cs can be NULL when it comes from r600_buffer_map_sync_with_rings()
to avoid doing the same checks. It was checked for write mappings
but not for read mappings.

Cc: "17.0" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
(cherry picked from commit af303abcdbeac3b90fb760de19bed56cc40cfff4)

src/gallium/winsys/amdgpu/drm/amdgpu_bo.c

index e8d2c00..e7ea519 100644 (file)
@@ -253,14 +253,17 @@ static void *amdgpu_bo_map(struct pb_buffer *buf,
              * (neither one is changing it).
              *
              * Only check whether the buffer is being used for write. */
-            if (cs && amdgpu_bo_is_referenced_by_cs_with_usage(cs, bo,
-                                                               RADEON_USAGE_WRITE)) {
-               cs->flush_cs(cs->flush_data, 0, NULL);
-            } else {
-               /* Try to avoid busy-waiting in amdgpu_bo_wait. */
-               if (p_atomic_read(&bo->num_active_ioctls))
-                  amdgpu_cs_sync_flush(rcs);
+            if (cs) {
+               if (amdgpu_bo_is_referenced_by_cs_with_usage(cs, bo,
+                                                            RADEON_USAGE_WRITE)) {
+                  cs->flush_cs(cs->flush_data, 0, NULL);
+               } else {
+                  /* Try to avoid busy-waiting in amdgpu_bo_wait. */
+                  if (p_atomic_read(&bo->num_active_ioctls))
+                     amdgpu_cs_sync_flush(rcs);
+               }
             }
+
             amdgpu_bo_wait((struct pb_buffer*)bo, PIPE_TIMEOUT_INFINITE,
                            RADEON_USAGE_WRITE);
          } else {