All of lore.kernel.org
 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 v3 3/6] cxl/test: Refactor platform device enumerations
Date: Wed, 10 Jun 2026 22:32:20 +0000	[thread overview]
Message-ID: <20260610223221.3B6DC1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260610222328.2272427-4-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing error code assignments on `platform_device_alloc` failure cause populate helpers to falsely return success, leading to an invalid pointer dereference crash.
- [Medium] Error handling cleanup loops mistakenly use `break` instead of `continue` in reverse iteration array cleanup functions, causing resource leaks on error paths.
--

commit 166861bc24df0a0108568d617198fe4532f08924
Author: Dave Jiang <dave.jiang@intel.com>
cxl/test: Refactor platform device enumerations

This commit refactors the platform device enumeration in the cxl test
module by splitting host bridges, root ports, and switch port setups
into separate helper functions.

> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index e91c125d557d9..b29be2597064e 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
[ ... ]
> +static void host_bridges_remove(void)
> +{
> +	int i;
> +
> +	for (i = ARRAY_SIZE(cxl_host_bridge) - 1; i >= 0; i--) {
> +		struct platform_device *pdev = cxl_host_bridge[i];
> +
> +		if (!pdev)
> +			break;

[Severity: Medium]
Since this cleanup loop iterates backwards from the end of the array, won't
a break here immediately terminate the loop on the first empty slot?

In the original code, this used a continue to skip empty slots and
successfully reach the populated devices at lower indices. Does this cause
resource leaks when initialization fails partway through?

This same pattern appears to be repeated in cxl_rootports_remove(),
cxl_usps_remove(), and cxl_dsps_remove().

[ ... ]
> +static int host_bridges_populate(void)
> +{
> +	int rc = 0;
> +
> +	for (int i = 0; i < ARRAY_SIZE(cxl_host_bridge); i++) {
>  		struct acpi_device *adev = &host_bridge[i];
>  		struct platform_device *pdev;
>  
[ ... ]
> +		pdev = platform_device_alloc("cxl_host_bridge", i);
> +		if (!pdev)
> +			goto err_bridge;

[Severity: High]
If platform_device_alloc() fails here, does this function return 0
instead of an error code?

Because rc is initialized to 0, returning 0 would cause the main init
function to assume success and proceed.

If initialization proceeds to cxl_rootports_populate(), it will try to set
the parent pointer using a NULL bridge device:

cxl_rootports_populate()
    bridge = cxl_host_bridge[...];
    pdev->dev.parent = &bridge->dev;

Could this cause an invalid pointer dereference when platform_device_add()
is subsequently called? Should this set rc = -ENOMEM before jumping to
the error label?

This missing error code assignment also appears to happen in the new
cxl_rootports_populate(), cxl_usps_populate(), and cxl_dsps_populate()
helper functions.

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

  reply	other threads:[~2026-06-10 22:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 22:23 [PATCH v3 0/6] cxl: Add CXL type2 accelerator support for cxl_test Dave Jiang
2026-06-10 22:23 ` [PATCH v3 1/6] cxl/test: Add test for module parameters Dave Jiang
2026-06-10 22:32   ` sashiko-bot
2026-06-10 22:23 ` [PATCH v3 2/6] cxl/test: Add type2 support for mock CFMWS0 Dave Jiang
2026-06-10 22:32   ` sashiko-bot
2026-06-10 22:23 ` [PATCH v3 3/6] cxl/test: Refactor platform device enumerations Dave Jiang
2026-06-10 22:32   ` sashiko-bot [this message]
2026-06-10 22:23 ` [PATCH v3 4/6] cxl/test: Add hierarchy enumeration support for type2 device Dave Jiang
2026-06-10 22:36   ` sashiko-bot
2026-06-10 22:23 ` [PATCH v3 5/6] cxl/test: Fixup hdm init for auto region to support type2 Dave Jiang
2026-06-10 22:23 ` [PATCH v3 6/6] cxl/test: Add cxl_test accelerator driver Dave Jiang
2026-06-10 22: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=20260610223221.3B6DC1F00893@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.