From: Jason Gunthorpe <jgg@nvidia.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Brice Goglin <Brice.Goglin@inria.fr>,
Keith Busch <kbusch@kernel.org>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] node: fix device cleanups in error handling code
Date: Fri, 16 Apr 2021 16:35:35 -0300 [thread overview]
Message-ID: <20210416193535.GO1370958@nvidia.com> (raw)
In-Reply-To: <YHA0JUra+F64+NpB@mwanda>
On Fri, Apr 09, 2021 at 02:01:57PM +0300, Dan Carpenter wrote:
> We can't use kfree() to free device managed resources so the kfree(dev)
> is against the rules.
>
> It's easier to write this code if we open code the device_register() as
> a device_initialize() and device_add(). That way if dev_set_name() set
> name fails we can call put_device() and it will clean up correctly.
>
> Fixes: acc02a109b04 ("node: Add memory-side caching attributes")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/base/node.c | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
Wow, yikes, that "kfree_const(dev->kobj.name);" is really creative
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Though I dislike ignoring the error code from dev_set_name(), I think
Greg would prefer this:
diff --git a/drivers/base/node.c b/drivers/base/node.c
index f449dbb2c74666..80079e440add12 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -140,20 +140,16 @@ static struct node_access_nodes *node_init_node_access(struct node *node,
dev->parent = &node->dev;
dev->release = node_access_release;
dev->groups = node_access_node_groups;
- if (dev_set_name(dev, "access%u", access))
- goto free;
- if (device_register(dev))
- goto free_name;
+ dev_set_name(dev, "access%u", access);
+ if (device_register(dev)) {
+ put_device(dev);
+ return NULL;
+ }
pm_runtime_no_callbacks(dev);
list_add_tail(&access_node->list_node, &node->access_list);
return access_node;
-free_name:
- kfree_const(dev->kobj.name);
-free:
- kfree(access_node);
- return NULL;
}
(arguably a device_register_name() would be even better, if you are
handy with coccinelle there could quickly be alot of users)
Jason
prev parent reply other threads:[~2021-04-16 19:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-09 11:01 [PATCH] node: fix device cleanups in error handling code Dan Carpenter
2021-04-16 19:35 ` Jason Gunthorpe [this message]
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=20210416193535.GO1370958@nvidia.com \
--to=jgg@nvidia.com \
--cc=Brice.Goglin@inria.fr \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=kbusch@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/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