From: Alison Schofield <alison.schofield@intel.com>
To: Chenyuan Yang <chenyuan0y@gmail.com>
Cc: dave@stgolabs.net, jonathan.cameron@huawei.com,
dave.jiang@intel.com, vishal.l.verma@intel.com,
ira.weiny@intel.com, dan.j.williams@intel.com,
linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cxl/acpi: Add Null check for adev
Date: Thu, 13 Mar 2025 15:04:38 -0700 [thread overview]
Message-ID: <Z9NWdob3CSy9UDq5@aschofie-mobl2.lan> (raw)
In-Reply-To: <20250313190753.450546-1-chenyuan0y@gmail.com>
On Thu, Mar 13, 2025 at 02:07:53PM -0500, Chenyuan Yang wrote:
> Not all devices have an ACPI companion fwnode, so adev might be NULL.
> This is similar to the commit cd2fd6eab480
> ("platform/x86: int3472: Check for adev == NULL").
>
> Add a check for adev not being set and return -ENODEV in that case to
> avoid a possible NULL pointer deref in cxl_acpi_probe().
>
Avoiding the NULL ptr deref seems obvious as ACPI_COMPANION() return
is routinely checked throughout the kernel. Why the reference to the
other commit? Do these devices have something in common?
I'm curious as to when *this* specific adev can be NULL.
Looks good to check it like you do here, or if someone chimes in that
it can never be NULL, just add a code comment saying so.
Perhaps emit a message on NULL too.
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> ---
> drivers/cxl/acpi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
> index cb14829bb9be..9195001db3c1 100644
> --- a/drivers/cxl/acpi.c
> +++ b/drivers/cxl/acpi.c
> @@ -823,6 +823,9 @@ static int cxl_acpi_probe(struct platform_device *pdev)
> struct acpi_device *adev = ACPI_COMPANION(host);
> struct cxl_cfmws_context ctx;
>
> + if (!adev)
> + return -ENODEV;
> +
> device_lock_set_class(&pdev->dev, &cxl_root_key);
> rc = devm_add_action_or_reset(&pdev->dev, cxl_acpi_lock_reset_class,
> &pdev->dev);
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-03-13 22:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 19:07 [PATCH] cxl/acpi: Add Null check for adev Chenyuan Yang
2025-03-13 22:04 ` Alison Schofield [this message]
2025-03-13 22:27 ` Dave Jiang
2025-03-13 22:31 ` 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=Z9NWdob3CSy9UDq5@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=chenyuan0y@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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