* question about drivers/dma/dma-jz4780.c
@ 2015-07-19 9:08 Julia Lawall
2015-07-20 8:18 ` Alex Smith
0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-07-19 9:08 UTC (permalink / raw)
To: Zubair.Kakakhel; +Cc: dmaengine, linux-kernel
The file drivers/dma/dma-jz4780.c has a probe function that sets up irqs
using devm_request_irq. The probe function then ends with:
err_unregister_dev:
dma_async_device_unregister(dd);
err_disable_clk:
clk_disable_unprepare(jzdma->clk);
return ret;
}
The remove function, on the other hand contains:
of_dma_controller_free(pdev->dev.of_node);
devm_free_irq(&pdev->dev, jzdma->irq, jzdma);
dma_async_device_unregister(&jzdma->dma_device);
The need for calling devm_free_irq explicitly would be that it needs to
occur before dma_async_device_unregister, to eg avoid a reference to a
dangling pointer. But devm_free_irq is implicitly called after the call
to dma_async_device_unregister at the end of the probe function. Which
one is correct?
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-19 9:08 question about drivers/dma/dma-jz4780.c Julia Lawall
@ 2015-07-20 8:18 ` Alex Smith
2015-07-20 8:28 ` Julia Lawall
0 siblings, 1 reply; 12+ messages in thread
From: Alex Smith @ 2015-07-20 8:18 UTC (permalink / raw)
To: Julia Lawall; +Cc: Zubair.Kakakhel, dmaengine, linux-kernel
On 19/07/2015 10:08, Julia Lawall wrote:
> The file drivers/dma/dma-jz4780.c has a probe function that sets up irqs
> using devm_request_irq. The probe function then ends with:
>
> err_unregister_dev:
> dma_async_device_unregister(dd);
>
> err_disable_clk:
> clk_disable_unprepare(jzdma->clk);
> return ret;
> }
>
> The remove function, on the other hand contains:
>
> of_dma_controller_free(pdev->dev.of_node);
> devm_free_irq(&pdev->dev, jzdma->irq, jzdma);
> dma_async_device_unregister(&jzdma->dma_device);
>
> The need for calling devm_free_irq explicitly would be that it needs to
> occur before dma_async_device_unregister, to eg avoid a reference to a
> dangling pointer. But devm_free_irq is implicitly called after the call
> to dma_async_device_unregister at the end of the probe function. Which
> one is correct?
>
> julia
Hi,
I think the explicit devm_free_irq() here is unnecessary, as when remove
is called there should be no remaining users of the DMA controller and
therefore no chance of an IRQ occurring between the controller being
unregistered and an implicit IRQ release afterwards.
I recently sent a series of fixes for this driver, I will send a new
version with a patch to remove the unnecessary free.
Thanks,
Alex
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-20 8:18 ` Alex Smith
@ 2015-07-20 8:28 ` Julia Lawall
2015-07-21 4:15 ` Vinod Koul
0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-07-20 8:28 UTC (permalink / raw)
To: Alex Smith; +Cc: Julia Lawall, Zubair.Kakakhel, dmaengine, linux-kernel
On Mon, 20 Jul 2015, Alex Smith wrote:
> On 19/07/2015 10:08, Julia Lawall wrote:
> > The file drivers/dma/dma-jz4780.c has a probe function that sets up irqs
> > using devm_request_irq. The probe function then ends with:
> >
> > err_unregister_dev:
> > dma_async_device_unregister(dd);
> >
> > err_disable_clk:
> > clk_disable_unprepare(jzdma->clk);
> > return ret;
> > }
> >
> > The remove function, on the other hand contains:
> >
> > of_dma_controller_free(pdev->dev.of_node);
> > devm_free_irq(&pdev->dev, jzdma->irq, jzdma);
> > dma_async_device_unregister(&jzdma->dma_device);
> >
> > The need for calling devm_free_irq explicitly would be that it needs to
> > occur before dma_async_device_unregister, to eg avoid a reference to a
> > dangling pointer. But devm_free_irq is implicitly called after the call
> > to dma_async_device_unregister at the end of the probe function. Which
> > one is correct?
> >
> > julia
>
> Hi,
>
> I think the explicit devm_free_irq() here is unnecessary, as when remove is
> called there should be no remaining users of the DMA controller and therefore
> no chance of an IRQ occurring between the controller being unregistered and an
> implicit IRQ release afterwards.
>
> I recently sent a series of fixes for this driver, I will send a new version
> with a patch to remove the unnecessary free.
Great. Thanks.
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-20 8:28 ` Julia Lawall
@ 2015-07-21 4:15 ` Vinod Koul
2015-07-22 14:26 ` Alex Smith
0 siblings, 1 reply; 12+ messages in thread
From: Vinod Koul @ 2015-07-21 4:15 UTC (permalink / raw)
To: Julia Lawall; +Cc: Alex Smith, Zubair.Kakakhel, dmaengine, linux-kernel
On Mon, Jul 20, 2015 at 10:28:14AM +0200, Julia Lawall wrote:
> On Mon, 20 Jul 2015, Alex Smith wrote:
>
> > On 19/07/2015 10:08, Julia Lawall wrote:
> > > The file drivers/dma/dma-jz4780.c has a probe function that sets up irqs
> > > using devm_request_irq. The probe function then ends with:
> > >
> > > err_unregister_dev:
> > > dma_async_device_unregister(dd);
> > >
> > > err_disable_clk:
> > > clk_disable_unprepare(jzdma->clk);
> > > return ret;
> > > }
> > >
> > > The remove function, on the other hand contains:
> > >
> > > of_dma_controller_free(pdev->dev.of_node);
> > > devm_free_irq(&pdev->dev, jzdma->irq, jzdma);
> > > dma_async_device_unregister(&jzdma->dma_device);
> > >
> > > The need for calling devm_free_irq explicitly would be that it needs to
> > > occur before dma_async_device_unregister, to eg avoid a reference to a
> > > dangling pointer. But devm_free_irq is implicitly called after the call
> > > to dma_async_device_unregister at the end of the probe function. Which
> > > one is correct?
Not just users but from a device management you are ensuring that your
device is not able to send any more interrupts and also your tasklet is not
spawned further. For this it is neccessary that devm_irq_free be called
explcitly by devices
> > >
> > > julia
> >
> > Hi,
> >
> > I think the explicit devm_free_irq() here is unnecessary, as when remove is
> > called there should be no remaining users of the DMA controller and therefore
> > no chance of an IRQ occurring between the controller being unregistered and an
> > implicit IRQ release afterwards.
Are you ensuring that device can no longer sent interrupts and all instances
of tasklet running or either completed are terminated and no further tasklet
can be spawned?
--
~Vinod
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-21 4:15 ` Vinod Koul
@ 2015-07-22 14:26 ` Alex Smith
2015-07-23 17:21 ` Vinod Koul
0 siblings, 1 reply; 12+ messages in thread
From: Alex Smith @ 2015-07-22 14:26 UTC (permalink / raw)
To: Vinod Koul; +Cc: Julia Lawall, Zubair.Kakakhel, dmaengine, linux-kernel
On 21/07/2015 05:15, Vinod Koul wrote:
> On Mon, Jul 20, 2015 at 10:28:14AM +0200, Julia Lawall wrote:
>> On Mon, 20 Jul 2015, Alex Smith wrote:
>>
>>> On 19/07/2015 10:08, Julia Lawall wrote:
>>>> The file drivers/dma/dma-jz4780.c has a probe function that sets up irqs
>>>> using devm_request_irq. The probe function then ends with:
>>>>
>>>> err_unregister_dev:
>>>> dma_async_device_unregister(dd);
>>>>
>>>> err_disable_clk:
>>>> clk_disable_unprepare(jzdma->clk);
>>>> return ret;
>>>> }
>>>>
>>>> The remove function, on the other hand contains:
>>>>
>>>> of_dma_controller_free(pdev->dev.of_node);
>>>> devm_free_irq(&pdev->dev, jzdma->irq, jzdma);
>>>> dma_async_device_unregister(&jzdma->dma_device);
>>>>
>>>> The need for calling devm_free_irq explicitly would be that it needs to
>>>> occur before dma_async_device_unregister, to eg avoid a reference to a
>>>> dangling pointer. But devm_free_irq is implicitly called after the call
>>>> to dma_async_device_unregister at the end of the probe function. Which
>>>> one is correct?
> Not just users but from a device management you are ensuring that your
> device is not able to send any more interrupts and also your tasklet is not
> spawned further. For this it is neccessary that devm_irq_free be called
> explcitly by devices
>>>>
>>>> julia
>>>
>>> Hi,
>>>
>>> I think the explicit devm_free_irq() here is unnecessary, as when remove is
>>> called there should be no remaining users of the DMA controller and therefore
>>> no chance of an IRQ occurring between the controller being unregistered and an
>>> implicit IRQ release afterwards.
> Are you ensuring that device can no longer sent interrupts and all instances
> of tasklet running or either completed are terminated and no further tasklet
> can be spawned?
Hi Vinod,
If I understand correctly, when remove() is called, there should be no
more users of the DMA controller, enforced by the module reference count.
Wouldn't that guarantee that there are no more transactions running and
therefore no chance of an interrupt from the controller or a tasklet
still running?
Thanks,
Alex
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-22 14:26 ` Alex Smith
@ 2015-07-23 17:21 ` Vinod Koul
2015-07-23 17:24 ` Julia Lawall
0 siblings, 1 reply; 12+ messages in thread
From: Vinod Koul @ 2015-07-23 17:21 UTC (permalink / raw)
To: Alex Smith; +Cc: Julia Lawall, Zubair.Kakakhel, dmaengine, linux-kernel
On Wed, Jul 22, 2015 at 03:26:01PM +0100, Alex Smith wrote:
> >>>I think the explicit devm_free_irq() here is unnecessary, as when remove is
> >>>called there should be no remaining users of the DMA controller and therefore
> >>>no chance of an IRQ occurring between the controller being unregistered and an
> >>>implicit IRQ release afterwards.
> >Are you ensuring that device can no longer sent interrupts and all instances
> >of tasklet running or either completed are terminated and no further tasklet
> >can be spawned?
>
> Hi Vinod,
>
> If I understand correctly, when remove() is called, there should be
> no more users of the DMA controller, enforced by the module
> reference count.
>
> Wouldn't that guarantee that there are no more transactions running
> and therefore no chance of an interrupt from the controller or a
> tasklet still running?
That will only guarantee no new requests are recieved, but you may have
tasklet already scheduled or irq sent from HW how do you prevent that?
--
~Vinod
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-23 17:21 ` Vinod Koul
@ 2015-07-23 17:24 ` Julia Lawall
2015-07-24 5:42 ` Vinod Koul
0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-07-23 17:24 UTC (permalink / raw)
To: Vinod Koul
Cc: Alex Smith, Zubair.Kakakhel, dmaengine, Vaishali Thakkar,
linux-kernel
On Thu, 23 Jul 2015, Vinod Koul wrote:
> On Wed, Jul 22, 2015 at 03:26:01PM +0100, Alex Smith wrote:
>
> > >>>I think the explicit devm_free_irq() here is unnecessary, as when remove is
> > >>>called there should be no remaining users of the DMA controller and therefore
> > >>>no chance of an IRQ occurring between the controller being unregistered and an
> > >>>implicit IRQ release afterwards.
> > >Are you ensuring that device can no longer sent interrupts and all instances
> > >of tasklet running or either completed are terminated and no further tasklet
> > >can be spawned?
> >
> > Hi Vinod,
> >
> > If I understand correctly, when remove() is called, there should be
> > no more users of the DMA controller, enforced by the module
> > reference count.
> >
> > Wouldn't that guarantee that there are no more transactions running
> > and therefore no chance of an interrupt from the controller or a
> > tasklet still running?
>
> That will only guarantee no new requests are recieved, but you may have
> tasklet already scheduled or irq sent from HW how do you prevent that?
More genrally, I have seen another driver with synchronize_irq in the
remove function (dma/img-mdc-dma.c). Would that be safe enough? On the
other hand, if one is going to go to the trouble of putting that, maybe
one would do just as well to drop the devm for irqs and use free_irq in
place of synchronize_irq instead?
thanks,
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-23 17:24 ` Julia Lawall
@ 2015-07-24 5:42 ` Vinod Koul
2015-07-24 5:51 ` Julia Lawall
0 siblings, 1 reply; 12+ messages in thread
From: Vinod Koul @ 2015-07-24 5:42 UTC (permalink / raw)
To: Julia Lawall
Cc: Alex Smith, Zubair.Kakakhel, dmaengine, Vaishali Thakkar,
linux-kernel
On Thu, Jul 23, 2015 at 07:24:10PM +0200, Julia Lawall wrote:
>
>
> On Thu, 23 Jul 2015, Vinod Koul wrote:
>
> > On Wed, Jul 22, 2015 at 03:26:01PM +0100, Alex Smith wrote:
> >
> > > >>>I think the explicit devm_free_irq() here is unnecessary, as when remove is
> > > >>>called there should be no remaining users of the DMA controller and therefore
> > > >>>no chance of an IRQ occurring between the controller being unregistered and an
> > > >>>implicit IRQ release afterwards.
> > > >Are you ensuring that device can no longer sent interrupts and all instances
> > > >of tasklet running or either completed are terminated and no further tasklet
> > > >can be spawned?
> > >
> > > Hi Vinod,
> > >
> > > If I understand correctly, when remove() is called, there should be
> > > no more users of the DMA controller, enforced by the module
> > > reference count.
> > >
> > > Wouldn't that guarantee that there are no more transactions running
> > > and therefore no chance of an interrupt from the controller or a
> > > tasklet still running?
> >
> > That will only guarantee no new requests are recieved, but you may have
> > tasklet already scheduled or irq sent from HW how do you prevent that?
>
> More genrally, I have seen another driver with synchronize_irq in the
> remove function (dma/img-mdc-dma.c). Would that be safe enough? On the
> other hand, if one is going to go to the trouble of putting that, maybe
> one would do just as well to drop the devm for irqs and use free_irq in
> place of synchronize_irq instead?
synchronize_irq() will take care of irq but not tasklet right. Also irq can
be triggered again as you haven't disabled that yet.
Is it really worth the trouble going though hoops to ensure your device is
in right state, so might be simpler to free the irq and kill tasklet
Yes for dmaengine drivers I do ask this question which typically ends up in
driver invoking devm_irq_free() in driver's remove callback
IMHO don't think devm irq calls are very useful, they do make stuff complicated
--
~Vinod
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-24 5:42 ` Vinod Koul
@ 2015-07-24 5:51 ` Julia Lawall
2015-07-24 6:30 ` Vinod Koul
0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-07-24 5:51 UTC (permalink / raw)
To: Vinod Koul
Cc: Alex Smith, Zubair.Kakakhel, dmaengine, Vaishali Thakkar,
linux-kernel
> Yes for dmaengine drivers I do ask this question which typically ends up in
> driver invoking devm_irq_free() in driver's remove callback
>
> IMHO don't think devm irq calls are very useful, they do make stuff
> complicate
Would it be better then to just go back to request_irq (or whatever is
appropriate in this case). It would seem that the devm property can never
be relied on, so there is no point to use it.
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-24 5:51 ` Julia Lawall
@ 2015-07-24 6:30 ` Vinod Koul
2015-07-24 6:49 ` Julia Lawall
2015-07-24 8:28 ` Alex Smith
0 siblings, 2 replies; 12+ messages in thread
From: Vinod Koul @ 2015-07-24 6:30 UTC (permalink / raw)
To: Julia Lawall
Cc: Alex Smith, Zubair.Kakakhel, dmaengine, Vaishali Thakkar,
linux-kernel
On Fri, Jul 24, 2015 at 07:51:28AM +0200, Julia Lawall wrote:
> > Yes for dmaengine drivers I do ask this question which typically ends up in
> > driver invoking devm_irq_free() in driver's remove callback
> >
> > IMHO don't think devm irq calls are very useful, they do make stuff
> > complicate
>
> Would it be better then to just go back to request_irq (or whatever is
> appropriate in this case). It would seem that the devm property can never
> be relied on, so there is no point to use it.
Yes I do think that is right way in this case
--
~Vinod
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-24 6:30 ` Vinod Koul
@ 2015-07-24 6:49 ` Julia Lawall
2015-07-24 8:28 ` Alex Smith
1 sibling, 0 replies; 12+ messages in thread
From: Julia Lawall @ 2015-07-24 6:49 UTC (permalink / raw)
To: Vinod Koul
Cc: Julia Lawall, Alex Smith, Zubair.Kakakhel, dmaengine,
Vaishali Thakkar, linux-kernel
On Fri, 24 Jul 2015, Vinod Koul wrote:
> On Fri, Jul 24, 2015 at 07:51:28AM +0200, Julia Lawall wrote:
> > > Yes for dmaengine drivers I do ask this question which typically ends up in
> > > driver invoking devm_irq_free() in driver's remove callback
> > >
> > > IMHO don't think devm irq calls are very useful, they do make stuff
> > > complicate
> >
> > Would it be better then to just go back to request_irq (or whatever is
> > appropriate in this case). It would seem that the devm property can never
> > be relied on, so there is no point to use it.
>
> Yes I do think that is right way in this case
Thanks for your help.
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: question about drivers/dma/dma-jz4780.c
2015-07-24 6:30 ` Vinod Koul
2015-07-24 6:49 ` Julia Lawall
@ 2015-07-24 8:28 ` Alex Smith
1 sibling, 0 replies; 12+ messages in thread
From: Alex Smith @ 2015-07-24 8:28 UTC (permalink / raw)
To: Vinod Koul, Julia Lawall
Cc: Zubair.Kakakhel, dmaengine, Vaishali Thakkar, linux-kernel
On 24/07/2015 07:30, Vinod Koul wrote:
> On Fri, Jul 24, 2015 at 07:51:28AM +0200, Julia Lawall wrote:
>>> Yes for dmaengine drivers I do ask this question which typically ends up in
>>> driver invoking devm_irq_free() in driver's remove callback
>>>
>>> IMHO don't think devm irq calls are very useful, they do make stuff
>>> complicate
>>
>> Would it be better then to just go back to request_irq (or whatever is
>> appropriate in this case). It would seem that the devm property can never
>> be relied on, so there is no point to use it.
>
> Yes I do think that is right way in this case
>
Hmm, OK, I will drop the patch I submitted removing the explicit
devm_free_irq() call and send a new one which stops using the devm IRQ
functions, and kills the tasklets.
Thanks,
Alex
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-07-24 8:28 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-19 9:08 question about drivers/dma/dma-jz4780.c Julia Lawall
2015-07-20 8:18 ` Alex Smith
2015-07-20 8:28 ` Julia Lawall
2015-07-21 4:15 ` Vinod Koul
2015-07-22 14:26 ` Alex Smith
2015-07-23 17:21 ` Vinod Koul
2015-07-23 17:24 ` Julia Lawall
2015-07-24 5:42 ` Vinod Koul
2015-07-24 5:51 ` Julia Lawall
2015-07-24 6:30 ` Vinod Koul
2015-07-24 6:49 ` Julia Lawall
2015-07-24 8:28 ` Alex Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox