All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Roberts" <ryan.roberts@arm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices
Date: Fri, 17 Jul 2026 10:57:08 +0000	[thread overview]
Message-ID: <20260717105709.172911F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717104759.123203-4-ryan.roberts@arm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Improper handling of `krealloc_array()` failure in `cla_dev_domain_get()` overwrites the array pointer with NULL, causing a memory leak and subsequent NULL pointer dereference.
- [High] Missing `platform_driver_unregister()` on the `cla_domains_finalise()` error path leaves the driver registered, leading to a Use-After-Free.
- [Medium] Integer overflow when calculating `cla_nr_domains` causes lookup tables to remain unpopulated, silently breaking device initialization.
--

--- Patch [3]: [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices ---
commit f4618493e3d162e6d466cff0e6d759171e5655f5
Author: Jean-Philippe Brucker <jpb@kernel.org>

misc/arm-cla: Probe firmware-described devices

Discover CLA devices from firmware and instantiate the driver with
platform_driver_probe(). Map the MMIO frame, select the kernel-accessible
privilege-level frame and associate each CLA with the CPU named by firmware.

> diff --git a/drivers/misc/arm-cla/cla-init.c b/drivers/misc/arm-cla/cla-init.c
> --- a/drivers/misc/arm-cla/cla-init.c
> +++ b/drivers/misc/arm-cla/cla-init.c

[ ... ]

>  	ret = platform_driver_probe(&cla_driver, cla_probe);
>  	if (ret) {
>  		if (ret != -ENODEV)
>  			pr_err("arm-cla: probe failed with %d\n", ret);
>  		/* Some domains may have been created during probe */
>  		goto err_domains_free;
>  	}
>  
>  	ret = cla_domains_finalise();
>  	if (ret) {
>  		pr_err("arm-cla: failed to finalise domains: %d", ret);
>  		goto err_domains_free;

[Severity: High]
If cla_domains_finalise() fails, this jumps to err_domains_free, which skips
platform_driver_unregister(). Will this leave dangling pointers to the freed
cla_driver struct on the platform bus?

>  	}
>  
>  	/*
>  	 * Each CPU initializes their own CLA. CPUHP uses a pair of smp_mb()
>  	 * when calling the startup callback, ensuring that cla_dev_setup()
>  	 * reads fully initialized cla_lut_cpu and cla_dev structures.
>  	 */
>  	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm-cla",
>  				cla_dev_setup, cla_dev_teardown);
>  	if (ret < 0) {
>  		pr_err("arm-cla: failed to setup cpuhp: %d", ret);
>  		goto err_driver_unregister;
>  	}
>  	cla_cpuhp_state = ret;
>  
>  	return 0;
>  
>  err_driver_unregister:
>  	platform_driver_unregister(&cla_driver);
>  err_domains_free:
>  	cla_domains_free();
>  	return ret;
>  }

[ ... ]

> diff --git a/drivers/misc/arm-cla/cla-topology.c b/drivers/misc/arm-cla/cla-topology.c
> --- /dev/null
> +++ b/drivers/misc/arm-cla/cla-topology.c

[ ... ]

> +struct cla_domain *cla_dev_domain_get(struct cla_dev *dev)
> +{
> +	int ret;
> +	unsigned int domain_id;
> +	struct cla_domain *domain;
> +
> +	/* Domain ID is provided by firmware */
> +	ret = of_property_read_u32(dev->dev->of_node, "domain", &domain_id);
> +	if (WARN_ON(ret))
> +		return ERR_PTR(-EINVAL);
> +
> +	domain = xa_load(&cla_domains, domain_id);
> +	if (domain) {
> +		domain->nr_devs++;
> +		domain->devs = krealloc_array(domain->devs, domain->nr_devs,
> +					      sizeof(*domain->devs), GFP_KERNEL);

[Severity: High]
Does this code leak the original domain->devs array if krealloc_array() fails
and returns NULL? Also, since domain->nr_devs was unconditionally incremented,
will a subsequent call to cla_domains_finalise() dereference the NULL
pointer at domain->devs[j]?

> +		if (!domain->devs)
> +			return ERR_PTR(-ENOMEM);
> +		domain->devs[domain->nr_devs - 1] = dev;
> +		return domain;
> +	}
> +
> +	domain = cla_domain_alloc(dev, domain_id);
> +	if (IS_ERR(domain))
> +		return domain;
> +
> +	cla_nr_domains = max(domain_id + 1, cla_nr_domains);

[Severity: Medium]
Can this calculation overflow to 0 if firmware provides a domain_id of
UINT_MAX? If it overflows, will cla_domains_finalise() skip its loop and
leave the device uninitialized in the lookup tables?

> +
> +	return domain;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717104759.123203-1-ryan.roberts@arm.com?part=3

  reply	other threads:[~2026-07-17 10:57 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 10:47 [RFC PATCH v1 0/8] Arm Core Local Accelerator Driver Ryan Roberts
2026-07-17 10:47 ` [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-07-17 10:56   ` sashiko-bot
2026-07-17 13:49   ` Arnd Bergmann
2026-07-17 15:44     ` Ryan Roberts
2026-07-17 16:10       ` Arnd Bergmann
2026-07-17 10:47 ` [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-07-17 11:01   ` sashiko-bot
2026-07-17 12:16   ` Arnd Bergmann
2026-07-17 10:47 ` [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-07-17 10:57   ` sashiko-bot [this message]
2026-07-17 12:25   ` Arnd Bergmann
2026-07-17 12:36     ` Ryan Roberts
2026-07-17 10:47 ` [RFC PATCH v1 4/8] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-07-17 10:58   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 5/8] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-07-17 10:58   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 6/8] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-07-17 11:02   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 7/8] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-07-17 11:01   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface Ryan Roberts
2026-07-17 11:10   ` sashiko-bot
2026-07-17 12:54   ` Arnd Bergmann
2026-07-17 14:35     ` Ryan Roberts
2026-07-17 15:31       ` Arnd Bergmann
2026-07-17 16:21         ` Ryan Roberts
2026-07-17 20:11           ` Arnd Bergmann
2026-07-17 11:33 ` [RFC PATCH v1 0/8] Arm Core Local Accelerator Driver Will Deacon
2026-07-17 12:09   ` Marc Zyngier
2026-07-17 12:33     ` Ryan Roberts
2026-07-17 12:30   ` Ryan Roberts
2026-07-17 13:32   ` Jason Gunthorpe
2026-07-17 13:42     ` Ryan Roberts

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=20260717105709.172911F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.