Skip to contentSkip to conversation

drm/amdgpu: Fix kobject cleanup in xcp sysfs

PATCH In review Lijo Lazar 2 participants 2 messages Jun 17

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix kobject cleanup in xcp sysfs

Fix the indexing issue. Release the kobject whose init/add failed, and unwind the successfully added ones.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +5 -3
index 14cef0264c17..d0d494e00cfe 100644
@@ -904,7 +904,7 @@ static void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_xcp_res_details *xcp_res;
 	struct amdgpu_xcp_cfg *xcp_cfg;
-	int i, r, j, rid, mode;
+	int i, r, rid, mode;
 
 	if (!adev->xcp_mgr)
 		return;
@@ -950,14 +950,16 @@ static void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)
 					 &xcp_cfg_res_sysfs_ktype,
 					 &xcp_cfg->kobj, "%s",
 					 xcp_res_names[rid]);
-		if (r)
+		if (r) {
+			kobject_put(&xcp_res->kobj);
 			goto err;
+		}
 	}
 
 	adev->xcp_mgr->xcp_cfg = xcp_cfg;
 	return;
 err:
-	for (j = 0; j < i; j++) {
+	while (i--) {
 		xcp_res = &xcp_cfg->xcp_res[i];
 		kobject_put(&xcp_res->kobj);
 	}
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lijo Lazar

Fix the indexing issue. Release the kobject whose init/add failed, and unwind the successfully added ones.

Quoted 39 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +5 -4
index 14cef0264c17..d0d494e00cfe 100644
@@ -904,7 +904,7 @@ static void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)
 {
        struct amdgpu_xcp_res_details *xcp_res;
        struct amdgpu_xcp_cfg *xcp_cfg;
-       int i, r, j, rid, mode;
+       int i, r, rid, mode;
 
        if (!adev->xcp_mgr)
                return;
@@ -950,14 +950,16 @@ static void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)
                                         &xcp_cfg_res_sysfs_ktype,
                                         &xcp_cfg->kobj, "%s",
                                         xcp_res_names[rid]);
-               if (r)
+               if (r) {
+                       kobject_put(&xcp_res->kobj);
                        goto err;
+               }
        }
 
        adev->xcp_mgr->xcp_cfg = xcp_cfg;
        return;
 err:
-       for (j = 0; j < i; j++) {
+       while (i--) {
                xcp_res = &xcp_cfg->xcp_res[i];
                kobject_put(&xcp_res->kobj);
        }
--

2.49.0