linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] node: Add memory-side caching attributes
@ 2021-04-01  9:00 Dan Carpenter
  2021-04-01 11:25 ` Jason Gunthorpe
  2021-04-01 21:27 ` Keith Busch
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-04-01  9:00 UTC (permalink / raw)
  To: kbusch; +Cc: linux-kernel, kernel-janitors, Jason Gunthorpe

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-01 21:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).