Commit 9eee152a authored by Alex Deucher's avatar Alex Deucher

drm/amdgpu/debugfs: fix ref count leak when pm_runtime_get_sync fails

The call to pm_runtime_get_sync increments the counter even in case of
failure, leading to incorrect ref count.
In case of failure, decrement the ref count before returning.
Acked-by: default avatarEvan Quan <evan.quan@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent dfd84d90
...@@ -223,12 +223,16 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f, ...@@ -223,12 +223,16 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,
*pos &= (1UL << 22) - 1; *pos &= (1UL << 22) - 1;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
if (use_bank) { if (use_bank) {
if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) || if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
...@@ -332,12 +336,16 @@ static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf, ...@@ -332,12 +336,16 @@ static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -387,12 +395,16 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user ...@@ -387,12 +395,16 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -443,12 +455,16 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, ...@@ -443,12 +455,16 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -498,12 +514,16 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user ...@@ -498,12 +514,16 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -554,12 +574,16 @@ static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf, ...@@ -554,12 +574,16 @@ static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -609,12 +633,16 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user * ...@@ -609,12 +633,16 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -764,12 +792,16 @@ static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf, ...@@ -764,12 +792,16 @@ static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
valuesize = sizeof(values); valuesize = sizeof(values);
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize); r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize);
...@@ -842,12 +874,16 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf, ...@@ -842,12 +874,16 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
simd = (*pos & GENMASK_ULL(44, 37)) >> 37; simd = (*pos & GENMASK_ULL(44, 37)) >> 37;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
r = amdgpu_virt_enable_access_debugfs(adev); r = amdgpu_virt_enable_access_debugfs(adev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
/* switch to the specific se/sh/cu */ /* switch to the specific se/sh/cu */
mutex_lock(&adev->grbm_idx_mutex); mutex_lock(&adev->grbm_idx_mutex);
...@@ -981,6 +1017,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf, ...@@ -981,6 +1017,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
return result; return result;
err: err:
pm_runtime_put_autosuspend(adev->ddev->dev);
kfree(data); kfree(data);
return r; return r;
} }
...@@ -1006,8 +1043,10 @@ static ssize_t amdgpu_debugfs_gfxoff_write(struct file *f, const char __user *bu ...@@ -1006,8 +1043,10 @@ static ssize_t amdgpu_debugfs_gfxoff_write(struct file *f, const char __user *bu
return -EINVAL; return -EINVAL;
r = pm_runtime_get_sync(adev->ddev->dev); r = pm_runtime_get_sync(adev->ddev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
while (size) { while (size) {
uint32_t value; uint32_t value;
...@@ -1143,8 +1182,10 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data) ...@@ -1143,8 +1182,10 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
int r = 0, i; int r = 0, i;
r = pm_runtime_get_sync(dev->dev); r = pm_runtime_get_sync(dev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
/* Avoid accidently unparking the sched thread during GPU reset */ /* Avoid accidently unparking the sched thread during GPU reset */
mutex_lock(&adev->lock_reset); mutex_lock(&adev->lock_reset);
...@@ -1200,8 +1241,10 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data) ...@@ -1200,8 +1241,10 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
int r; int r;
r = pm_runtime_get_sync(dev->dev); r = pm_runtime_get_sync(dev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev)); seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
...@@ -1219,8 +1262,10 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data) ...@@ -1219,8 +1262,10 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
int r; int r;
r = pm_runtime_get_sync(dev->dev); r = pm_runtime_get_sync(dev->dev);
if (r < 0) if (r < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return r; return r;
}
seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT)); seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT));
...@@ -1410,16 +1455,16 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val) ...@@ -1410,16 +1455,16 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
return -EINVAL; return -EINVAL;
ret = pm_runtime_get_sync(adev->ddev->dev); ret = pm_runtime_get_sync(adev->ddev->dev);
if (ret < 0) if (ret < 0) {
pm_runtime_put_autosuspend(adev->ddev->dev);
return ret; return ret;
}
if (is_support_sw_smu(adev)) { if (is_support_sw_smu(adev)) {
ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK, &min_freq, &max_freq, true); ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK, &min_freq, &max_freq, true);
if (ret || val > max_freq || val < min_freq) if (ret || val > max_freq || val < min_freq)
return -EINVAL; return -EINVAL;
ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK, (uint32_t)val, (uint32_t)val, true); ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK, (uint32_t)val, (uint32_t)val, true);
} else {
return 0;
} }
pm_runtime_mark_last_busy(adev->ddev->dev); pm_runtime_mark_last_busy(adev->ddev->dev);
......
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