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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4D37C5516E for ; Thu, 30 Jul 2026 20:30:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 78EEB10F095; Thu, 30 Jul 2026 20:30:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="eRsGqGEt"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE5C210F08B for ; Thu, 30 Jul 2026 20:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785443441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2gwla5Iow9keC3LIa++F5i/nMXpP28FwdNmiA+kgV98=; b=eRsGqGEt+9povWSVdahF2x+5iEJwAnMDHmwwsR61xlNG66mQ0iVp3eR0yCk9ogH6GNzk9K o4ia3upB+/CyyBifdRlIBDRiyFcO9gO+UCSwG1UTYD1cskB5kHezo7W2BeUJ/U0HLimSVe Jd1495DHetsOv8hMknHIU8Vn3jmNeuo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-S2GJUaIoOX2fLRtAZz4V9w-1; Thu, 30 Jul 2026 16:30:35 -0400 X-MC-Unique: S2GJUaIoOX2fLRtAZz4V9w-1 X-Mimecast-MFC-AGG-ID: S2GJUaIoOX2fLRtAZz4V9w_1785443434 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1D94D180035C; Thu, 30 Jul 2026 20:30:34 +0000 (UTC) Received: from GoldenWind.lan (unknown [10.22.88.35]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B24CA423; Thu, 30 Jul 2026 20:30:32 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: "Maarten Lankhorst" , "Simona Vetter" , "David Airlie" , "Thomas Zimmermann" , "Maxime Ripard" , "Danilo Krummrich" , "Lyude Paul" Subject: [PATCH v3 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new() Date: Thu, 30 Jul 2026 16:28:04 -0400 Message-ID: <20260730203015.1572240-2-lyude@redhat.com> In-Reply-To: <20260730203015.1572240-1-lyude@redhat.com> References: <20260730203015.1572240-1-lyude@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-MFC-PROC-ID: K0q4EzvocKxbZWr1ifNVsMIQtHWpv7wkXNzhaXD6IB4_1785443434 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Sashiko caught this while reviewing the patches for enabling atomic by default - if we fail to allocate the DRM device pointer, we'll attempt to free the error pointer that it returns rather than the actual struct. Let's fix this while we're at it. Signed-off-by: Lyude Paul --- V3: * Don't use devm, that will just break during unbind (Sashiko). drivers/gpu/drm/nouveau/nouveau_drm.c | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index 4d1ad718e09b7..3dfe21cd4bde4 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -749,7 +749,7 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren drm->dev = drm_dev_alloc(drm_driver, parent); if (IS_ERR(drm->dev)) { ret = PTR_ERR(drm->dev); - goto done; + goto err_free_drm; } drm->dev->dev_private = drm; @@ -762,39 +762,43 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, "drm", nouveau_name(drm->dev), &drm->_client); if (ret) - goto done; + goto err_device_del; ret = nvif_device_ctor(&drm->_client, "drmDevice", &drm->device); if (ret) { NV_ERROR(drm, "Device allocation failed: %d\n", ret); - goto done; + goto err_device_del; } ret = nvif_device_map(&drm->device); if (ret) { NV_ERROR(drm, "Failed to map PRI: %d\n", ret); - goto done; + goto err_device_del; } ret = nvif_mclass(&drm->device.object, mmus); if (ret < 0) { NV_ERROR(drm, "No supported MMU class\n"); - goto done; + goto err_device_del; } ret = nvif_mmu_ctor(&drm->device.object, "drmMmu", mmus[ret].oclass, &drm->mmu); if (ret) { NV_ERROR(drm, "MMU allocation failed: %d\n", ret); - goto done; + goto err_device_del; } -done: - if (ret) { - nouveau_drm_device_del(drm); - drm = NULL; - } + return 0; + +err_free_drm: + kfree(drm); + + return ERR_PTR(ret); + +err_device_del: + nouveau_drm_device_del(drm); - return ret ? ERR_PTR(ret) : drm; + return ERR_PTR(ret); } /* -- 2.55.0