From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755539AbcBPRUF (ORCPT ); Tue, 16 Feb 2016 12:20:05 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:13376 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751619AbcBPRUC (ORCPT ); Tue, 16 Feb 2016 12:20:02 -0500 X-IronPort-AV: E=Sophos;i="5.22,456,1449529200"; d="scan'208";a="203382872" Date: Tue, 16 Feb 2016 18:19:52 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Yann Droneaud cc: Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek , Tejun Heo , Greg Kroah-Hartman , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Pekka Enberg Subject: Re: [PATCH 3/3] coccinelle: catch krealloc() on devm_*() allocated memory In-Reply-To: <5783128fc07898adc6860a398fc4f4e0893bc91a.1455638829.git.ydroneaud@opteya.com> Message-ID: References: <5783128fc07898adc6860a398fc4f4e0893bc91a.1455638829.git.ydroneaud@opteya.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 Feb 2016, Yann Droneaud wrote: > 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 > Cc: Pekka Enberg > Signed-off-by: Yann Droneaud Acked-by: Julia Lawall > --- > scripts/coccinelle/free/devm_free.cocci | 4 ++++ > 1 file changed, 4 insertions(+) > > 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) > -- > 2.5.0 > >