Skip to content

Commit

Permalink
drm/amdgpu: Fix some sanity check
Browse files Browse the repository at this point in the history
ras context might be NULL, so move con->h_data after check !con
also fix sizeof wrong type while at it.

Signed-off-by: xinhui pan <xinhui.pan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
xinhui pan authored and Alex Deucher committed Mar 28, 2019
1 parent 6c85141 commit 73aa8e1
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
data->inject.value = value;
}
} else {
if (size < sizeof(data))
if (size < sizeof(*data))
return -EINVAL;

if (copy_from_user(data, buf, sizeof(*data)))
Expand Down Expand Up @@ -1208,14 +1208,15 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
unsigned long *bps, int pages)
{
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 ret = 0;

if (!con || !data || !bps || pages <= 0)
if (!con || !con->eh_data || !bps || pages <= 0)
return 0;

mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data)
goto out;

Expand All @@ -1239,15 +1240,18 @@ int amdgpu_ras_add_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 ras_err_handler_data *data = con->eh_data;
struct ras_err_handler_data *data;
uint64_t bp;
struct amdgpu_bo *bo;
int i;

if (!con || !data)
if (!con || !con->eh_data)
return 0;

mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data)
goto out;
/* reserve vram at driver post stage. */
for (i = data->last_reserved; i < data->count; i++) {
bp = data->bps[i].bp;
Expand All @@ -1259,6 +1263,7 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
data->bps[i].bo = bo;
data->last_reserved = i + 1;
}
out:
mutex_unlock(&con->recovery_lock);
return 0;
}
Expand All @@ -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)
{
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;
int i;

if (!con || !data)
if (!con || !con->eh_data)
return 0;

mutex_lock(&con->recovery_lock);
data = con->eh_data;
if (!data)
goto out;

for (i = data->last_reserved - 1; i >= 0; i--) {
bo = data->bps[i].bo;

Expand All @@ -1283,6 +1292,7 @@ static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
data->bps[i].bo = bo;
data->last_reserved = i;
}
out:
mutex_unlock(&con->recovery_lock);
return 0;
}
Expand Down

0 comments on commit 73aa8e1

Please sign in to comment.