From: Dave Jiang <dave.jiang@intel.com>
To: Robert Richter <rrichter@amd.com>
Cc: <linux-cxl@vger.kernel.org>, Ira Weiny <ira.weiny@intel.com>,
<dan.j.williams@intel.com>, <vishal.l.verma@intel.com>,
<alison.schofield@intel.com>, <Jonathan.Cameron@huawei.com>,
<dave@stgolabs.net>
Subject: Re: [PATCH v6 3/5] cxl: Fix device reference leak in cxl_port_perf_data_calculate()
Date: Fri, 5 Jan 2024 16:59:48 -0700 [thread overview]
Message-ID: <3d0a0ec2-1184-48dc-aa09-5d62b17d06a5@intel.com> (raw)
In-Reply-To: <ZZiJMN4zjjDErSRF@rric.localdomain>
On 1/5/24 15:56, Robert Richter wrote:
> See inline.
>
> On 05.01.24 15:07:46, Dave Jiang wrote:
>> cxl_port_perf_data_calculate() calls find_cxl_root() and does not
>> dereference the 'struct device' in the cxl_root->port. find_cxl_root()
>> calls get_device() and takes a reference on the port 'struct device'
>> member. Use the __free() macro to ensure the dereference happens.
>>
>> Fixes: 7a4f148dd8d5 ("cxl: Compute the entire CXL path latency and bandwidth data")
>> Reviewed-by: Ira Weiny <ira.weiny@intel.com>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>> v5:
>> - Update patch title (Dan)
>> ---
>> drivers/cxl/core/cdat.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c
>> index 0df5379cf02f..c6208aab452f 100644
>> --- a/drivers/cxl/core/cdat.c
>> +++ b/drivers/cxl/core/cdat.c
>> @@ -162,7 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>> struct xarray *dsmas_xa)
>> {
>> struct access_coordinate c;
>> - struct cxl_root *cxl_root;
>> struct dsmas_entry *dent;
>> int valid_entries = 0;
>> unsigned long index;
>> @@ -174,7 +173,11 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>> return rc;
>> }
>>
>> - cxl_root = find_cxl_root(port);
>> + struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
>
> I am not quite sure here, can a definition in the middle of a block?
> At least this is uncommon.
From what I understand with the introduction of the scope-based resource management, this kind of declaration is ok for that purpose? Dan?
>
>> +
>> + if (!cxl_root)
>> + return -ENODEV;
>
> As Dan pointed out earlier, isn't there always a root port in the
> hierarchy? So the check could be dropped?
>
>> +
>> if (!cxl_root->ops || !cxl_root->ops->qos_class)
>> return -EOPNOTSUPP;
>>
>>
>>
next prev parent reply other threads:[~2024-01-05 23:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-05 22:07 [PATCH v6 0/5] cxl: find_cxl_root() related cleanups Dave Jiang
2024-01-05 22:07 ` [PATCH v6 1/5] cxl: Introduce put_cxl_root() helper Dave Jiang
2024-01-05 22:14 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 2/5] cxl: Convert find_cxl_root() to return a 'struct cxl_root *' Dave Jiang
2024-01-05 22:51 ` Robert Richter
2024-01-05 23:08 ` Dave Jiang
2024-01-05 23:34 ` Dave Jiang
2024-01-08 20:43 ` Dan Williams
2024-01-08 22:30 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 3/5] cxl: Fix device reference leak in cxl_port_perf_data_calculate() Dave Jiang
2024-01-05 22:56 ` Robert Richter
2024-01-05 23:59 ` Dave Jiang [this message]
2024-01-08 21:03 ` Dan Williams
2024-01-05 22:07 ` [PATCH v6 4/5] cxl: Refactor to use __free() for cxl_root allocation in cxl_find_nvdimm_bridge() Dave Jiang
2024-01-05 23:06 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 5/5] cxl: Refactor to use __free() for cxl_root allocation in cxl_endpoint_port_probe() Dave Jiang
2024-01-05 23:09 ` Robert Richter
2024-01-05 22:35 ` [PATCH v6 0/5] cxl: find_cxl_root() related cleanups Dan Williams
2024-01-08 11:53 ` Jonathan Cameron
2024-01-08 21:05 ` Dan Williams
2024-01-09 1:07 ` [PATCH 1/3] cxl: Remove cxl_root check after find_cxl_root Dave Jiang
2024-01-09 1:16 ` Dan Williams
2024-01-09 1:07 ` [PATCH 2/3] cxl: Cleanup unnecessary uages of cxl_port local vars from cxl_root Dave Jiang
2024-01-09 1:17 ` Dan Williams
2024-01-09 15:29 ` Jonathan Cameron
2024-01-09 15:38 ` Dave Jiang
2024-01-09 1:07 ` [PATCH 3/3] cxl: Make calling of find_cxl_root() declaration uniform Dave Jiang
2024-01-09 1:37 ` Dan Williams
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=3d0a0ec2-1184-48dc-aa09-5d62b17d06a5@intel.com \
--to=dave.jiang@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=rrichter@amd.com \
--cc=vishal.l.verma@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