[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <91407377-f586-4fd2-b8e4-d1fd54c1a52a@linaro.org>
Date: Mon, 8 Sep 2025 08:39:38 +0100
From: Tudor Ambarus <tudor.ambarus@...aro.org>
To: Krzysztof Kozlowski <krzk@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, Peter Griffin <peter.griffin@...aro.org>,
André Draszik <andre.draszik@...aro.org>,
Michael Turquette <mturquette@...libre.com>, Stephen Boyd
<sboyd@...nel.org>, Alim Akhtar <alim.akhtar@...sung.com>,
Sylwester Nawrocki <s.nawrocki@...sung.com>,
Chanwoo Choi <cw00.choi@...sung.com>,
Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>
Cc: linux-kernel@...r.kernel.org, linux-samsung-soc@...r.kernel.org,
devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-clk@...r.kernel.org, willmcvicker@...gle.com, kernel-team@...roid.com
Subject: Re: [PATCH v3 3/5] clk: samsung: add Exynos ACPM clock driver
On 9/6/25 1:19 PM, Krzysztof Kozlowski wrote:
> On 03/09/2025 15:56, Tudor Ambarus wrote:
>> +
>> +static int acpm_clk_probe(struct platform_device *pdev)
>> +{
>> + enum acpm_clk_dev_type type = platform_get_device_id(pdev)->driver_data;
>> + const struct acpm_clk_driver_data *drv_data;
>> + const struct acpm_handle *acpm_handle;
>> + struct clk_hw_onecell_data *clk_data;
>> + struct clk_hw **hws;
>> + struct device *dev = &pdev->dev;
>> + struct acpm_clk *aclks;
>> + unsigned int mbox_chan_id;
>> + int i, err, count;
>> +
>> + switch (type) {
>> + case GS101_ACPM_CLK_ID:
>> + drv_data = &acpm_clk_gs101;
>
> Just use acpm_clk_gs101 directly (see also further comment).
okay
>
>> + break;
>> + default:
>> + return dev_err_probe(dev, -EINVAL, "Invalid device type\n");
>> + }
>> +
>> + acpm_handle = devm_acpm_get_by_node(dev, dev->parent->of_node);
>> + if (IS_ERR(acpm_handle))
>> + return dev_err_probe(dev, PTR_ERR(acpm_handle),
>> + "Failed to get acpm handle.\n");
>> +
>> + count = drv_data->nr_clks;
>> + mbox_chan_id = drv_data->mbox_chan_id;
>> +
>> + clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count),
>> + GFP_KERNEL);
>> + if (!clk_data)
>> + return -ENOMEM;
>> +
>> + clk_data->num = count;
>> + hws = clk_data->hws;
>> +
>> + aclks = devm_kcalloc(dev, count, sizeof(*aclks), GFP_KERNEL);
>> + if (!aclks)
>> + return -ENOMEM;
>> +
>> + for (i = 0; i < count; i++) {
>> + const struct acpm_clk_variant *variant = &drv_data->clks[i];
>> + unsigned int id = variant->id;
>> + struct acpm_clk *aclk;
>> +
>> + if (id >= count)
>
> This is not possible. You control the IDs build time, so this must be
> either build time check or no check. I vote for no check, because I
using BUILD_BUG_ON_MSG? that would work, see below the why.
> don't think the ID is anyhow related to number of clocks. What if (not
> recommended but what if) the IDs have a gap and next ID is 1000. I see
> your code using ID:
>
>
>> + return dev_err_probe(dev, -EINVAL,
>> + "Invalid ACPM clock ID.\n");
>> +
>> + aclk = &aclks[id];
>> + aclk->id = id;
>> + aclk->handle = acpm_handle;
>> + aclk->mbox_chan_id = mbox_chan_id;
>> +
>> + hws[id] = &aclk->hw;
>
> ^^^ here, but why do you need it? Why it cannot be hws[i]?
so that it works correctly with of_clk_hw_onecell_get() in case the clocks
IDs are not starting from 0 or are reordered when defined. For example let's
consider clock ID 1 is wrongly defined at index 0 in the array. When someone
references clock ID 1 in the device tree, and we use of_clk_hw_onecell_get,
it would get the clock defined at index 1.
In my case the clocks start from index 0 and they are defined in ascending
order with no gaps, so the check is gratuitously made. I wanted to have some
sanity check. Do you still think I shall remove the check and use hws[i]?
>
>> +
>> + err = acpm_clk_ops_init(dev, aclk, variant->name);
>> + if (err)
>> + return dev_err_probe(dev, err,
>> + "Failed to register clock.\n");
>> + }
>> +
>> + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
>> + clk_data);
>> +}
>> +
>> +static const struct platform_device_id acpm_clk_id[] = {
>> + { "gs101-acpm-clk", GS101_ACPM_CLK_ID },
>
> Please drop GS101_ACPM_CLK_ID here and in other places. It's dead code
> now. It should be introduced with next users/devices.
okay. Thanks for the review!
>
>> + {},
>> +};
>> +MODULE_DEVICE_TABLE(platform, acpm_clk_id);
>
> Best regards,
> Krzysztof
Powered by blists - more mailing lists