From: Lyude Paul <lyude@redhat.com>
To: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Simona Vetter <simona@ffwll.ch>,
Maxime Ripard <mripard@kernel.org>,
Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH v4 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new()
Date: Thu, 30 Jul 2026 16:36:09 -0400 [thread overview]
Message-ID: <20260730203723.1649433-2-lyude@redhat.com> (raw)
In-Reply-To: <20260730203723.1649433-1-lyude@redhat.com>
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 <lyude@redhat.com>
---
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
WARNING: multiple messages have this Message-ID (diff)
From: Lyude Paul <lyude@redhat.com>
To: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Simona Vetter" <simona@ffwll.ch>,
"David Airlie" <airlied@gmail.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Maxime Ripard" <mripard@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Lyude Paul" <lyude@redhat.com>
Subject: [PATCH v4 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new()
Date: Thu, 30 Jul 2026 16:36:09 -0400 [thread overview]
Message-ID: <20260730203723.1649433-2-lyude@redhat.com> (raw)
In-Reply-To: <20260730203723.1649433-1-lyude@redhat.com>
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 <lyude@redhat.com>
---
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
next prev parent reply other threads:[~2026-07-30 20:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 20:36 [PATCH v4 0/5] Enable atomic modesetting by default Lyude Paul
2026-07-30 20:36 ` Lyude Paul
2026-07-30 20:36 ` Lyude Paul [this message]
2026-07-30 20:36 ` [PATCH v4 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new() Lyude Paul
2026-07-30 20:45 ` sashiko-bot
2026-07-30 20:36 ` [PATCH v4 2/5] drm/nouveau: Print the nouveau.atomic parameter in nouveau_display_options() Lyude Paul
2026-07-30 20:36 ` Lyude Paul
2026-07-30 20:36 ` [PATCH v4 3/5] drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling Lyude Paul
2026-07-30 20:36 ` Lyude Paul
2026-07-30 20:54 ` sashiko-bot
2026-07-30 20:36 ` [PATCH v4 4/5] drm/nouveau/kms: Only allow enabling atomic modesetting on nv50+ Lyude Paul
2026-07-30 20:36 ` Lyude Paul
2026-07-30 20:36 ` [PATCH v4 5/5] drm/nouveau/kms/nv50-: Enable atomic modesetting by default Lyude Paul
2026-07-30 20:36 ` Lyude Paul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260730203723.1649433-2-lyude@redhat.com \
--to=lyude@redhat.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.