drm/amd/pm: Handle non-terminated overdrive commands.
authorjsg <jsg@openbsd.org>
Thu, 30 Nov 2023 02:44:33 +0000 (02:44 +0000)
committerjsg <jsg@openbsd.org>
Thu, 30 Nov 2023 02:44:33 +0000 (02:44 +0000)
From Bas Nieuwenhuizen
e973f40de16125f3f85a07db68a2ad4a0aeb42c2 in linux-6.1.y/6.1.64
08e9ebc75b5bcfec9d226f9e16bab2ab7b25a39a in mainline linux

sys/dev/pci/drm/amd/pm/amdgpu_pm.c

index 5e27a5a..cb2fa34 100644 (file)
@@ -760,7 +760,7 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
        if (adev->in_suspend && !adev->in_runpm)
                return -EPERM;
 
-       if (count > 127)
+       if (count > 127 || count == 0)
                return -EINVAL;
 
        if (*buf == 's')
@@ -780,7 +780,8 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
        else
                return -EINVAL;
 
-       memcpy(buf_cpy, buf, count+1);
+       memcpy(buf_cpy, buf, count);
+       buf_cpy[count] = 0;
 
        tmp_str = buf_cpy;
 
@@ -797,6 +798,9 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
                        return -EINVAL;
                parameter_size++;
 
+               if (!tmp_str)
+                       break;
+
                while (isspace(*tmp_str))
                        tmp_str++;
        }