clk: scpi: register scpi-cpufreq once and clear on failure

scpi_clocks_probe() walks clock children and, for each DVFS provider, calls
platform_device_register_simple("scpi-cpufreq", -1, ...). Two related bugs:

Since all DVFS providers register the fixed scpi-cpufreq device using
PLATFORM_DEVID_NONE, a second registration fails with -EEXIST and
overwrites the pointer to the successfully registered device. The first
device can then no longer be unregistered.

Register the virtual device only once. If registration fails, reset the
pointer to NULL so a subsequent DVFS provider can retry and the global
pointer only represents a successfully registered device.

Fixes: 9490f01e24 ("clk: scpi: add support for cpufreq virtual device")
Fixes: 67bcc2c5f1 ("clk: scpi: don't add cpufreq device if the scpi dvfs node is disabled")
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
Link: https://patch.msgid.link/fd1b9199a9c3.v2.1785200642.git.liuxixin@kylinos.cn
(sudeep.holla: reworded the commit message to improve readability)
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
This commit is contained in:
Xixin Liu 2026-07-28 08:50:00 +08:00 committed by Sudeep Holla
parent 70f4b78d56
commit ab06cf8152

View File

@ -272,10 +272,14 @@ static int scpi_clocks_probe(struct platform_device *pdev)
if (match->data != &scpi_dvfs_ops)
continue;
/* Add the virtual cpufreq device if it's DVFS clock provider */
if (cpufreq_dev)
continue;
cpufreq_dev = platform_device_register_simple("scpi-cpufreq",
-1, NULL, 0);
if (IS_ERR(cpufreq_dev))
if (IS_ERR(cpufreq_dev)) {
pr_warn("unable to register cpufreq device");
cpufreq_dev = NULL;
}
}
return 0;
}