[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240801235526.GA129068@bhelgaas>
Date: Thu, 1 Aug 2024 18:55:26 -0500
From: Bjorn Helgaas <helgaas@...nel.org>
To: David Hunter <david.hunter.linux@...il.com>
Cc: bhelgaas@...gle.com, linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org, julia.lawall@...ia.fr,
skhan@...uxfoundation.org, javier.carrasco.cruz@...il.com,
Rob Herring <robh@...nel.org>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>
Subject: Re: [PATCH] of.c: replace of_node_put with __free improves cleanup
[+cc Rob, Jonathan]
On Fri, Jul 19, 2024 at 06:38:05PM -0400, David Hunter wrote:
> The use of the __free function allows the cleanup to be based on scope
> instead of on another function called later. This makes the cleanup
> automatic and less susceptible to errors later.
>
> This code was compiled without errors or warnings.
I *think* this looks OK, but I'm not comfy with all this scope magic
yet, so would like Jonathan and/or Rob to take a peek too.
And is there some way to include a hint here about how to find the
implicit of_node_put()? I think it's this from 9448e55d032d ("of: Add
cleanup.h based auto release via __free(device_node) markings"):
+DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
but it did take some looking to find it.
If it looks good, I'll tweak the commit log to use imperative mood:
https://chris.beams.io/posts/git-commit/
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=v6.9#n94
since this technically says what *could* happen but not what the patch
*does*.
> Signed-off-by: David Hunter <david.hunter.linux@...il.com>
> ---
> drivers/pci/of.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index b908fe1ae951..8b150982f5cd 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -616,16 +616,14 @@ int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
>
> void of_pci_remove_node(struct pci_dev *pdev)
> {
> - struct device_node *np;
> + struct device_node *np __free(device_node) = pci_device_to_OF_node(pdev);
>
> - np = pci_device_to_OF_node(pdev);
> if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> return;
> pdev->dev.of_node = NULL;
>
> of_changeset_revert(np->data);
> of_changeset_destroy(np->data);
> - of_node_put(np);
> }
>
> void of_pci_make_dev_node(struct pci_dev *pdev)
> --
> 2.34.1
>
Powered by blists - more mailing lists