From nobody Wed Apr 8 01:51:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62939C43219 for ; Fri, 21 Oct 2022 02:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiJUCXF (ORCPT ); Thu, 20 Oct 2022 22:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiJUCWu (ORCPT ); Thu, 20 Oct 2022 22:22:50 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA5512248E8 for ; Thu, 20 Oct 2022 19:22:48 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCK4pJ1zHvCk; Fri, 21 Oct 2022 10:22:37 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:46 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:45 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 10/11] drm/amdgpu/discovery: fix possible memory leak Date: Fri, 21 Oct 2022 10:21:01 +0800 Message-ID: <20221021022102.2231464-11-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If kset_register() fails, the refcount of kobject is not 0, the name allocated in kobject_set_name(&kset.kobj, ...) is leaked. Fix this by calling kset_put(), so that it will be freed in callback function kobject_cleanup(). Cc: stable@vger.kernel.org Fixes: a6c40b178092 ("drm/amdgpu: Show IP discovery in sysfs") Signed-off-by: Yang Yingliang Reviewed-by: Luben Tuikov --- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/dr= m/amd/amdgpu/amdgpu_discovery.c index 3993e6134914..638edcf70227 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c @@ -863,7 +863,7 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_dev= ice *adev, res =3D kset_register(&ip_hw_id->hw_id_kset); if (res) { DRM_ERROR("Couldn't register ip_hw_id kset"); - kfree(ip_hw_id); + kset_put(&ip_hw_id->hw_id_kset); return res; } if (hw_id_names[ii]) { @@ -954,7 +954,7 @@ static int amdgpu_discovery_sysfs_recurse(struct amdgpu= _device *adev) res =3D kset_register(&ip_die_entry->ip_kset); if (res) { DRM_ERROR("Couldn't register ip_die_entry kset"); - kfree(ip_die_entry); + kset_put(&ip_die_entry->ip_kset); return res; } =20 @@ -989,6 +989,7 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_de= vice *adev) res =3D kset_register(&adev->ip_top->die_kset); if (res) { DRM_ERROR("Couldn't register die_kset"); + kset_put(&adev->ip_top->die_kset); goto Err; } =20 --=20 2.25.1