From: Ira Weiny <ira.weiny@intel.com>
To: Li Zhijian <lizhijian@fujitsu.com>, <dave@stgolabs.net>,
<jonathan.cameron@huawei.com>, <dave.jiang@intel.com>,
<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
<ira.weiny@intel.com>, <dan.j.williams@intel.com>,
<linux-cxl@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, Li Zhijian <lizhijian@fujitsu.com>
Subject: Re: [PATCH 2/2] cxl/region: Fix missing put_device(region_dev)
Date: Mon, 29 Apr 2024 09:14:21 -0700 [thread overview]
Message-ID: <662fc75dc1106_19ca3929456@iweiny-mobl.notmuch> (raw)
In-Reply-To: <20240429013154.368118-2-lizhijian@fujitsu.com>
Li Zhijian wrote:
> > mutex_lock(&cxlrd->range_lock);
> > region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa,
> > match_region_by_range);
> > if (!region_dev)
> > cxlr = construct_region(cxlrd, cxled);
> > else
> > cxlr = to_cxl_region(region_dev);
> > mutex_unlock(&cxlrd->range_lock);
> >
> > rc = PTR_ERR_OR_ZERO(cxlr);
> > if (rc)
> > goto out;
> >
> > if (!region_dev)
> > region_dev = &cxlr->dev;
This diff hunk in the commit message is very odd. I would drop it. We
know this builds on patch 1 where you made the above change.
>
> When to_cxl_region(region_dev) fails, put_device(region_dev) should be
> called to decrease the reference count added by device_find_child().
I __think__ this is what Dan was pointing out but I'm not sure.
I wanted to point out that to_cxl_region() can't fail because the
device_find_child() is checking that the device is a region device.
Dan, is that what you were saying when you mentioned there were more
serious issues if to_cxl_region() were to fail?
Ira
>
> Simply put_device(region_dev) if region_dev is valid in the error path.
>
> Fixes: a32320b71f08 ("cxl/region: Add region autodiscovery")
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> drivers/cxl/core/region.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 3c80aa263a65..75390865382f 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3117,8 +3117,9 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
> p->res);
> }
>
> - put_device(region_dev);
> out:
> + if (region_dev)
> + put_device(region_dev);
> put_device(cxlrd_dev);
> return rc;
> }
> --
> 2.29.2
>
next prev parent reply other threads:[~2024-04-29 16:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 1:31 [PATCH 1/2] cxl/region: Fix potential invalid pointer dereference Li Zhijian
2024-04-29 1:31 ` [PATCH 2/2] cxl/region: Fix missing put_device(region_dev) Li Zhijian
2024-04-29 1:51 ` Zhijian Li (Fujitsu)
2024-04-29 8:00 ` Markus Elfring
2024-04-29 8:26 ` Zhijian Li (Fujitsu)
2024-04-29 10:00 ` Dan Carpenter
2024-04-29 10:11 ` Zhijian Li (Fujitsu)
2024-04-29 8:35 ` Zhijian Li (Fujitsu)
2024-04-29 10:17 ` Dan Carpenter
2024-04-29 10:26 ` Zhijian Li (Fujitsu)
2024-04-29 10:32 ` Dan Carpenter
2024-04-29 16:14 ` Ira Weiny [this message]
2024-04-29 7:50 ` [PATCH 1/2] cxl/region: Fix potential invalid pointer dereference Markus Elfring
2024-04-29 8:43 ` Zhijian Li (Fujitsu)
2024-04-29 8:55 ` [1/2] " Markus Elfring
2024-04-29 10:10 ` [PATCH 1/2] " Dan Carpenter
2024-04-29 10:25 ` Zhijian Li (Fujitsu)
2024-04-29 10:30 ` Dan Carpenter
2024-04-29 16:17 ` Ira Weiny
2024-04-29 16:05 ` Ira Weiny
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=662fc75dc1106_19ca3929456@iweiny-mobl.notmuch \
--to=ira.weiny@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhijian@fujitsu.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