[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <61741b61.46f3.1818a331e3d.Coremail.windhl@126.com>
Date: Wed, 22 Jun 2022 14:56:54 +0800 (CST)
From: "Liang He" <windhl@....com>
To: "Krzysztof Kozlowski" <krzysztof.kozlowski@...aro.org>
Cc: thierry.reding@...il.com, jonathanh@...dia.com,
linux-kernel@...r.kernel.org, linux-tegra@...r.kernel.org
Subject: Re:Re: [PATCH] memory/tegra: Add missing of_node_get() in
tegra_emc_find_node_by_ram_code
At 2022-06-22 14:50:41, "Krzysztof Kozlowski" <krzysztof.kozlowski@...aro.org> wrote:
>On 22/06/2022 06:28, Liang He wrote:
>> of_find_node_by_name() will decrease the refcount of its first arg and
>> we need to add a of_node_put() to keep refcount balance.
>
>We do NOT need to add an of_node_put?
>
Sorry, this is a typo, I want to say we need to add a 'of_node_get()'
>Anyway why do you add of_node_get which is not explained here?
>
This is a common mistake that missing the of_node_get(X) before we call
of_find_node_by_name(X,..) as the of_find_xxx will decrease the refcount of X.
A similar error is:
https://lore.kernel.org/all/20200720152806.443262648@linuxfoundation.org/
If I am wrong, please correct me, thanks.
>>
>> Besides, during the 'for' loop execution, the refcount of 'np' will be
>> automatically increased and decreased. There is no need to call
>> of_node_put() again.
>>
>> Signed-off-by: Liang He <windhl@....com>
>> ---
>> drivers/memory/tegra/tegra20-emc.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c
>> index 25ba3c5e4ad6..e43a5f8e188e 100644
>> --- a/drivers/memory/tegra/tegra20-emc.c
>> +++ b/drivers/memory/tegra/tegra20-emc.c
>> @@ -477,6 +477,7 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc)
>>
>> ram_code = tegra_read_ram_code();
>>
>> + of_get_node(dev->of_node);
>> for (np = of_find_node_by_name(dev->of_node, "emc-tables"); np;
>> np = of_find_node_by_name(np, "emc-tables")) {
>> err = of_property_read_u32(np, "nvidia,ram-code", &value);
>> @@ -484,6 +485,7 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc)
>> struct device_node *lpddr2_np;
>> bool cfg_mismatches = false;
>>
>> + of_node_get(np);
>> lpddr2_np = of_find_node_by_name(np, "lpddr2");
>> if (lpddr2_np) {
>> const struct lpddr2_info *info;
>> @@ -521,7 +523,6 @@ tegra_emc_find_node_by_ram_code(struct tegra_emc *emc)
>> }
>>
>> if (cfg_mismatches) {
>> - of_node_put(np);
>> continue;
>> }
>> }
>
>
>Best regards,
>Krzysztof
Powered by blists - more mailing lists