From: Keith Busch <kbusch@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [bug report] node: Add memory-side caching attributes
Date: Fri, 2 Apr 2021 06:27:53 +0900 [thread overview]
Message-ID: <20210401212753.GB31698@redsun51.ssa.fujisawa.hgst.com> (raw)
In-Reply-To: <YGWLtzMLqSW4cxma@mwanda>
On Thu, Apr 01, 2021 at 12:00:39PM +0300, Dan Carpenter wrote:
> Hi Keith,
>
> I've been trying to figure out ways Smatch can check for device managed
> resources. Like adding rules that if we call dev_set_name(&foo->bar)
> then it's device managaged and if there is a kfree(foo) without calling
> device_put(&foo->bar) then that's a resource leak.
>
> Of course one of the rules is that if you call device_register(dev) then
> you can't kfree(dev), it has to released with device_put(dev) and that's
> true even if the register fails. But this code here feels very
> intentional so maybe there is an exception to the rule?
Thanks for the notice. There was no intentional use of this, so I
think it was a mistake. The proposal in the follow on replies looks much
better.
> The patch acc02a109b04: "node: Add memory-side caching attributes"
> from Mar 11, 2019, leads to the following static checker warning:
>
> drivers/base/node.c:285 node_init_cache_dev()
> error: kfree after device_register(): 'dev'
>
> drivers/base/node.c
> 263 static void node_init_cache_dev(struct node *node)
> 264 {
> 265 struct device *dev;
> 266
> 267 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> 268 if (!dev)
> 269 return;
> 270
> 271 dev->parent = &node->dev;
> 272 dev->release = node_cache_release;
> 273 if (dev_set_name(dev, "memory_side_cache"))
> 274 goto free_dev;
> 275
> 276 if (device_register(dev))
> ^^^^^^^^^^^^^^^^^^^
> 277 goto free_name;
> 278
> 279 pm_runtime_no_callbacks(dev);
> 280 node->cache_dev = dev;
> 281 return;
> 282 free_name:
> 283 kfree_const(dev->kobj.name);
> 284 free_dev:
> 285 kfree(dev);
> ^^^^^^^^^^
> 286 }
>
> regards,
> dan carpenter
prev parent reply other threads:[~2021-04-01 21:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-01 9:00 [bug report] node: Add memory-side caching attributes Dan Carpenter
2021-04-01 11:25 ` Jason Gunthorpe
2021-04-01 14:06 ` Dan Carpenter
2021-04-01 15:22 ` Jason Gunthorpe
2021-04-01 21:27 ` Keith Busch [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=20210401212753.GB31698@redsun51.ssa.fujisawa.hgst.com \
--to=kbusch@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=jgg@nvidia.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).