]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/nvm: Defer xe->nvm assignment until init succeeds
authorShuicheng Lin <shuicheng.lin@intel.com>
Tue, 20 Jan 2026 18:32:43 +0000 (18:32 +0000)
committerAshutosh Dixit <ashutosh.dixit@intel.com>
Thu, 29 Jan 2026 02:40:08 +0000 (18:40 -0800)
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
drivers/gpu/drm/xe/xe_nvm.c

index 6f9dd519371c9da7ef48eda08a679d1928c92371..bc88804de51463d5b72bdbb6d656716cfd024566 100644 (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);
 }