uint32_t phy_id;
uint32_t op;
char str[64];
- int ret;
+ long len;
+ ssize_t write_ret = size;
+ int ret, nargs;
- if (*pos || size > sizeof(str) - 1)
+ if (*pos)
return -EINVAL;
- memset(str, 0, sizeof(str));
- ret = copy_from_user(str, buf, size);
- if (ret)
+ len = strncpy_from_user(str, buf, sizeof(str));
+ if (len < 0)
return -EFAULT;
+ if (len == 0 || len >= sizeof(str))
+ return -EINVAL;
ret = pm_runtime_get_sync(dev->dev);
if (ret < 0) {
return ret;
}
- if (size < 3)
- sscanf(str, "%u ", &op);
+ if (len < 3)
+ nargs = sscanf(str, "%u", &op);
else
- sscanf(str, "%u %u", &op, &phy_id);
+ nargs = sscanf(str, "%u %u", &op, &phy_id);
+ if (nargs < 1) {
+ write_ret = -EINVAL;
+ goto out;
+ }
switch (op) {
case 1:
mutex_unlock(&psp->securedisplay_context.mutex);
break;
case 2:
- if (size < 3 || phy_id >= TA_SECUREDISPLAY_MAX_PHY) {
+ if (nargs < 2 || phy_id >= TA_SECUREDISPLAY_MAX_PHY) {
dev_err(adev->dev, "Invalid input: %s\n", str);
- return -EINVAL;
+ write_ret = -EINVAL;
+ break;
}
mutex_lock(&psp->securedisplay_context.mutex);
psp_prep_securedisplay_cmd_buf(psp, &securedisplay_cmd,
break;
default:
dev_err(adev->dev, "Invalid input: %s\n", str);
+ write_ret = -EINVAL;
+ break;
}
+out:
pm_runtime_put_autosuspend(dev->dev);
- return size;
+ return write_ret;
}
static const struct file_operations amdgpu_securedisplay_debugfs_ops = {