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 4/6] cxl/test: Add hierarchy enumeration support for type2 device
Date: Wed, 10 Jun 2026 22:36:04 +0000	[thread overview]
Message-ID: <20260610223605.0E3511F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260610222328.2272427-5-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Teardown loops iterate backwards but incorrectly use `break` when encountering a NULL pointer, causing persistent resource leaks on error paths.
--

commit 53bf17c5a72c46ea341694a714ad1ee38917639a
Author: Dave Jiang <dave.jiang@intel.com>

cxl/test: Add hierarchy enumeration support for type2 device

Add enumeration of type2 device hierarchy in cxl-test. The type2 device
is setup to be directly attached to a root port instead of rp -> switch
-> device that type3 hierarchy is setup..

> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index b29be2597064e..5186a13b20aa9 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
[ ... ]
> +static int cxl_type2_mem_init(void)
> +{
> +	int i, rc;
[ ... ]
> +err_mem:
> +	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--) {
> +		struct platform_device *pdev = cxl_mem[i];
> +
> +		if (!pdev)
> +			break;
> +		platform_device_unregister(cxl_mem[i]);
> +	}
> +	return rc;
>  }

[Severity: Medium]
Will this teardown loop leak successfully allocated devices if an error
occurs before all iterations complete?

Because cxl_mem is populated sequentially starting from index 0, the higher
indices remain NULL if initialization fails partway through. Since this
teardown loop iterates backwards from the max index, it will immediately
hit an uninitialized NULL pointer at the top and break. This skips the
unregistration for any devices that were successfully allocated at lower
indices.

Could this use continue instead of break? Alternatively, since
platform_device_unregister() handles NULL pointers safely, could the check
be omitted entirely?

This same pattern appears in cxl_type2_mem_exit() and cxl_type3_mem_exit()
in this patch, as well as in pre-existing teardown loops like
cxl_usps_remove().

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

  reply	other threads:[~2026-06-10 22:36 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
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 [this message]
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=20260610223605.0E3511F00893@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.