Re: [PATCH 2/7] pmdomain: qcom: add CPRv4 power domain driver

From: Julius Bairaktaris

Date: Sat Dec 05 2026 - 10:01:00 EST


On Tue, Dec 01, 2026 at 10:34:15PM +0100, Robert Marko wrote:
> +unreg_genpd:
> + /* Clean up genpds */
> + for (i = desc->num_threads - 1; i >= 0; i--)
> + pm_genpd_remove(&drv->threads[i].pd);

i is an unsigned int in cpr_probe(), so this loop does not end: once i
wraps it indexes past drv->threads. Any error from cpr4_init_parameters(),
cpr_configure() or of_genpd_add_provider_onecell() lands here. An int, or
"while (i--)" from num_threads, fixes it.

> +static void cpr_remove(struct platform_device *pdev)
> +{
> + struct cpr_drv *drv = platform_get_drvdata(pdev);
> + int i;
> +
> + of_genpd_del_provider(pdev->dev.of_node);
> +
> + for (i = 0; i < drv->desc->num_threads; i++) {
> + cpr_ctl_disable(&drv->threads[i]);
> + cpr_irq_set(&drv->threads[i], 0);
> + pm_genpd_remove(&drv->threads[i].pd);
> + }

An unbind through /sys/bus/platform/drivers/qcom-cpr4/unbind, or rmmod,
runs this while qcom-cpufreq-nvmem has the CPUs attached. pm_genpd_remove()
returns -EBUSY because device_count is not zero, the error is dropped, and
devres frees drv->threads with the still registered domain in it, drv,
the MMIO mapping and the vdd regulator. The next frequency change runs
cpr_set_performance_state() on the freed domain.

> +static struct platform_driver cpr4_driver = {
> + .probe = cpr_probe,
> + .remove = cpr_remove,
> + .driver = {
> + .name = "qcom-cpr4",
> + .of_match_table = cpr4_match_table,
> + },
> +};
> +module_platform_driver(cpr4_driver)

remove() cannot refuse and the CPUs never detach, so drop cpr_remove()
and do what rpmpd and rpmhpd do: set .suppress_bind_attrs = true and
register with builtin_platform_driver(cpr4_driver), which has no module
exit. The platform_set_drvdata() in probe then has no reader.

The APCS device link added in probe is a managed link, so unbinding
qcom-apcs-ipc still unbinds this device. That driver's remove() also
unregisters the CPU clock device, so the fix for that path goes in the
mailbox driver.