+
+ if (ret)
+ return -EFAULT;
But returning here without dropping the lock is certainly incorrect.
+
+ len += strlen(reg_offset);
+ }
+
+ up_read(&adev->reset_sem);
+
+ ret = copy_to_user(buf + len, "\n", 1);
+
+ if (ret)
+ return -EFAULT;
+
+ len++;
+ *pos += len;
+
+ return len;
+}
+
+static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
+ const char __user *buf, size_t size, loff_t *pos)
+{
+ struct amdgpu_device *adev = (struct amdgpu_device
*)file_inode(f)->i_private;
+ char *reg_offset, *reg, reg_temp[11];
+ uint32_t reg_list[128];
+ int ret, i = 0, len = 0;
+
+ do {
+ reg_offset = reg_temp;
+ memset(reg_offset, 0, 11);
+ ret = copy_from_user(reg_offset, buf + len, min(11,
((int)size-len)));
+
+ if (ret)
+ return -EFAULT;
+
+ if (strncmp(reg_offset, "clear", 5) == 0) {
Please completely drop the idea with the clear here, that should be
unnecessary.
+
+ ret = down_read_killable(&adev->reset_sem);
+
+ if (ret)
+ return ret;
+
+ kfree(adev->reset_dump_reg_list);
+ adev->reset_dump_reg_list = NULL;
+ adev->num_regs = 0;
+
+ up_read(&adev->reset_sem);
+
+ return size;
+ }
+
+ reg = strsep(®_offset, " ");
+ ret = kstrtouint(reg, 16, ®_list[i]);
+
+ if (ret)
+ return -EFAULT;
+
+ len += strlen(reg) + 1;
+ i++;
+
+ } while (len < size);
+
+ adev->reset_dump_reg_list =
krealloc_array(adev->reset_dump_reg_list,
+ i, sizeof(uint32_t), GFP_KERNEL);
Well that still doesn't looks like what we need.
Here is once more the roughly what the code should do:
unsigned int i;
uint32_t *tmp;
i = 0;
do {
tmp = krealloc_array(tmp, i, sizeof(uint32_t), GFP_KERNEL);
copy_from_user().....
i++;
} while (len < size);
down_write_killable();
...
swap(adev->reset_dump_reg_list, tmp);
adev->num_regs = i;
up_write();
Regards,
Christian.
+
+ ret = down_read_killable(&adev->reset_sem);
+
+ if (ret)
+ return ret;
+
+ adev->num_regs = i;
+ memcpy(adev->reset_dump_reg_list, reg_list,
+ sizeof(uint32_t) * adev->num_regs);
+
+ up_read(&adev->reset_sem);
+
+ return size;
+}
+
+
+
+static const struct file_operations amdgpu_reset_dump_register_list
= {
+ .owner = THIS_MODULE,
+ .read = amdgpu_reset_dump_register_list_read,
+ .write = amdgpu_reset_dump_register_list_write,
+ .llseek = default_llseek
+};
+
int amdgpu_debugfs_init(struct amdgpu_device *adev)
{
struct dentry *root = adev_to_drm(adev)->primary->debugfs_root;
@@ -1672,6 +1782,8 @@ int amdgpu_debugfs_init(struct amdgpu_device
*adev)
&amdgpu_debugfs_test_ib_fops);
debugfs_create_file("amdgpu_vm_info", 0444, root, adev,
&amdgpu_debugfs_vm_info_fops);
+ debugfs_create_file("amdgpu_reset_dump_register_list", 0644,
root, adev,
+ &amdgpu_reset_dump_register_list);
adev->debugfs_vbios_blob.data = adev->bios;
adev->debugfs_vbios_blob.size = adev->bios_size;