Commit 7755ed58 authored by Shuicheng Lin's avatar Shuicheng Lin Committed by Ashutosh Dixit
Browse files

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: default avatarShuicheng Lin <shuicheng.lin@intel.com>
Reviewed-by: default avatarBrian Nguyen <brian3.nguyen@intel.com>
Signed-off-by: default avatarAshutosh Dixit <ashutosh.dixit@intel.com>
Link: https://patch.msgid.link/20260120183239.2966782-8-shuicheng.lin@intel.com
parent a3187c0c
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -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);
}