Commit 73aa8e1a authored by xinhui pan's avatar xinhui pan Committed by Alex Deucher

drm/amdgpu: Fix some sanity check

ras context might be NULL, so move con->h_data after check !con
also fix sizeof wrong type while at it.
Signed-off-by: default avatarxinhui pan <xinhui.pan@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 6c851417
...@@ -270,7 +270,7 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f, ...@@ -270,7 +270,7 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
data->inject.value = value; data->inject.value = value;
} }
} else { } else {
if (size < sizeof(data)) if (size < sizeof(*data))
return -EINVAL; return -EINVAL;
if (copy_from_user(data, buf, sizeof(*data))) if (copy_from_user(data, buf, sizeof(*data)))
...@@ -1208,14 +1208,15 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev, ...@@ -1208,14 +1208,15 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
unsigned long *bps, int pages) unsigned long *bps, int pages)
{ {
struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
struct ras_err_handler_data *data = con->eh_data; struct ras_err_handler_data *data;
int i = pages; int i = pages;
int ret = 0; int ret = 0;
if (!con || !data || !bps || pages <= 0) if (!con || !con->eh_data || !bps || pages <= 0)
return 0; return 0;
mutex_lock(&con->recovery_lock); mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data) if (!data)
goto out; goto out;
...@@ -1239,15 +1240,18 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev, ...@@ -1239,15 +1240,18 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev) int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
{ {
struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
struct ras_err_handler_data *data = con->eh_data; struct ras_err_handler_data *data;
uint64_t bp; uint64_t bp;
struct amdgpu_bo *bo; struct amdgpu_bo *bo;
int i; int i;
if (!con || !data) if (!con || !con->eh_data)
return 0; return 0;
mutex_lock(&con->recovery_lock); mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data)
goto out;
/* reserve vram at driver post stage. */ /* reserve vram at driver post stage. */
for (i = data->last_reserved; i < data->count; i++) { for (i = data->last_reserved; i < data->count; i++) {
bp = data->bps[i].bp; bp = data->bps[i].bp;
...@@ -1259,6 +1263,7 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev) ...@@ -1259,6 +1263,7 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
data->bps[i].bo = bo; data->bps[i].bo = bo;
data->last_reserved = i + 1; data->last_reserved = i + 1;
} }
out:
mutex_unlock(&con->recovery_lock); mutex_unlock(&con->recovery_lock);
return 0; return 0;
} }
...@@ -1267,14 +1272,18 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev) ...@@ -1267,14 +1272,18 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev) static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
{ {
struct amdgpu_ras *con = amdgpu_ras_get_context(adev); struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
struct ras_err_handler_data *data = con->eh_data; struct ras_err_handler_data *data;
struct amdgpu_bo *bo; struct amdgpu_bo *bo;
int i; int i;
if (!con || !data) if (!con || !con->eh_data)
return 0; return 0;
mutex_lock(&con->recovery_lock); mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data)
goto out;
for (i = data->last_reserved - 1; i >= 0; i--) { for (i = data->last_reserved - 1; i >= 0; i--) {
bo = data->bps[i].bo; bo = data->bps[i].bo;
...@@ -1283,6 +1292,7 @@ static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev) ...@@ -1283,6 +1292,7 @@ static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
data->bps[i].bo = bo; data->bps[i].bo = bo;
data->last_reserved = i; data->last_reserved = i;
} }
out:
mutex_unlock(&con->recovery_lock); mutex_unlock(&con->recovery_lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment