All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbusch@kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Jason Gunthorpe <jgg@nvidia.com>
Subject: [bug report] node: Add memory-side caching attributes
Date: Thu, 1 Apr 2021 12:00:39 +0300	[thread overview]
Message-ID: <YGWLtzMLqSW4cxma@mwanda> (raw)

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?

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

             reply	other threads:[~2021-04-01  9:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  9:00 Dan Carpenter [this message]
2021-04-01 11:25 ` [bug report] node: Add memory-side caching attributes Jason Gunthorpe
2021-04-01 14:06   ` Dan Carpenter
2021-04-01 15:22     ` Jason Gunthorpe
2021-04-01 21:27 ` Keith Busch
  -- strict thread matches above, loose matches on Subject: below --
2020-02-05  5:11 Dan Carpenter

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=YGWLtzMLqSW4cxma@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=jgg@nvidia.com \
    --cc=kbusch@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.