drm/amdgpu: Fix kobject cleanup in xcp sysfs
Subsystems (2)
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.
Signed-off-by Lijo Lazar <[email protected]>
--- 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
@@ -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
Quoted 5 lines · Lijo Lazar
Fix the indexing issue. Release the kobject whose init/add failed, and unwind the successfully added ones.
Signed-off-by Lijo Lazar <[email protected]>
Reviewed-by Alex Deucher <[email protected]>
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@@ -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