From: Shuicheng Lin Date: Tue, 20 Jan 2026 18:32:43 +0000 (+0000) Subject: drm/xe/nvm: Defer xe->nvm assignment until init succeeds X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7755ed58a49f4c7f603e2b7b9fd5073a70d96406;p=thirdparty%2Flinux.git drm/xe/nvm: Defer xe->nvm assignment until init succeeds Allocate and initialize the NVM structure using a local pointer and assign it to xe->nvm only after all initialization steps succeed. This avoids exposing a partially initialized xe->nvm and removes the need to explicitly clear xe->nvm on error paths, simplifying error handling and making the lifetime rules clearer. Cc: Alexander Usyskin Cc: Rodrigo Vivi Cc: Brian Nguyen Signed-off-by: Shuicheng Lin Reviewed-by: Brian Nguyen Signed-off-by: Ashutosh Dixit Link: https://patch.msgid.link/20260120183239.2966782-8-shuicheng.lin@intel.com --- diff --git a/drivers/gpu/drm/xe/xe_nvm.c b/drivers/gpu/drm/xe/xe_nvm.c index 6f9dd519371c9..bc88804de5146 100644 --- a/drivers/gpu/drm/xe/xe_nvm.c +++ b/drivers/gpu/drm/xe/xe_nvm.c @@ -133,12 +133,10 @@ int xe_nvm_init(struct xe_device *xe) if (WARN_ON(xe->nvm)) return -EFAULT; - xe->nvm = kzalloc(sizeof(*nvm), GFP_KERNEL); - if (!xe->nvm) + nvm = kzalloc(sizeof(*nvm), GFP_KERNEL); + if (!nvm) return -ENOMEM; - nvm = xe->nvm; - nvm->writable_override = xe_nvm_writable_override(xe); nvm->non_posted_erase = xe_nvm_non_posted_erase(xe); nvm->bar.parent = &pdev->resource[0]; @@ -165,7 +163,6 @@ int xe_nvm_init(struct xe_device *xe) if (ret) { drm_err(&xe->drm, "xe-nvm aux init failed %d\n", ret); kfree(nvm); - xe->nvm = NULL; return ret; } @@ -173,8 +170,9 @@ int xe_nvm_init(struct xe_device *xe) if (ret) { drm_err(&xe->drm, "xe-nvm aux add failed %d\n", ret); auxiliary_device_uninit(aux_dev); - xe->nvm = NULL; return ret; } + + xe->nvm = nvm; return devm_add_action_or_reset(xe->drm.dev, xe_nvm_fini, xe); }