Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
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:28:19 +0000	[thread overview]
Message-ID: <20260120182815.2966078-8-shuicheng.lin@intel.com> (raw)
In-Reply-To: <20260120182815.2966078-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


  parent reply	other threads:[~2026-01-20 18:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 22:00 [PATCH] drm/xe: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-09 22:14 ` ✓ CI.KUnit: success for " Patchwork
2026-01-09 22:51 ` ✓ Xe.CI.BAT: " Patchwork
2026-01-10  3:27 ` ✓ Xe.CI.Full: " Patchwork
2026-01-13 16:11 ` [PATCH] " Lin, Shuicheng
2026-01-15 11:30 ` Usyskin, Alexander
2026-01-16 18:05 ` Nguyen, Brian3
2026-01-16 18:44   ` Lin, Shuicheng
2026-01-16 21:40 ` [PATCH 0/2] Fix nvm aux resource cleanup Shuicheng Lin
2026-01-16 21:40   ` [PATCH v2 1/2] drm/xe/nvm: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-16 21:40   ` [PATCH 2/2] drm/xe/nvm: Fix double-free on aux add failure Shuicheng Lin
2026-01-17  0:00     ` Nguyen, Brian3
2026-01-18  7:03     ` Usyskin, Alexander
2026-01-20 17:42       ` Lin, Shuicheng
2026-01-19  5:15     ` Gote, Nitin R
2026-01-16 21:51 ` ✓ CI.KUnit: success for drm/xe: Manage nvm aux cleanup with devres (rev2) Patchwork
2026-01-16 22:26 ` ✓ Xe.CI.BAT: " Patchwork
2026-01-16 23:45 ` ✓ Xe.CI.Full: " Patchwork
2026-01-20 17:59 ` [PATCH v3 0/3] Fix nvm aux resource cleanup Shuicheng Lin
2026-01-20 17:59   ` [PATCH v3 1/3] drm/xe/nvm: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-20 17:59   ` [PATCH v3 2/3] drm/xe/nvm: Fix double-free on aux add failure Shuicheng Lin
2026-01-20 17:59   ` [PATCH v3 3/3] drm/xe/nvm: Defer xe->nvm assignment until init succeeds 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 1/3] drm/xe/nvm: Manage nvm aux cleanup with devres Shuicheng Lin
2026-01-20 18:28   ` [PATCH v4 2/3] drm/xe/nvm: Fix double-free on aux add failure Shuicheng Lin
2026-01-20 18:28   ` Shuicheng Lin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-01-20 18:32 [PATCH v4 0/3] Fix nvm aux resource cleanup Shuicheng Lin
2026-01-20 18:32 ` [PATCH v4 3/3] drm/xe/nvm: Defer xe->nvm assignment until init succeeds Shuicheng Lin
2026-01-20 23:41   ` Nguyen, Brian3
2026-01-21  7:02   ` Usyskin, Alexander
2026-01-21 16:05     ` Lin, Shuicheng

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=20260120182815.2966078-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