From mboxrd@z Thu Jan 1 00:00:00 1970 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 38034383994; Sat, 10 Oct 2026 02:20:19 +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=1791598824; cv=none; b=C29XrzNdVyMLrXXwcSG92Abshza/qrpqp8LIkBy3ymKm6xL3WTw3A0WW4oYncgLMehroWvPCUkR285vsLOiklqSttw/dcNDTqIZYHdyuyXDzJ6ilOK+7cR4JrOkXB5Rw6epM+npzlgWEg6vBWY/aDFhPEa9SE+6xvVYzAf1DWIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791598824; c=relaxed/simple; bh=2089kwbaZq9M8O6Guv+ssDUQsuKV9uHzJWo2WqeMgO0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAfWU+oANOAywyjoiwNjS4CrjwW114L04Sosb5A9hVJXwAQx1y9krjNHj1WBNpAqnAtbC0noxUGM5DXSVMJu3hatm+iwfOogydS4e8cH4tQTo3qjgGyUy3oZ6yEVvAP+swp7GH8l0kdmVjXjFIq4vCrIrkVQZr8KvlUjC4ksZPU= 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: 1f7bef4ec45111f19a56ed5b684f684d-20261010 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:ecee74a2-1e55-4a6b-b0a6-44bafed3e660,IP:0,U RL:0,TC:0,Content:-5,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:20 X-CID-META: VersionHash:7db8b62,CLOUDID:18ca962c9afe14172961c7209937d7a0,BulkI D:nil,BulkQuantity:0,SF:81|82|102|136|865|898,TC:nil,Content:0|15|50|99,ED M: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: 1f7bef4ec45111f19a56ed5b684f684d-20261010 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 954129788; Sat, 10 Oct 2026 10:20:12 +0800 From: liupeng To: lyude@redhat.com, dakr@kernel.org Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, linux@roeck-us.net, nouveau@karolherbst.de, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, stable@vger.kernel.org, liupeng Subject: [PATCH v4 2/2] drm/nouveau: Fix memory leak in hwmon init error path Date: Sat, 10 Oct 2026 10:20:06 +0800 Message-ID: <20261010022006.28263-2-liupeng01@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261010022006.28263-1-liupeng01@kylinos.cn> References: <20261010022006.28263-1-liupeng01@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 this by freeing the allocated memory and clearing the pointer on the error path. Fixes: b9ed919f1c8f ("drm/nouveau/drm/pm: remove everything except the hwmon interfaces to THERM") Cc: stable@vger.kernel.org Reviewed-by: Lyude Paul Signed-off-by: liupeng --- Changes in v4: - Split the debugfs and hwmon fixes into two separate patches as requested by Danilo, since they are unrelated fixes with different Fixes: tags. No functional change to this fix. drivers/gpu/drm/nouveau/nouveau_hwmon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/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 = PTR_ERR(hwmon_dev); NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret); + drm->hwmon = NULL; + kfree(hwmon); return ret; } -- 2.53.0