From: Shuicheng Lin <shuicheng.lin@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Shuicheng Lin <shuicheng.lin@intel.com>,
Alexander Usyskin <alexander.usyskin@intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Brian Nguyen <brian3.nguyen@intel.com>
Subject: [PATCH v4 3/3] drm/xe/nvm: Defer xe->nvm assignment until init succeeds
Date: Tue, 20 Jan 2026 18:32:43 +0000 [thread overview]
Message-ID: <20260120183239.2966782-8-shuicheng.lin@intel.com> (raw)
In-Reply-To: <20260120183239.2966782-5-shuicheng.lin@intel.com>
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>
---
drivers/gpu/drm/xe/xe_nvm.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_nvm.c b/drivers/gpu/drm/xe/xe_nvm.c
index 6f9dd519371c..bc88804de514 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);
}
--
2.50.1
next prev parent reply other threads:[~2026-01-20 18:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 18:32 [PATCH v4 0/3] Fix nvm aux resource cleanup Shuicheng Lin
2026-01-20 18:32 ` [PATCH v4 1/3] drm/xe/nvm: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-20 18:32 ` [PATCH v4 2/3] drm/xe/nvm: Fix double-free on aux add failure Shuicheng Lin
2026-01-20 18:32 ` Shuicheng Lin [this message]
2026-01-20 23:41 ` [PATCH v4 3/3] drm/xe/nvm: Defer xe->nvm assignment until init succeeds Nguyen, Brian3
2026-01-21 7:02 ` Usyskin, Alexander
2026-01-21 16:05 ` Lin, Shuicheng
2026-01-20 18:42 ` ✓ CI.KUnit: success for Fix nvm aux resource cleanup Patchwork
2026-01-20 19:23 ` ✓ Xe.CI.BAT: " Patchwork
2026-01-21 1:12 ` ✓ Xe.CI.Full: " Patchwork
2026-01-26 18:48 ` [PATCH v4 0/3] " Lin, Shuicheng
-- strict thread matches above, loose matches on Subject: below --
2026-01-09 22:00 [PATCH] drm/xe: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-20 18:28 ` [PATCH v4 0/3] Fix nvm aux resource cleanup Shuicheng Lin
2026-01-20 18:28 ` [PATCH v4 3/3] drm/xe/nvm: Defer xe->nvm assignment until init succeeds Shuicheng Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260120183239.2966782-8-shuicheng.lin@intel.com \
--to=shuicheng.lin@intel.com \
--cc=alexander.usyskin@intel.com \
--cc=brian3.nguyen@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=rodrigo.vivi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox