From: Yann Droneaud Date: Mon, 23 May 2016 15:07:21 +0000 (+0200) Subject: UPSTREAM: coccinelle: catch krealloc() on devm_*() allocated memory X-Git-Tag: release-20171130_firefly~4^2~215 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d3dd61f590f6fa27f1757008852e51ca7590092c;p=firefly-linux-kernel-4.4.55.git UPSTREAM: 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. Change-Id: I36061f5668a1b1128df9414b577150281f0f8a5a Cc: Tejun Heo Cc: Pekka Enberg Acked-by: Julia Lawall Signed-off-by: Yann Droneaud Signed-off-by: Michal Marek Signed-off-by: Huang, Tao (cherry picked from commit b7b2ee41f300b69c67c798df0cd5b8648bcb26a3) --- diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci index 3794cd97494b..c990d2c7ee16 100644 --- a/scripts/coccinelle/free/devm_free.cocci +++ b/scripts/coccinelle/free/devm_free.cocci @@ -66,6 +66,10 @@ position p; | * kzfree@p(x) | +* __krealloc@p(x, ...) +| +* krealloc@p(x, ...) +| * free_pages@p(x, ...) | * free_page@p(x)