[PATCH] drm/amd/pm: fix variable dereferenced issue in amdgpu_device_attr_create()

Feng, Kenneth Kenneth.Feng at amd.com
Tue Aug 1 14:07:55 UTC 2023


[AMD Official Use Only - General]

Reviewed-by: Kenneth Feng <kenneth.feng at amd.com>


-----Original Message-----
From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Yang Wang
Sent: Tuesday, August 1, 2023 5:16 PM
To: amd-gfx at lists.freedesktop.org
Cc: Dan Carpenter <dan.carpenter at linaro.org>; Wang, Yang(Kevin) <KevinYang.Wang at amd.com>
Subject: [PATCH] drm/amd/pm: fix variable dereferenced issue in amdgpu_device_attr_create()

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


- fix variable ('attr') dereferenced issue.
- using condition check instead of BUG_ON().

Fixes: 4e01847c38f7 ("drm/amdgpu: optimize amdgpu device attribute code")

Cc: Dan Carpenter <dan.carpenter at linaro.org>
Signed-off-by: Yang Wang <kevinyang.wang at amd.com>
---
 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index 3922dd274f30..383b2b778456 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -2171,15 +2171,19 @@ static int amdgpu_device_attr_create(struct amdgpu_device *adev,
                                     uint32_t mask, struct list_head *attr_list)  {
        int ret = 0;
-       struct device_attribute *dev_attr = &attr->dev_attr;
-       const char *name = dev_attr->attr.name;
        enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
        struct amdgpu_device_attr_entry *attr_entry;
+       struct device_attribute *dev_attr;
+       const char *name;

        int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
                           uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;

-       BUG_ON(!attr);
+       if (!attr)
+               return -EINVAL;
+
+       dev_attr = &attr->dev_attr;
+       name = dev_attr->attr.name;

        attr_update = attr->attr_update ? attr->attr_update : default_attr_update;

--
2.34.1



More information about the amd-gfx mailing list