From nobody Mon Sep 28 08:46:39 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E91B3A3E98; Mon, 24 Aug 2026 09:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787562314; cv=none; b=Z+Esti3qj2OwRQRVmCrqpoAuwAg3OYqy/LS/2Tc2mtWa2JfapcDKMep0LH4lyg1FbGtbbTlQXvXNmIwR+UFsaFoj/Y/XGKrsSeylPOXGzWqO+yDvTY9NsTfMkM+jj3ISMHrxe/r/M6da0bu9Xy58Fb5yNzuKvkUGEXw1gpERDUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787562314; c=relaxed/simple; bh=QXXi6VY60XfR6HcVSUWh7dvUR5lb1j2CyE/aZL8rqBA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Qcn4TMMh71VKouTavc7ykYPe9+FXBQFncvnmjwhVBzxzNs1DBeHEVXIeHkBUm/A9Rf+/0Ez+wSPk1LJ1STibcTjRP5l8ym+qEo60RIc4InI5KAYJYtCSdwGCs1d+H/lilY/ExX7HLeLIwhtIwKpBl6FzLVsBbV9VLqKNFsnNm+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: e795010e9f9a11f19a56ed5b684f684d-20260824 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:4b0dc80c-51b4-4b0b-95e6-2555655507c5,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:25 X-CID-META: VersionHash:7db8b62,CLOUDID:01a2156ffd7c7dfc5acc72dd072014e6,BulkI D:nil,BulkQuantity:0,SF:102|136|865|898,TC:nil,Content:0|15|50,EDM:5|-100, IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV: 0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: e795010e9f9a11f19a56ed5b684f684d-20260824 X-User: liupeng01@kylinos.cn Received: from t14 [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1125191586; Mon, 24 Aug 2026 17:05:08 +0800 From: liupeng To: Lyude Paul , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Guenter Roeck , dri-devel@lists.freedesktop.org (open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS), nouveau@lists.freedesktop.org (open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS), linux-kernel@vger.kernel.org (open list), linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING:Keyword:(devm_)?hwmon_device_(un)?register(|_with_groups|_with_info)) Cc: liupeng Subject: [PATCH] drm/nouveau: Fix memory leaks in debugfs and hwmon init error paths Date: Mon, 24 Aug 2026 17:05:04 +0800 Message-ID: <20260824090505.49913-1-liupeng01@kylinos.cn> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In nouveau_debugfs_init(), if nvif_object_ctor() fails, the previously allocated drm->debugfs is leaked because the function returns the error code directly. In nouveau_hwmon_init(), if hwmon_device_register_with_info() fails, the allocated hwmon structure is leaked because the function returns the error code directly. Fix both by freeing the allocated memory and clearing the pointer on the error paths. Signed-off-by: liupeng --- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 15 ++++++++++++--- drivers/gpu/drm/nouveau/nouveau_hwmon.c | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/no= uveau/nouveau_debugfs.c index 47d5579c568d..88223931f382 100644 --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c @@ -295,13 +295,22 @@ nouveau_drm_debugfs_init(struct drm_minor *minor) int nouveau_debugfs_init(struct nouveau_drm *drm) { + int ret; + drm->debugfs =3D kzalloc_obj(*drm->debugfs); if (!drm->debugfs) return -ENOMEM; =20 - return nvif_object_ctor(&drm->client.device.object, "debugfsCtrl", 0, - NVIF_CLASS_CONTROL, NULL, 0, - &drm->debugfs->ctrl); + ret =3D nvif_object_ctor(&drm->client.device.object, "debugfsCtrl", 0, + NVIF_CLASS_CONTROL, NULL, 0, + &drm->debugfs->ctrl); + if (ret) { + kfree(drm->debugfs); + drm->debugfs =3D NULL; + return ret; + } + + return 0; } =20 void diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouv= eau/nouveau_hwmon.c index 726397ab035d..ffbe7f542ab0 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -697,6 +697,8 @@ nouveau_hwmon_init(struct drm_device *dev) if (IS_ERR(hwmon_dev)) { ret =3D PTR_ERR(hwmon_dev); NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret); + drm->hwmon =3D NULL; + kfree(hwmon); return ret; } =20 --=20 2.53.0