drm/amdgpu: Guard against write accesses after device removal
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_vce.c
index ea6a62f..8332034 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/module.h>
 
 #include <drm/drm.h>
+#include <drm/drm_drv.h>
 
 #include "amdgpu.h"
 #include "amdgpu_pm.h"
@@ -293,7 +294,7 @@ int amdgpu_vce_resume(struct amdgpu_device *adev)
        void *cpu_addr;
        const struct common_firmware_header *hdr;
        unsigned offset;
-       int r;
+       int r, idx;
 
        if (adev->vce.vcpu_bo == NULL)
                return -EINVAL;
@@ -313,8 +314,12 @@ int amdgpu_vce_resume(struct amdgpu_device *adev)
 
        hdr = (const struct common_firmware_header *)adev->vce.fw->data;
        offset = le32_to_cpu(hdr->ucode_array_offset_bytes);
-       memcpy_toio(cpu_addr, adev->vce.fw->data + offset,
-                   adev->vce.fw->size - offset);
+
+       if (drm_dev_enter(&adev->ddev, &idx)) {
+               memcpy_toio(cpu_addr, adev->vce.fw->data + offset,
+                           adev->vce.fw->size - offset);
+               drm_dev_exit(idx);
+       }
 
        amdgpu_bo_kunmap(adev->vce.vcpu_bo);