Skip to content

Commit

Permalink
drm/amdpgu/debugfs: Simplify some exit paths
Browse files Browse the repository at this point in the history
To avoid code repetition, unify the function exit path when possible. No
functional changes.

Acked-by: Christian König <[email protected]>
Signed-off-by: André Almeida <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
  • Loading branch information
andrealmeid authored and alexdeucher committed Jul 5, 2022
1 parent c3c4833 commit edadd6f
Showing 1 changed file with 42 additions and 65 deletions.
107 changes: 42 additions & 65 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,24 +383,21 @@ static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,

value = RREG32_PCIE(*pos);
r = put_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

result += 4;
buf += 4;
*pos += 4;
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -441,12 +438,8 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user
uint32_t value;

r = get_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

WREG32_PCIE(*pos, value);

Expand All @@ -456,11 +449,12 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -502,24 +496,21 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,

value = RREG32_DIDT(*pos >> 2);
r = put_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

result += 4;
buf += 4;
*pos += 4;
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -560,12 +551,8 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
uint32_t value;

r = get_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

WREG32_DIDT(*pos >> 2, value);

Expand All @@ -575,11 +562,12 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -621,24 +609,21 @@ static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,

value = RREG32_SMC(*pos);
r = put_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

result += 4;
buf += 4;
*pos += 4;
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -679,12 +664,8 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *
uint32_t value;

r = get_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
amdgpu_virt_disable_access_debugfs(adev);
return r;
}
if (r)
goto out;

WREG32_SMC(*pos, value);

Expand All @@ -694,11 +675,12 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

amdgpu_virt_disable_access_debugfs(adev);
return result;
return r;
}

/**
Expand Down Expand Up @@ -1090,11 +1072,8 @@ static ssize_t amdgpu_debugfs_gfxoff_write(struct file *f, const char __user *bu
uint32_t value;

r = get_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
return r;
}
if (r)
goto out;

amdgpu_gfx_off_ctrl(adev, value ? true : false);

Expand All @@ -1104,10 +1083,12 @@ static ssize_t amdgpu_debugfs_gfxoff_write(struct file *f, const char __user *bu
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

return result;
return r;
}


Expand Down Expand Up @@ -1139,29 +1120,25 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct file *f, char __user *buf,
uint32_t value;

r = amdgpu_get_gfx_off_status(adev, &value);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
return r;
}
if (r)
goto out;

r = put_user(value, (uint32_t *)buf);
if (r) {
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
return r;
}
if (r)
goto out;

result += 4;
buf += 4;
*pos += 4;
size -= 4;
}

r = result;
out:
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

return result;
return r;
}

static const struct file_operations amdgpu_debugfs_regs2_fops = {
Expand Down

0 comments on commit edadd6f

Please sign in to comment.