From: "Tauro, Riana" <riana.tauro@intel.com>
To: "Lin, Shuicheng" <shuicheng.lin@intel.com>,
"Jadav, Raag" <raag.jadav@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH 1/2] drm/xe/ras: Fix error handling in register_nodes()
Date: Tue, 14 Apr 2026 10:00:13 +0530 [thread overview]
Message-ID: <cbcfe35d-6796-410d-921d-0d4d9b3564a0@intel.com> (raw)
In-Reply-To: <DM4PR11MB5456648D71E87DC8D522DFE4EA252@DM4PR11MB5456.namprd11.prod.outlook.com>
On 4/14/2026 6:00 AM, Lin, Shuicheng wrote:
> On Sat, Apr 11, 2026 12:56 AM Raag Jadav wrote:
>> On Tue, Apr 07, 2026 at 10:59:12PM +0000, Shuicheng Lin wrote:
>>> Fix two issues in register_nodes():
>>>
>>> 1. When the loop fails mid-way, previously registered nodes are not
>>> cleaned up. Add goto-based error unwinding that walks backwards
>>> through completed iterations.
>> Did you check with the author if this is expected behaviour?
> Author is in the Cc list.
>
>>> 2. When allocate_and_copy_counters() fails, assign_node_params()
>>> leaves ras->info[severity] as an ERR_PTR and returns. The caller
>>> then passes that ERR_PTR to kfree() via cleanup_node_param(),
>>> causing an invalid free. Fix by making assign_node_params()
>>> self-contained on error: NULL out the stale ERR_PTR and free
>>> device_name before returning.
>> Can this be rather fixed using a local pointer?
> Yes, a local pointer could make the code simpler.
> As author will have new series, I would leave author to refine it.
> Thanks.
>
I did not mean that. I meant all the small cosmetic changes (Patch 2 in
the series) can be part of any
bigger change.
Thanks
Riana
>
> Shuicheng
>
>> Raag
>>
>>> Fixes: b40db12b542f ("drm/xe/xe_drm_ras: Add support for XE DRM RAS")
>>> Cc: Riana Tauro <riana.tauro@intel.com>
>>> Assisted-by: Claude:claude-opus-4.6
>>> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
>>> ---
>>> drivers/gpu/drm/xe/xe_drm_ras.c | 31 ++++++++++++++++++++++--------
>> -
>>> 1 file changed, 22 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/xe/xe_drm_ras.c
>>> b/drivers/gpu/drm/xe/xe_drm_ras.c index e07dc23a155e..802e4bcb731c
>>> 100644
>>> --- a/drivers/gpu/drm/xe/xe_drm_ras.c
>>> +++ b/drivers/gpu/drm/xe/xe_drm_ras.c
>>> @@ -73,6 +73,7 @@ static int assign_node_params(struct xe_device *xe,
>> struct drm_ras_node *node,
>>> struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
>>> struct xe_drm_ras *ras = &xe->ras;
>>> const char *device_name;
>>> + int ret;
>>>
>>> device_name = kasprintf(GFP_KERNEL, "%04x:%02x:%02x.%d",
>>> pci_domain_nr(pdev->bus), pdev->bus-
>>> number, @@ -89,8 +90,11 @@
>>> static int assign_node_params(struct xe_device *xe, struct drm_ras_node
>> *node,
>>> node->priv = xe;
>>>
>>> ras->info[severity] = allocate_and_copy_counters(xe);
>>> - if (IS_ERR(ras->info[severity]))
>>> - return PTR_ERR(ras->info[severity]);
>>> + if (IS_ERR(ras->info[severity])) {
>>> + ret = PTR_ERR(ras->info[severity]);
>>> + ras->info[severity] = NULL;
>>> + goto err_free_name;
>>> + }
>>>
>>> if (severity == DRM_XE_RAS_ERR_SEV_CORRECTABLE)
>>> node->query_error_counter =
>> query_correctable_error_counter; @@
>>> -98,6 +102,11 @@ static int assign_node_params(struct xe_device *xe,
>> struct drm_ras_node *node,
>>> node->query_error_counter =
>> query_uncorrectable_error_counter;
>>> return 0;
>>> +
>>> +err_free_name:
>>> + kfree(device_name);
>>> + node->device_name = NULL;
>>> + return ret;
>>> }
>>>
>>> static void cleanup_node_param(struct xe_drm_ras *ras, const enum
>>> drm_xe_ras_error_severity severity) @@ -114,26 +123,30 @@ static void
>>> cleanup_node_param(struct xe_drm_ras *ras, const enum drm_xe_ras_err
>>> static int register_nodes(struct xe_device *xe) {
>>> struct xe_drm_ras *ras = &xe->ras;
>>> - int i;
>>> + int i, ret;
>>>
>>> for_each_error_severity(i) {
>>> struct drm_ras_node *node = &ras->node[i];
>>> - int ret;
>>>
>>> ret = assign_node_params(xe, node, i);
>>> - if (ret) {
>>> - cleanup_node_param(ras, i);
>>> - return ret;
>>> - }
>>> + if (ret)
>>> + goto err_unwind;
>>>
>>> ret = drm_ras_node_register(node);
>>> if (ret) {
>>> cleanup_node_param(ras, i);
>>> - return ret;
>>> + goto err_unwind;
>>> }
>>> }
>>>
>>> return 0;
>>> +
>>> +err_unwind:
>>> + while (i--) {
>>> + drm_ras_node_unregister(&ras->node[i]);
>>> + cleanup_node_param(ras, i);
>>> + }
>>> + return ret;
>>> }
>>>
>>> static void xe_drm_ras_unregister_nodes(struct drm_device *device,
>>> void *arg)
>>> --
>>> 2.43.0
>>>
next prev parent reply other threads:[~2026-04-14 4:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 22:59 [PATCH 0/2] drm/xe/ras: Fix and clean up xe_drm_ras Shuicheng Lin
2026-04-07 22:59 ` [PATCH 1/2] drm/xe/ras: Fix error handling in register_nodes() Shuicheng Lin
2026-04-11 4:46 ` Nguyen, Brian3
2026-04-13 4:39 ` Tauro, Riana
2026-04-14 0:15 ` Lin, Shuicheng
2026-04-14 4:27 ` Tauro, Riana
2026-04-11 7:56 ` Raag Jadav
2026-04-14 0:30 ` Lin, Shuicheng
2026-04-14 4:30 ` Tauro, Riana [this message]
2026-04-07 22:59 ` [PATCH 2/2] drm/xe/ras: Clean up coding style in xe_drm_ras Shuicheng Lin
2026-04-11 4:54 ` Nguyen, Brian3
2026-04-13 4:46 ` Tauro, Riana
2026-04-14 0:27 ` Lin, Shuicheng
2026-04-14 4:33 ` Tauro, Riana
2026-04-11 7:58 ` Raag Jadav
2026-04-07 23:09 ` ✗ CI.checkpatch: warning for drm/xe/ras: Fix and clean up xe_drm_ras Patchwork
2026-04-07 23:10 ` ✗ CI.KUnit: failure " Patchwork
2026-04-10 3:55 ` ✗ CI.checkpatch: warning for drm/xe/ras: Fix and clean up xe_drm_ras (rev2) Patchwork
2026-04-10 3:56 ` ✓ CI.KUnit: success " Patchwork
2026-04-10 4:32 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-10 10:41 ` ✗ Xe.CI.FULL: failure " Patchwork
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=cbcfe35d-6796-410d-921d-0d4d9b3564a0@intel.com \
--to=riana.tauro@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=raag.jadav@intel.com \
--cc=shuicheng.lin@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