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 <alexander.usyskin@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Brian Nguyen <brian3.nguyen@intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
Reviewed-by: Brian Nguyen <brian3.nguyen@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Link: https://patch.msgid.link/20260120183239.2966782-8-shuicheng.lin@intel.com
This commit is contained in:
Shuicheng Lin 2026-01-20 18:32:43 +00:00 committed by Ashutosh Dixit
parent a3187c0c2b
commit 7755ed58a4

View File

@ -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);
}