Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Jiang" <dave.jiang@intel.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v6 4/6] cxl/test: Add hierarchy enumeration support for type2 device
Date: Mon, 29 Jun 2026 20:36:57 +0000	[thread overview]
Message-ID: <20260629203658.574A51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260629202720.3658117-5-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The error path for cxl_test_init() incorrectly replaces platform_device_unregister() with platform_device_put() for cxl_acpi, leading to a resource leak and potential use-after-free.
--

commit 74917ddebbac04cd137d2f935b0132cdc7d979fe
Author: Dave Jiang <dave.jiang@intel.com>
cxl/test: Add hierarchy enumeration support for type2 device

This commit adds enumeration of type2 device hierarchy in cxl-test. The type2 
device is configured to be directly attached to a root port instead of the 
rp -> switch -> device setup used for type3 hierarchy.

> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index 8abe066080bc8..1eac06ad46601 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
[ ... ]
> @@ -2156,17 +2314,9 @@ static __init int cxl_test_init(void)
>  err_mem:
>  	cxl_mem_exit();
>  err_root:
> -	platform_device_unregister(cxl_acpi);
> -err_rch:
> -	cxl_rch_topo_exit();
> -err_single:
> -	cxl_single_topo_exit();
> -err_switches:
> -	cxl_switches_remove();
> -err_root_ports:
> -	cxl_rootports_remove();
> -err_host_bridges:
> -	host_bridges_remove();
> +	platform_device_put(cxl_acpi);

[Severity: High]
Does this error path properly tear down the device if cxl_mem_init() or
hmem_test_init() fails?

Since cxl_acpi was already successfully registered with the driver core via
cxl_mock_platform_device_add() earlier in cxl_test_init(), it seems
platform_device_unregister() should be used instead of platform_device_put().

Using platform_device_put() here only drops the initial allocation reference,
leaving the device actively linked in the platform bus and sysfs hierarchies.

Because the module unload upon initialization failure will free its memory,
could any subsequent access to the device's sysfs files dereference invalid
memory and cause a use-after-free?

> +err_topo:
> +	cxl_topo_exit();
>  err_populate:
>  	depopulate_all_mock_resources();
>  err_gen_pool_add:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260629202720.3658117-1-dave.jiang@intel.com?part=4

  reply	other threads:[~2026-06-29 20:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 20:27 [PATCH v6 0/6] cxl: Add CXL type2 accelerator support for cxl_test Dave Jiang
2026-06-29 20:27 ` [PATCH v6 1/6] cxl/test: Add test for module parameters Dave Jiang
2026-06-29 20:27 ` [PATCH v6 2/6] cxl/test: Add type2 support for mock CFMWS0 Dave Jiang
2026-06-29 20:27 ` [PATCH v6 3/6] cxl/test: Refactor platform device enumerations Dave Jiang
2026-06-29 20:38   ` sashiko-bot
2026-06-29 20:27 ` [PATCH v6 4/6] cxl/test: Add hierarchy enumeration support for type2 device Dave Jiang
2026-06-29 20:36   ` sashiko-bot [this message]
2026-06-29 20:43     ` Dave Jiang
2026-06-29 20:27 ` [PATCH v6 5/6] cxl/test: Fixup hdm init for auto region to support type2 Dave Jiang
2026-06-29 20:38   ` sashiko-bot
2026-06-29 20:27 ` [PATCH v6 6/6] cxl/test: Add cxl_test accelerator driver Dave Jiang
2026-06-29 20:37   ` sashiko-bot

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=20260629203658.574A51F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dave.jiang@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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