[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <257958e0-8359-4296-9653-ba821b39d813@gmail.com>
Date: Wed, 30 Sep 2020 18:22:37 +0300
From: Dmitry Osipenko <digetx@...il.com>
To: Krzysztof Kozlowski <krzk@...nel.org>
Cc: Nicolin Chen <nicoleotsuka@...il.com>, thierry.reding@...il.com,
joro@...tes.org, vdumpa@...dia.com, jonathanh@...dia.com,
linux-tegra@...r.kernel.org, iommu@...ts.linux-foundation.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 1/3] memory: tegra: Add
devm_tegra_get_memory_controller()
30.09.2020 17:45, Krzysztof Kozlowski пишет:
> On Wed, 30 Sep 2020 at 16:41, Dmitry Osipenko <digetx@...il.com> wrote:
>>
>> ...
>>> +struct tegra_mc *devm_tegra_get_memory_controller(struct device *dev)
>>> +{
>>> + struct platform_device *pdev;
>>> + struct device_node *np;
>>> + struct tegra_mc *mc;
>>> + int err;
>>> +
>>> + np = of_find_matching_node_and_match(NULL, tegra_mc_of_match, NULL);
>>> + if (!np)
>>> + return ERR_PTR(-ENOENT);
>>> +
>>> + pdev = of_find_device_by_node(np);
>>> + of_node_put(np);
>>> + if (!pdev)
>>> + return ERR_PTR(-ENODEV);
>>> +
>>> + mc = platform_get_drvdata(pdev);
>>> + if (!mc) {
>>> + put_device(mc->dev);
>>
>> This should be put_device(&pdev->dev). Please always be careful while
>> copying someones else code :)
>
> Good catch. I guess devm_add_action_or_reset() would also work... or
> running Smatch on new code. Smatch should point it out.
The devm_add_action_or_reset() shouldn't help much in this particular
case because it's too early for the devm_add_action here.
Having an explicit put_device() in all error code paths also helps with
improving readability of the code a tad, IMO.
Smatch indeed should catch this bug, but Smatch usually isn't a part of
the developers workflow. More often Smatch is a part of maintainers
workflow, hence such problems usually are getting caught before patches
are applied.
Powered by blists - more mailing lists