Re: [PATCH v12 04/11] clk: realtek: Introduce common probe() and remove()

[email protected]
Newsgroups org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Race condition in rtk_clk_remove() leading to NULL pointer dereference
--

--- Patch [4]: [PATCH v12 04/11] clk: realtek: Introduce common probe() and remove() ---
commit 3b0d9bad8da74951cdbfe60e9a47d2e11203aeb5
Author: Cheng-Yu Lee <[email protected]>

clk: realtek: Introduce common probe() and remove()

This patch introduces common probe and remove routines for Realtek clock
drivers. It handles setting up shared regmaps, registering clock hardware,
and conditionally creating an auxiliary device for reset controllers.

> diff --git a/drivers/clk/realtek/clk-rtk-common.c b/drivers/clk/realtek/clk-rtk-common.c
> new file mode 100644
> index 0000000000000..e8422ecbad797
> --- /dev/null
> +++ b/drivers/clk/realtek/clk-rtk-common.c
[ ... ]
> +int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc)
> +{
[ ... ]
> +	for (i = 0; i < desc->clk_data->num; i++) {
> +		hw = desc->clk_data->hws[i];
> +		if (!hw)
> +			continue;
> +
> +		ret = devm_clk_hw_register(dev, hw);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "failed to register hw of clk%d\n", i);
> +	}
[ ... ]
> +void rtk_clk_remove(struct platform_device *pdev)
> +{
> +	const struct rtk_clk_desc *desc = platform_get_drvdata(pdev);
> +
> +	if (!desc)
> +		return;
> +
> +	for (int i = 0; i < desc->num_clks; i++)
> +		desc->clks[i]->regmap = NULL;

[Severity: High]
Because rtk_clk_probe() registers the clocks using devm_clk_hw_register(),
the devres framework will unregister the clocks after rtk_clk_remove()
completes.

By clearing the regmap pointers to NULL here, does this create a window where
the clocks are still registered in the clock framework but their underlying
regmap pointers are missing?

If clock operations are invoked concurrently during driver unbind, such as
from reading clk_summary in debugfs, could the clock callbacks dereference
this NULL regmap and cause a crash?

> +}
> +EXPORT_SYMBOL_NS_GPL(rtk_clk_remove, "CLK_REALTEK");

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.