From: wuyifan <wuyifan50@huawei.com>
To: Reinette Chatre <reinette.chatre@intel.com>,
<tony.luck@intel.com>, <Dave.Martin@arm.com>,
<james.morse@arm.com>, <babu.moger@amd.com>, <shuah@kernel.org>,
<tan.shaopeng@fujitsu.com>, <fenghuay@nvidia.com>,
<ben.horgan@arm.com>, <jonathan.cameron@huawei.com>,
<zengheng4@huawei.com>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kselftest@vger.kernel.org>, <linuxarm@huawei.com>
Cc: <xiaqinxin@huawei.com>, <prime.zeng@hisilicon.com>,
<wangyushan12@huawei.com>, <xuwei5@huawei.com>,
<fanghao11@huawei.com>, <wangzhou1@hisilicon.com>
Subject: Re: [PATCH v2 1/6] selftests/resctrl: Introduced linked list management for IMC counters
Date: Fri, 8 May 2026 18:14:26 +0800 [thread overview]
Message-ID: <86683f18-2d11-4e20-a3b3-736da89e8cf1@huawei.com> (raw)
In-Reply-To: <4d600e39-686d-4f0f-8a74-6d55bffac70a@intel.com>
Hi Reinette
On 5/8/2026 12:13 AM, Reinette Chatre wrote:
>> Calling cleanup_read_mem_bw_imc() in the error exit path may be intended
>> to prevent resource leaks. However, this results in the function being called
>> repeatedly in both the error exit branch and test_cleanup().
> You are correct and calling it repeatedly is ok. When cleanup_read_mem_bw_imc() is
> called from test_cleanup() after a failure in parse_imc_read_bw_events() then it
> will find that the list is empty and just be a no-op. This is safe.
>
>> Is there any specific intention behind calling it in parse_imc_read_bw_events()?
> The motivation behind calling it in parse_imc_read_bw_events() is to not leave this
> memory allocated when this function fails. A function having a single responsibility
> is easier to use and maintain since a caller does not need to take into account that
> when the function fails it also needs to have additional responsibility to clean up
> the state left behind by it.
>
> There may be some patterns where caller needs to clean up after a failure but that is
> usually done in an obvious way where the caller_immediately_ does the cleanup on failure
> but here this dependency is well hidden in this implementation with test_cleanup() being
> called so far from parse_imc_read_bw_events(). This hidden dependency makes this code
> difficult to use and maintain.
>
>> Or should the cleanup be uniformly handled in test_cleanup()?
> Handling it only in test_cleanup() may work in current execution flow but if the code is
> ever re-factored this would result in a memory leak. It is not custom that callers need
> to clean up state when a function fails and since this allocation is buried deep within the
> execution flow I see this as a latent bug just waiting to be triggered.
Thank you for the detailed explanation. I understand the rationale now.
I will explicitly add cleanup calls in the error exit path in the next
version.
Best regards,
Yifan
next prev parent reply other threads:[~2026-05-08 10:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 9:33 [PATCH v2 0/6] selftests/resctrl: Add dynamic linked list management for IMC counters Yifan Wu
2026-04-10 9:33 ` [PATCH v2 1/6] selftests/resctrl: Introduced " Yifan Wu
2026-04-22 16:02 ` Reinette Chatre
2026-05-06 7:17 ` wuyifan
2026-05-07 16:13 ` Reinette Chatre
2026-05-08 10:14 ` wuyifan [this message]
2026-04-10 9:33 ` [PATCH v2 2/6] selftests/resctrl: Refactor the discovery of IMC counters using linked list Yifan Wu
2026-04-22 16:04 ` Reinette Chatre
2026-04-10 9:33 ` [PATCH v2 3/6] selftests/resctrl: Refactor the initialization of IMC's perf_event_attr " Yifan Wu
2026-04-22 16:05 ` Reinette Chatre
2026-04-10 9:33 ` [PATCH v2 4/6] selftests/resctrl: Refactor perf event open/close " Yifan Wu
2026-04-22 16:05 ` Reinette Chatre
2026-04-10 9:33 ` [PATCH v2 5/6] selftests/resctrl: Refactor reading from IMC " Yifan Wu
2026-04-10 9:33 ` [PATCH v2 6/6] selftests/resctrl: Remove the definition of the IMC counter config array and imcs Yifan Wu
2026-04-22 16:05 ` Reinette Chatre
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=86683f18-2d11-4e20-a3b3-736da89e8cf1@huawei.com \
--to=wuyifan50@huawei.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=ben.horgan@arm.com \
--cc=fanghao11@huawei.com \
--cc=fenghuay@nvidia.com \
--cc=james.morse@arm.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=prime.zeng@hisilicon.com \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=tan.shaopeng@fujitsu.com \
--cc=tony.luck@intel.com \
--cc=wangyushan12@huawei.com \
--cc=wangzhou1@hisilicon.com \
--cc=xiaqinxin@huawei.com \
--cc=xuwei5@huawei.com \
--cc=zengheng4@huawei.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