]> asedeno.scripts.mit.edu Git - linux.git/commit
coccinelle: catch krealloc() on devm_*() allocated memory
authorYann Droneaud <ydroneaud@opteya.com>
Mon, 23 May 2016 15:07:21 +0000 (17:07 +0200)
committerMichal Marek <mmarek@suse.com>
Tue, 21 Jun 2016 09:43:32 +0000 (11:43 +0200)
commitb7b2ee41f300b69c67c798df0cd5b8648bcb26a3
treebeec6c46f805fd36a2a9b0386adb7f9ea1da91a8
parenta720c0644d14011d3a1bcc8d1b36e80571ad2ce1
coccinelle: catch krealloc() on devm_*() allocated memory

krealloc() must not be used against devm_*() allocated
memory regions:

- if a bigger memory is to be allocated, krealloc() and
  __krealloc() could return a different pointer than the
  one given to them, creating a memory region which is not
  managed, thus it will not be automatically released on
  device removal.

- if a bigger memory is to be allocated, krealloc() could
  kfree() the managed memory region which is passed to it.
  The old pointer is left registered as a resource for the
  device. On device removal, this dangling pointer will be
  used and an unrelated memory region could be released.

- if the requested size is equal to 0, krealloc() can also
  just behave like kfree(). Here too, the old pointer is
  kept associated with the device. On device removal, this
  invalid pointer will be used and an unrelated memory
  region could be released.

For all these reasons, krealloc() must not be used on a
pointer returned by devm_*() functions.

Cc: Tejun Heo <tj@kernel.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
scripts/coccinelle/free/devm_free.cocci