lkml.org 
[lkml]   [2013]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] devres: Freeing the drs after all release() are called
On Thu, Nov 07, 2013 at 12:36:56AM +0000, Liu, Chuansheng wrote:
>
>
> > -----Original Message-----
> > From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of tj@kernel.org
> > Sent: Thursday, November 07, 2013 8:30 AM
> > To: Liu, Chuansheng
> > Cc: Greg KH; dmitry.torokhov@gmail.com; linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH] devres: Freeing the drs after all release() are called
> >
> > Hello, Liu.
> >
> > On Thu, Nov 07, 2013 at 12:27:56AM +0000, Liu, Chuansheng wrote:
> > > The driver code is as below:
> > > _INIT() {
> > >
> > > A = devm_kzalloc();
> > > B= devm_request_threaded_irq(isr_handler);
> > > C = devm_kzalloc();
> > > }
> > >
> > > When driver _EXIT, the devres_release_all () will be called.
> > > The C will be kfreed before B, but when freeing irq B, the pending isr_handler()
> > possibly
> > > will access the memory B which has been freed.
> > > Then the memory corruption occurred.
> > >
> > > This patch can solve this scenario.
> >
> > Isn't the bug there IRQ being requested before all its resources are
> > allocated? The proposed change just masks the underlying issue or
> > incorrectly ordered operations.
> Yes, I knew I can put the code always like below:
> A = devm_kzalloc();
> C = devm_kzalloc();
> ...
> B= devm_request_threaded_irq(isr_handler);
>
> But, the above is just one simple coding prototype, if there are many calling:
> E -- > F -- > D -- >... then to devm_kzalloc().
>
> To be honest, it will make code too hard to always adapt the rule?
> And I trying to find out every potential devm_kzalloc() before irq requesting.

Such code is already broken anyway and has to be fixed - if your IRQ
handler accesses data allocated by devm_kzalloc that you call only
_after_ you called devm_request_irq() then interrupt arriving at
unfortunate moment will crash your driver at the probing stage.

Thanks.

--
Dmitry


\
 
 \ /
  Last update: 2013-11-07 02:21    [W:0.068 / U:0.504 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site