* [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 6:41 ` Dan Carpenter
0 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 6:41 UTC (permalink / raw)
To: Alex Deucher, Eric Huang
Cc: Christian König, David Airlie, Jammy Zhou, Rex Zhu,
Harry Wentland, dri-devel, kernel-janitors
There is no limit on high "idx" can go. It should be less than
ARRAY_SIZE(data.states) which is 16.
The "data" variable wasn't declared in that scope so I shifted the code
around a bit to make it work.
Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 589b36e..ce9e97f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
if (strlen(buf) = 1)
adev->pp_force_state_enabled = false;
- else {
- ret = kstrtol(buf, 0, &idx);
+ else if (adev->pp_enabled) {
+ struct pp_states_info data;
- if (ret) {
+ ret = kstrtol(buf, 0, &idx);
+ if (ret || idx >= ARRAY_SIZE(data.states)) {
count = -EINVAL;
goto fail;
}
- if (adev->pp_enabled) {
- struct pp_states_info data;
- amdgpu_dpm_get_pp_num_states(adev, &data);
- state = data.states[idx];
- /* only set user selected power states */
- if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
- state != POWER_STATE_TYPE_DEFAULT) {
- amdgpu_dpm_dispatch_task(adev,
- AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
- adev->pp_force_state_enabled = true;
- }
+ amdgpu_dpm_get_pp_num_states(adev, &data);
+ state = data.states[idx];
+ /* only set user selected power states */
+ if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+ state != POWER_STATE_TYPE_DEFAULT) {
+ amdgpu_dpm_dispatch_task(adev,
+ AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
+ adev->pp_force_state_enabled = true;
}
}
fail:
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 6:41 ` Dan Carpenter
0 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 6:41 UTC (permalink / raw)
To: Alex Deucher, Eric Huang
Cc: Christian König, David Airlie, Jammy Zhou, Rex Zhu,
Harry Wentland, dri-devel, kernel-janitors
There is no limit on high "idx" can go. It should be less than
ARRAY_SIZE(data.states) which is 16.
The "data" variable wasn't declared in that scope so I shifted the code
around a bit to make it work.
Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 589b36e..ce9e97f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
if (strlen(buf) == 1)
adev->pp_force_state_enabled = false;
- else {
- ret = kstrtol(buf, 0, &idx);
+ else if (adev->pp_enabled) {
+ struct pp_states_info data;
- if (ret) {
+ ret = kstrtol(buf, 0, &idx);
+ if (ret || idx >= ARRAY_SIZE(data.states)) {
count = -EINVAL;
goto fail;
}
- if (adev->pp_enabled) {
- struct pp_states_info data;
- amdgpu_dpm_get_pp_num_states(adev, &data);
- state = data.states[idx];
- /* only set user selected power states */
- if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
- state != POWER_STATE_TYPE_DEFAULT) {
- amdgpu_dpm_dispatch_task(adev,
- AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
- adev->pp_force_state_enabled = true;
- }
+ amdgpu_dpm_get_pp_num_states(adev, &data);
+ state = data.states[idx];
+ /* only set user selected power states */
+ if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+ state != POWER_STATE_TYPE_DEFAULT) {
+ amdgpu_dpm_dispatch_task(adev,
+ AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
+ adev->pp_force_state_enabled = true;
}
}
fail:
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 6:41 ` Dan Carpenter
@ 2016-06-16 7:26 ` walter harms
-1 siblings, 0 replies; 16+ messages in thread
From: walter harms @ 2016-06-16 7:26 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alex Deucher, Eric Huang, Christian König, David Airlie,
Jammy Zhou, Rex Zhu, Harry Wentland, dri-devel, kernel-janitors
Am 16.06.2016 08:41, schrieb Dan Carpenter:
> There is no limit on high "idx" can go. It should be less than
> ARRAY_SIZE(data.states) which is 16.
>
> The "data" variable wasn't declared in that scope so I shifted the code
> around a bit to make it work.
>
> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 589b36e..ce9e97f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
>
> if (strlen(buf) = 1)
> adev->pp_force_state_enabled = false;
> - else {
> - ret = kstrtol(buf, 0, &idx);
> + else if (adev->pp_enabled) {
> + struct pp_states_info data;
>
> - if (ret) {
> + ret = kstrtol(buf, 0, &idx);
> + if (ret || idx >= ARRAY_SIZE(data.states)) {
> count = -EINVAL;
> goto fail;
> }
i would also expect a check idx < 0, does it mean this can not happen ?
otherwise maybe kstrtoul is a solution ?
re,
wh
>
> - if (adev->pp_enabled) {
> - struct pp_states_info data;
> - amdgpu_dpm_get_pp_num_states(adev, &data);
> - state = data.states[idx];
> - /* only set user selected power states */
> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> - state != POWER_STATE_TYPE_DEFAULT) {
> - amdgpu_dpm_dispatch_task(adev,
> - AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> - adev->pp_force_state_enabled = true;
> - }
> + amdgpu_dpm_get_pp_num_states(adev, &data);
> + state = data.states[idx];
> + /* only set user selected power states */
> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> + state != POWER_STATE_TYPE_DEFAULT) {
> + amdgpu_dpm_dispatch_task(adev,
> + AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> + adev->pp_force_state_enabled = true;
> }
> }
> fail:
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 7:26 ` walter harms
0 siblings, 0 replies; 16+ messages in thread
From: walter harms @ 2016-06-16 7:26 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alex Deucher, Eric Huang, Christian König, David Airlie,
Jammy Zhou, Rex Zhu, Harry Wentland, dri-devel, kernel-janitors
Am 16.06.2016 08:41, schrieb Dan Carpenter:
> There is no limit on high "idx" can go. It should be less than
> ARRAY_SIZE(data.states) which is 16.
>
> The "data" variable wasn't declared in that scope so I shifted the code
> around a bit to make it work.
>
> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 589b36e..ce9e97f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
>
> if (strlen(buf) == 1)
> adev->pp_force_state_enabled = false;
> - else {
> - ret = kstrtol(buf, 0, &idx);
> + else if (adev->pp_enabled) {
> + struct pp_states_info data;
>
> - if (ret) {
> + ret = kstrtol(buf, 0, &idx);
> + if (ret || idx >= ARRAY_SIZE(data.states)) {
> count = -EINVAL;
> goto fail;
> }
i would also expect a check idx < 0, does it mean this can not happen ?
otherwise maybe kstrtoul is a solution ?
re,
wh
>
> - if (adev->pp_enabled) {
> - struct pp_states_info data;
> - amdgpu_dpm_get_pp_num_states(adev, &data);
> - state = data.states[idx];
> - /* only set user selected power states */
> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> - state != POWER_STATE_TYPE_DEFAULT) {
> - amdgpu_dpm_dispatch_task(adev,
> - AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> - adev->pp_force_state_enabled = true;
> - }
> + amdgpu_dpm_get_pp_num_states(adev, &data);
> + state = data.states[idx];
> + /* only set user selected power states */
> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> + state != POWER_STATE_TYPE_DEFAULT) {
> + amdgpu_dpm_dispatch_task(adev,
> + AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> + adev->pp_force_state_enabled = true;
> }
> }
> fail:
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 7:26 ` walter harms
@ 2016-06-16 7:54 ` Dan Carpenter
-1 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 7:54 UTC (permalink / raw)
To: walter harms
Cc: Jammy Zhou, kernel-janitors, dri-devel, Eric Huang, Alex Deucher,
Rex Zhu, Christian König
On Thu, Jun 16, 2016 at 09:26:03AM +0200, walter harms wrote:
>
>
> Am 16.06.2016 08:41, schrieb Dan Carpenter:
> > There is no limit on high "idx" can go. It should be less than
> > ARRAY_SIZE(data.states) which is 16.
> >
> > The "data" variable wasn't declared in that scope so I shifted the code
> > around a bit to make it work.
> >
> > Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index 589b36e..ce9e97f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
> >
> > if (strlen(buf) = 1)
> > adev->pp_force_state_enabled = false;
> > - else {
> > - ret = kstrtol(buf, 0, &idx);
> > + else if (adev->pp_enabled) {
> > + struct pp_states_info data;
> >
> > - if (ret) {
> > + ret = kstrtol(buf, 0, &idx);
> > + if (ret || idx >= ARRAY_SIZE(data.states)) {
> > count = -EINVAL;
> > goto fail;
> > }
>
>
> i would also expect a check idx < 0, does it mean this can not happen ?
> otherwise maybe kstrtoul is a solution ?
The original code could underflow, but my code can't. ARRAY_SIZE()
means the comparison is type promoted to size_t which is unsigned long.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 7:54 ` Dan Carpenter
0 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 7:54 UTC (permalink / raw)
To: walter harms
Cc: Jammy Zhou, kernel-janitors, dri-devel, Eric Huang, Alex Deucher,
Rex Zhu, Christian König
On Thu, Jun 16, 2016 at 09:26:03AM +0200, walter harms wrote:
>
>
> Am 16.06.2016 08:41, schrieb Dan Carpenter:
> > There is no limit on high "idx" can go. It should be less than
> > ARRAY_SIZE(data.states) which is 16.
> >
> > The "data" variable wasn't declared in that scope so I shifted the code
> > around a bit to make it work.
> >
> > Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > index 589b36e..ce9e97f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> > @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
> >
> > if (strlen(buf) == 1)
> > adev->pp_force_state_enabled = false;
> > - else {
> > - ret = kstrtol(buf, 0, &idx);
> > + else if (adev->pp_enabled) {
> > + struct pp_states_info data;
> >
> > - if (ret) {
> > + ret = kstrtol(buf, 0, &idx);
> > + if (ret || idx >= ARRAY_SIZE(data.states)) {
> > count = -EINVAL;
> > goto fail;
> > }
>
>
> i would also expect a check idx < 0, does it mean this can not happen ?
> otherwise maybe kstrtoul is a solution ?
The original code could underflow, but my code can't. ARRAY_SIZE()
means the comparison is type promoted to size_t which is unsigned long.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 7:54 ` Dan Carpenter
@ 2016-06-16 7:58 ` Christian König
-1 siblings, 0 replies; 16+ messages in thread
From: Christian König @ 2016-06-16 7:58 UTC (permalink / raw)
To: Dan Carpenter, walter harms
Cc: Alex Deucher, Eric Huang, David Airlie, Jammy Zhou, Rex Zhu,
Harry Wentland, dri-devel, kernel-janitors
Am 16.06.2016 um 09:54 schrieb Dan Carpenter:
> On Thu, Jun 16, 2016 at 09:26:03AM +0200, walter harms wrote:
>>
>> Am 16.06.2016 08:41, schrieb Dan Carpenter:
>>> There is no limit on high "idx" can go. It should be less than
>>> ARRAY_SIZE(data.states) which is 16.
>>>
>>> The "data" variable wasn't declared in that scope so I shifted the code
>>> around a bit to make it work.
>>>
>>> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> index 589b36e..ce9e97f 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
>>>
>>> if (strlen(buf) = 1)
>>> adev->pp_force_state_enabled = false;
>>> - else {
>>> - ret = kstrtol(buf, 0, &idx);
>>> + else if (adev->pp_enabled) {
>>> + struct pp_states_info data;
>>>
>>> - if (ret) {
>>> + ret = kstrtol(buf, 0, &idx);
>>> + if (ret || idx >= ARRAY_SIZE(data.states)) {
>>> count = -EINVAL;
>>> goto fail;
>>> }
>>
>> i would also expect a check idx < 0, does it mean this can not happen ?
>> otherwise maybe kstrtoul is a solution ?
> The original code could underflow, but my code can't. ARRAY_SIZE()
> means the comparison is type promoted to size_t which is unsigned long.
That's probably true, but not very obvious (not that I understand much
of the power related code anyway).
Using kstrtoul() in the first place would make it a bit less obscure and
probably generate a nice error code when somebody really tries to use a
negative index here.
Cheers,
Christian.
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 7:58 ` Christian König
0 siblings, 0 replies; 16+ messages in thread
From: Christian König @ 2016-06-16 7:58 UTC (permalink / raw)
To: Dan Carpenter, walter harms
Cc: Alex Deucher, Eric Huang, David Airlie, Jammy Zhou, Rex Zhu,
Harry Wentland, dri-devel, kernel-janitors
Am 16.06.2016 um 09:54 schrieb Dan Carpenter:
> On Thu, Jun 16, 2016 at 09:26:03AM +0200, walter harms wrote:
>>
>> Am 16.06.2016 08:41, schrieb Dan Carpenter:
>>> There is no limit on high "idx" can go. It should be less than
>>> ARRAY_SIZE(data.states) which is 16.
>>>
>>> The "data" variable wasn't declared in that scope so I shifted the code
>>> around a bit to make it work.
>>>
>>> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> index 589b36e..ce9e97f 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>>> @@ -275,25 +275,23 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
>>>
>>> if (strlen(buf) == 1)
>>> adev->pp_force_state_enabled = false;
>>> - else {
>>> - ret = kstrtol(buf, 0, &idx);
>>> + else if (adev->pp_enabled) {
>>> + struct pp_states_info data;
>>>
>>> - if (ret) {
>>> + ret = kstrtol(buf, 0, &idx);
>>> + if (ret || idx >= ARRAY_SIZE(data.states)) {
>>> count = -EINVAL;
>>> goto fail;
>>> }
>>
>> i would also expect a check idx < 0, does it mean this can not happen ?
>> otherwise maybe kstrtoul is a solution ?
> The original code could underflow, but my code can't. ARRAY_SIZE()
> means the comparison is type promoted to size_t which is unsigned long.
That's probably true, but not very obvious (not that I understand much
of the power related code anyway).
Using kstrtoul() in the first place would make it a bit less obscure and
probably generate a nice error code when somebody really tries to use a
negative index here.
Cheers,
Christian.
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 7:58 ` Christian König
@ 2016-06-16 8:09 ` Dan Carpenter
-1 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 8:09 UTC (permalink / raw)
To: Christian König
Cc: Jammy Zhou, kernel-janitors, dri-devel, Eric Huang, Alex Deucher,
Rex Zhu, walter harms
Sure, I'll resend. Unsigned is a little cleaner. There is no new error
code/message or change in behavior though either way.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 8:09 ` Dan Carpenter
0 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 8:09 UTC (permalink / raw)
To: Christian König
Cc: Jammy Zhou, kernel-janitors, dri-devel, Eric Huang, Alex Deucher,
Rex Zhu, walter harms
Sure, I'll resend. Unsigned is a little cleaner. There is no new error
code/message or change in behavior though either way.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 8:09 ` Dan Carpenter
@ 2016-06-16 8:30 ` Dan Carpenter
-1 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 8:30 UTC (permalink / raw)
To: Alex Deucher
Cc: Jammy Zhou, kernel-janitors, dri-devel, Geliang Tang, Eric Huang,
Rex Zhu, Christian König
There is no limit on high "idx" can go. It should be less than
ARRAY_SIZE(data.states) which is 16.
The "data" variable wasn't declared in that scope so I shifted the code
around a bit to make it work. Also I made "idx" unsigned.
Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: make idx unsigned
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 589b36e..0e13d80 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = ddev->dev_private;
enum amd_pm_state_type state = 0;
- long idx;
+ unsigned long idx;
int ret;
if (strlen(buf) = 1)
adev->pp_force_state_enabled = false;
- else {
- ret = kstrtol(buf, 0, &idx);
+ else if (adev->pp_enabled) {
+ struct pp_states_info data;
- if (ret) {
+ ret = kstrtoul(buf, 0, &idx);
+ if (ret || idx >= ARRAY_SIZE(data.states)) {
count = -EINVAL;
goto fail;
}
- if (adev->pp_enabled) {
- struct pp_states_info data;
- amdgpu_dpm_get_pp_num_states(adev, &data);
- state = data.states[idx];
- /* only set user selected power states */
- if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
- state != POWER_STATE_TYPE_DEFAULT) {
- amdgpu_dpm_dispatch_task(adev,
- AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
- adev->pp_force_state_enabled = true;
- }
+ amdgpu_dpm_get_pp_num_states(adev, &data);
+ state = data.states[idx];
+ /* only set user selected power states */
+ if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+ state != POWER_STATE_TYPE_DEFAULT) {
+ amdgpu_dpm_dispatch_task(adev,
+ AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
+ adev->pp_force_state_enabled = true;
}
}
fail:
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 8:30 ` Dan Carpenter
0 siblings, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2016-06-16 8:30 UTC (permalink / raw)
To: Alex Deucher
Cc: Jammy Zhou, kernel-janitors, dri-devel, Geliang Tang, Eric Huang,
Rex Zhu, Christian König
There is no limit on high "idx" can go. It should be less than
ARRAY_SIZE(data.states) which is 16.
The "data" variable wasn't declared in that scope so I shifted the code
around a bit to make it work. Also I made "idx" unsigned.
Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: make idx unsigned
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 589b36e..0e13d80 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = ddev->dev_private;
enum amd_pm_state_type state = 0;
- long idx;
+ unsigned long idx;
int ret;
if (strlen(buf) == 1)
adev->pp_force_state_enabled = false;
- else {
- ret = kstrtol(buf, 0, &idx);
+ else if (adev->pp_enabled) {
+ struct pp_states_info data;
- if (ret) {
+ ret = kstrtoul(buf, 0, &idx);
+ if (ret || idx >= ARRAY_SIZE(data.states)) {
count = -EINVAL;
goto fail;
}
- if (adev->pp_enabled) {
- struct pp_states_info data;
- amdgpu_dpm_get_pp_num_states(adev, &data);
- state = data.states[idx];
- /* only set user selected power states */
- if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
- state != POWER_STATE_TYPE_DEFAULT) {
- amdgpu_dpm_dispatch_task(adev,
- AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
- adev->pp_force_state_enabled = true;
- }
+ amdgpu_dpm_get_pp_num_states(adev, &data);
+ state = data.states[idx];
+ /* only set user selected power states */
+ if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+ state != POWER_STATE_TYPE_DEFAULT) {
+ amdgpu_dpm_dispatch_task(adev,
+ AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
+ adev->pp_force_state_enabled = true;
}
}
fail:
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 8:30 ` Dan Carpenter
@ 2016-06-16 8:39 ` Christian König
-1 siblings, 0 replies; 16+ messages in thread
From: Christian König @ 2016-06-16 8:39 UTC (permalink / raw)
To: Dan Carpenter, Alex Deucher
Cc: Jammy Zhou, kernel-janitors, dri-devel, Geliang Tang, Eric Huang,
Rex Zhu
Am 16.06.2016 um 10:30 schrieb Dan Carpenter:
> There is no limit on high "idx" can go. It should be less than
> ARRAY_SIZE(data.states) which is 16.
>
> The "data" variable wasn't declared in that scope so I shifted the code
> around a bit to make it work. Also I made "idx" unsigned.
>
> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Christian König <christian.koenig@amd.com>.
> ---
> v2: make idx unsigned
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 589b36e..0e13d80 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
> struct drm_device *ddev = dev_get_drvdata(dev);
> struct amdgpu_device *adev = ddev->dev_private;
> enum amd_pm_state_type state = 0;
> - long idx;
> + unsigned long idx;
> int ret;
>
> if (strlen(buf) = 1)
> adev->pp_force_state_enabled = false;
> - else {
> - ret = kstrtol(buf, 0, &idx);
> + else if (adev->pp_enabled) {
> + struct pp_states_info data;
>
> - if (ret) {
> + ret = kstrtoul(buf, 0, &idx);
> + if (ret || idx >= ARRAY_SIZE(data.states)) {
> count = -EINVAL;
> goto fail;
> }
>
> - if (adev->pp_enabled) {
> - struct pp_states_info data;
> - amdgpu_dpm_get_pp_num_states(adev, &data);
> - state = data.states[idx];
> - /* only set user selected power states */
> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> - state != POWER_STATE_TYPE_DEFAULT) {
> - amdgpu_dpm_dispatch_task(adev,
> - AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> - adev->pp_force_state_enabled = true;
> - }
> + amdgpu_dpm_get_pp_num_states(adev, &data);
> + state = data.states[idx];
> + /* only set user selected power states */
> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> + state != POWER_STATE_TYPE_DEFAULT) {
> + amdgpu_dpm_dispatch_task(adev,
> + AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> + adev->pp_force_state_enabled = true;
> }
> }
> fail:
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-16 8:39 ` Christian König
0 siblings, 0 replies; 16+ messages in thread
From: Christian König @ 2016-06-16 8:39 UTC (permalink / raw)
To: Dan Carpenter, Alex Deucher
Cc: Jammy Zhou, kernel-janitors, dri-devel, Geliang Tang, Eric Huang,
Rex Zhu
Am 16.06.2016 um 10:30 schrieb Dan Carpenter:
> There is no limit on high "idx" can go. It should be less than
> ARRAY_SIZE(data.states) which is 16.
>
> The "data" variable wasn't declared in that scope so I shifted the code
> around a bit to make it work. Also I made "idx" unsigned.
>
> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for powerplay.')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Christian König <christian.koenig@amd.com>.
> ---
> v2: make idx unsigned
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 589b36e..0e13d80 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
> struct drm_device *ddev = dev_get_drvdata(dev);
> struct amdgpu_device *adev = ddev->dev_private;
> enum amd_pm_state_type state = 0;
> - long idx;
> + unsigned long idx;
> int ret;
>
> if (strlen(buf) == 1)
> adev->pp_force_state_enabled = false;
> - else {
> - ret = kstrtol(buf, 0, &idx);
> + else if (adev->pp_enabled) {
> + struct pp_states_info data;
>
> - if (ret) {
> + ret = kstrtoul(buf, 0, &idx);
> + if (ret || idx >= ARRAY_SIZE(data.states)) {
> count = -EINVAL;
> goto fail;
> }
>
> - if (adev->pp_enabled) {
> - struct pp_states_info data;
> - amdgpu_dpm_get_pp_num_states(adev, &data);
> - state = data.states[idx];
> - /* only set user selected power states */
> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> - state != POWER_STATE_TYPE_DEFAULT) {
> - amdgpu_dpm_dispatch_task(adev,
> - AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> - adev->pp_force_state_enabled = true;
> - }
> + amdgpu_dpm_get_pp_num_states(adev, &data);
> + state = data.states[idx];
> + /* only set user selected power states */
> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
> + state != POWER_STATE_TYPE_DEFAULT) {
> + amdgpu_dpm_dispatch_task(adev,
> + AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
> + adev->pp_force_state_enabled = true;
> }
> }
> fail:
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
2016-06-16 8:39 ` Christian König
@ 2016-06-17 16:34 ` Alex Deucher
-1 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2016-06-17 16:34 UTC (permalink / raw)
To: Christian König
Cc: Dan Carpenter, Alex Deucher, Jammy Zhou, kernel-janitors,
Maling list - DRI developers, Geliang Tang, Eric Huang, Rex Zhu
On Thu, Jun 16, 2016 at 4:39 AM, Christian König
<christian.koenig@amd.com> wrote:
> Am 16.06.2016 um 10:30 schrieb Dan Carpenter:
>>
>> There is no limit on high "idx" can go. It should be less than
>> ARRAY_SIZE(data.states) which is 16.
>>
>> The "data" variable wasn't declared in that scope so I shifted the code
>> around a bit to make it work. Also I made "idx" unsigned.
>>
>> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for
>> powerplay.')
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
>
> Acked-by: Christian König <christian.koenig@amd.com>.
>
Applied. thanks!
Alex
>
>> ---
>> v2: make idx unsigned
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> index 589b36e..0e13d80 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> @@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct
>> device *dev,
>> struct drm_device *ddev = dev_get_drvdata(dev);
>> struct amdgpu_device *adev = ddev->dev_private;
>> enum amd_pm_state_type state = 0;
>> - long idx;
>> + unsigned long idx;
>> int ret;
>> if (strlen(buf) = 1)
>> adev->pp_force_state_enabled = false;
>> - else {
>> - ret = kstrtol(buf, 0, &idx);
>> + else if (adev->pp_enabled) {
>> + struct pp_states_info data;
>> - if (ret) {
>> + ret = kstrtoul(buf, 0, &idx);
>> + if (ret || idx >= ARRAY_SIZE(data.states)) {
>> count = -EINVAL;
>> goto fail;
>> }
>> - if (adev->pp_enabled) {
>> - struct pp_states_info data;
>> - amdgpu_dpm_get_pp_num_states(adev, &data);
>> - state = data.states[idx];
>> - /* only set user selected power states */
>> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
>> - state != POWER_STATE_TYPE_DEFAULT) {
>> - amdgpu_dpm_dispatch_task(adev,
>> -
>> AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
>> - adev->pp_force_state_enabled = true;
>> - }
>> + amdgpu_dpm_get_pp_num_states(adev, &data);
>> + state = data.states[idx];
>> + /* only set user selected power states */
>> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
>> + state != POWER_STATE_TYPE_DEFAULT) {
>> + amdgpu_dpm_dispatch_task(adev,
>> + AMD_PP_EVENT_ENABLE_USER_STATE,
>> &state, NULL);
>> + adev->pp_force_state_enabled = true;
>> }
>> }
>> fail:
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [patch v2] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state()
@ 2016-06-17 16:34 ` Alex Deucher
0 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2016-06-17 16:34 UTC (permalink / raw)
To: Christian König
Cc: Dan Carpenter, Alex Deucher, Jammy Zhou, kernel-janitors,
Maling list - DRI developers, Geliang Tang, Eric Huang, Rex Zhu
On Thu, Jun 16, 2016 at 4:39 AM, Christian König
<christian.koenig@amd.com> wrote:
> Am 16.06.2016 um 10:30 schrieb Dan Carpenter:
>>
>> There is no limit on high "idx" can go. It should be less than
>> ARRAY_SIZE(data.states) which is 16.
>>
>> The "data" variable wasn't declared in that scope so I shifted the code
>> around a bit to make it work. Also I made "idx" unsigned.
>>
>> Fixes: f3898ea12fc1 ('drm/amd/powerplay: add some sysfs interfaces for
>> powerplay.')
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
>
> Acked-by: Christian König <christian.koenig@amd.com>.
>
Applied. thanks!
Alex
>
>> ---
>> v2: make idx unsigned
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> index 589b36e..0e13d80 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
>> @@ -270,30 +270,28 @@ static ssize_t amdgpu_set_pp_force_state(struct
>> device *dev,
>> struct drm_device *ddev = dev_get_drvdata(dev);
>> struct amdgpu_device *adev = ddev->dev_private;
>> enum amd_pm_state_type state = 0;
>> - long idx;
>> + unsigned long idx;
>> int ret;
>> if (strlen(buf) == 1)
>> adev->pp_force_state_enabled = false;
>> - else {
>> - ret = kstrtol(buf, 0, &idx);
>> + else if (adev->pp_enabled) {
>> + struct pp_states_info data;
>> - if (ret) {
>> + ret = kstrtoul(buf, 0, &idx);
>> + if (ret || idx >= ARRAY_SIZE(data.states)) {
>> count = -EINVAL;
>> goto fail;
>> }
>> - if (adev->pp_enabled) {
>> - struct pp_states_info data;
>> - amdgpu_dpm_get_pp_num_states(adev, &data);
>> - state = data.states[idx];
>> - /* only set user selected power states */
>> - if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
>> - state != POWER_STATE_TYPE_DEFAULT) {
>> - amdgpu_dpm_dispatch_task(adev,
>> -
>> AMD_PP_EVENT_ENABLE_USER_STATE, &state, NULL);
>> - adev->pp_force_state_enabled = true;
>> - }
>> + amdgpu_dpm_get_pp_num_states(adev, &data);
>> + state = data.states[idx];
>> + /* only set user selected power states */
>> + if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
>> + state != POWER_STATE_TYPE_DEFAULT) {
>> + amdgpu_dpm_dispatch_task(adev,
>> + AMD_PP_EVENT_ENABLE_USER_STATE,
>> &state, NULL);
>> + adev->pp_force_state_enabled = true;
>> }
>> }
>> fail:
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2016-06-17 16:34 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 6:41 [patch] drm/amdgpu: missing bounds check in amdgpu_set_pp_force_state() Dan Carpenter
2016-06-16 6:41 ` Dan Carpenter
2016-06-16 7:26 ` walter harms
2016-06-16 7:26 ` walter harms
2016-06-16 7:54 ` Dan Carpenter
2016-06-16 7:54 ` Dan Carpenter
2016-06-16 7:58 ` Christian König
2016-06-16 7:58 ` Christian König
2016-06-16 8:09 ` Dan Carpenter
2016-06-16 8:09 ` Dan Carpenter
2016-06-16 8:30 ` [patch v2] " Dan Carpenter
2016-06-16 8:30 ` Dan Carpenter
2016-06-16 8:39 ` Christian König
2016-06-16 8:39 ` Christian König
2016-06-17 16:34 ` Alex Deucher
2016-06-17 16:34 ` Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.