[PATCH v2 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new()
From: Lyude Paul
Date: Thu Jul 30 2026 - 15:56:17 EST
Sashiko caught this while reviewing the patches for enabling atomic by
default. Trying to fix this properly would be a bit of a pain, and we're
going to be adding another pre-DRM allocation here anyway. So, let's
instead just convert the initial struct nouveau_drm allocation over to
using devm so it is freed automatically.
Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
---
drivers/gpu/drm/nouveau/nouveau_drm.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 4d1ad718e09b7..9570850656126 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -723,7 +723,6 @@ nouveau_drm_device_del(struct nouveau_drm *drm)
nvif_parent_dtor(&drm->parent);
mutex_destroy(&drm->client_mutex);
- kfree(drm);
}
static struct nouveau_drm *
@@ -740,17 +739,15 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
struct nouveau_drm *drm;
int ret;
- drm = kzalloc_obj(*drm);
+ drm = devm_kzalloc(parent, sizeof(*drm), GFP_KERNEL);
if (!drm)
return ERR_PTR(-ENOMEM);
drm->nvkm = device;
drm->dev = drm_dev_alloc(drm_driver, parent);
- if (IS_ERR(drm->dev)) {
- ret = PTR_ERR(drm->dev);
- goto done;
- }
+ if (IS_ERR(drm->dev))
+ return ERR_CAST(drm->dev);
drm->dev->dev_private = drm;
dev_set_drvdata(parent, drm);
--
2.55.0