Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
	Chenyuan Yang <chenyuan0y@gmail.com>
Cc: dave@stgolabs.net, jonathan.cameron@huawei.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:27:18 -0700	[thread overview]
Message-ID: <b2bb61f0-6250-4b90-a765-c2873eccb07d@intel.com> (raw)
In-Reply-To: <Z9NWdob3CSy9UDq5@aschofie-mobl2.lan>



On 3/13/25 3:04 PM, Alison Schofield wrote:
> 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.

You get a NULL by either the the platform device being probed is not setup correctly and the fwnode end up failing is_acpi_device_node() or CONFIG_ACPI is not set. The second is impossible as cxl_acpi depends on CONFIG_CXL_ACPI which
depends on CONFIG_ACPI. The likelihood of the first I don't think is high unless the platform device for ACPI0017 is corrupted. So in this instance in the probe function, the checking while is fine for code correctness, may not be absolutely necessary perhaps. Just my 2 cents.

DJ

> 
> 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
>>


  reply	other threads:[~2025-03-13 22:27 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
2025-03-13 22:27   ` Dave Jiang [this message]
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=b2bb61f0-6250-4b90-a765-c2873eccb07d@intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=chenyuan0y@gmail.com \
    --cc=dan.j.williams@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