From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: "Xiaowei Song" <songxiaowei@hisilicon.com>,
"Binghui Wang" <wangbinghui@hisilicon.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: kirin: fix memory leak in kirin_pcie_parse_port()
Date: Fri, 5 Jul 2024 13:29:10 +0200 [thread overview]
Message-ID: <d061d545-4694-4d5b-86fa-03d1f7251b45@gmail.com> (raw)
In-Reply-To: <20240705111805.00002010@Huawei.com>
On 05/07/2024 12:18, Jonathan Cameron wrote:
> On Sun, 09 Jun 2024 12:56:14 +0200
> Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:
>
>> The conversion of this file to use the agnostic GPIO API has introduced
>> a new early return where the refcounts of two device nodes (parent and
>> child) are not decremented.
>>
>> Given that the device nodes are not required outside the loops where
>> they are used, and to avoid potential bugs every time a new error path
>> is introduced to the loop, the _scoped() versions of the macros have
>> been applied. The bug was introduced recently, and the fix is not
>> relevant for old stable kernels that might not support the scoped()
>> variant.
>>
>> Fixes: 1d38f9d89f85 ("PCI: kirin: Convert to use agnostic GPIO API")
>> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> Diff on this on is irritating as it doesn't actually show the
> buggy code... Ah well.
>
> Change is valid, but one suggestion inline.
>
> Looks like it's queued now already, but if not.
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
>
>> ---
>> This bug was found while analyzing the code and I don't have hardware to
>> validate it beyond compilation and static analysis. Any test with real
>> hardware to make sure there are no regressions is always welcome.
>>
>> The dev_err() messages have not been converted into dev_err_probe() to
>> keep the current format, but I am open to convert them if preferred.
>> ---
>> drivers/pci/controller/dwc/pcie-kirin.c | 21 ++++++---------------
>> 1 file changed, 6 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
>> index d1f54f188e71..0a29136491b8 100644
>> --- a/drivers/pci/controller/dwc/pcie-kirin.c
>> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
>> @@ -403,11 +403,10 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
>> struct device_node *node)
>> {
>> struct device *dev = &pdev->dev;
>> - struct device_node *parent, *child;
>> int ret, slot, i;
>>
>> - for_each_available_child_of_node(node, parent) {
>> - for_each_available_child_of_node(parent, child) {
>> + for_each_available_child_of_node_scoped(node, parent) {
>> + for_each_available_child_of_node_scoped(parent, child) {
>> i = pcie->num_slots;
>>
>> pcie->id_reset_gpio[i] = devm_fwnode_gpiod_get_index(dev,
>> @@ -424,14 +423,13 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
>> pcie->num_slots++;
>> if (pcie->num_slots > MAX_PCI_SLOTS) {
>> dev_err(dev, "Too many PCI slots!\n");
>> - ret = -EINVAL;
>> - goto put_node;
>> + return -EINVAL;
> Perhaps a future change, but this would be nicer as
> return dev_err_probe(dev, -EINVAL,
> "Too many PCI slots!\n");
> Maybe as part of a general change to this driver to use
> dev_err_probe() for all the error prints in paths only called
> from probe().
>
Yeah, it seems that other paths that have nothing to do with this fix
would require the same modification.
Best regards,
Javier Carrasco
next prev parent reply other threads:[~2024-07-05 11:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-09 10:56 [PATCH] PCI: kirin: fix memory leak in kirin_pcie_parse_port() Javier Carrasco
2024-06-11 13:50 ` Andy Shevchenko
2024-06-12 4:40 ` Manivannan Sadhasivam
2024-07-04 14:50 ` Javier Carrasco
2024-07-04 14:57 ` Krzysztof Wilczyński
2024-07-05 10:18 ` Jonathan Cameron
2024-07-05 11:29 ` Javier Carrasco [this message]
2024-07-06 3:15 ` Krzysztof Wilczyński
2024-07-06 3:13 ` Krzysztof Wilczyński
2024-07-09 23:37 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d061d545-4694-4d5b-86fa-03d1f7251b45@gmail.com \
--to=javier.carrasco.cruz@gmail.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=kw@linux.com \
--cc=kwilczynski@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=robh@kernel.org \
--cc=songxiaowei@hisilicon.com \
--cc=wangbinghui@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox