DMA Engine development
 help / color / mirror / Atom feed
From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
To: Paul Cercueil <paul@crapouillou.net>
Cc: madhuparnabhowmik10@gmail.com, dan.j.williams@intel.com,
	vkoul@kernel.org, dmaengine@vger.kernel.org,
	linux-kernel@vger.kernel.org, andrianov@ispras.ru,
	ldv-project@linuxtesting.org
Subject: Re: [PATCH] drivers/dma/dma-jz4780: Fix race condition between probe and irq handler
Date: Thu, 20 Aug 2020 23:22:28 +0530	[thread overview]
Message-ID: <20200820175228.GA7168@madhuparna-HP-Notebook> (raw)
In-Reply-To: <ZM2DFQ.KQQJYLJ02WTD3@crapouillou.net>

On Thu, Aug 20, 2020 at 01:59:23PM +0200, Paul Cercueil wrote:
> Hi,
> 
> Le dim. 16 août 2020 à 12:52, madhuparnabhowmik10@gmail.com a écrit :
> > From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> > 
> > In probe IRQ is requested before zchan->id is initialized which can be
> > read in the irq handler. Hence, shift request irq and enable clock after
> > other initializations complete. Here, enable clock part is not part of
> > the race, it is just shifted down after request_irq to keep the error
> > path same as before.
> > 
> > Found by Linux Driver Verification project (linuxtesting.org).
> > 
> > Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> 
> I don't think there is a race at all, the interrupt handler won't be called
> before the DMA is registered.
> 
> More importantly, this patch will break things, as there are now register
> writes in the probe before the clock is enabled.
>
Okay, thanks for reviewing the patch anyway, and sorry for the trouble.

Regards,
Madhuparna
> Cheers,
> -Paul
> 
> > ---
> >  drivers/dma/dma-jz4780.c | 44 ++++++++++++++++++++--------------------
> >  1 file changed, 22 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
> > index 448f663da89c..5cbc8c3bd6c7 100644
> > --- a/drivers/dma/dma-jz4780.c
> > +++ b/drivers/dma/dma-jz4780.c
> > @@ -879,28 +879,6 @@ static int jz4780_dma_probe(struct platform_device
> > *pdev)
> >  		return -EINVAL;
> >  	}
> > 
> > -	ret = platform_get_irq(pdev, 0);
> > -	if (ret < 0)
> > -		return ret;
> > -
> > -	jzdma->irq = ret;
> > -
> > -	ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0,
> > dev_name(dev),
> > -			  jzdma);
> > -	if (ret) {
> > -		dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq);
> > -		return ret;
> > -	}
> > -
> > -	jzdma->clk = devm_clk_get(dev, NULL);
> > -	if (IS_ERR(jzdma->clk)) {
> > -		dev_err(dev, "failed to get clock\n");
> > -		ret = PTR_ERR(jzdma->clk);
> > -		goto err_free_irq;
> > -	}
> > -
> > -	clk_prepare_enable(jzdma->clk);
> > -
> >  	/* Property is optional, if it doesn't exist the value will remain 0.
> > */
> >  	of_property_read_u32_index(dev->of_node, "ingenic,reserved-channels",
> >  				   0, &jzdma->chan_reserved);
> > @@ -949,6 +927,28 @@ static int jz4780_dma_probe(struct platform_device
> > *pdev)
> >  		jzchan->vchan.desc_free = jz4780_dma_desc_free;
> >  	}
> > 
> > +	ret = platform_get_irq(pdev, 0);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	jzdma->irq = ret;
> > +
> > +	ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0,
> > dev_name(dev),
> > +			  jzdma);
> > +	if (ret) {
> > +		dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq);
> > +		return ret;
> > +	}
> > +
> > +	jzdma->clk = devm_clk_get(dev, NULL);
> > +	if (IS_ERR(jzdma->clk)) {
> > +		dev_err(dev, "failed to get clock\n");
> > +		ret = PTR_ERR(jzdma->clk);
> > +		goto err_free_irq;
> > +	}
> > +
> > +	clk_prepare_enable(jzdma->clk);
> > +
> >  	ret = dmaenginem_async_device_register(dd);
> >  	if (ret) {
> >  		dev_err(dev, "failed to register device\n");
> > --
> > 2.17.1
> > 
> 
> 

  reply	other threads:[~2020-08-20 17:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-16  7:22 [PATCH] drivers/dma/dma-jz4780: Fix race condition between probe and irq handler madhuparnabhowmik10
2020-08-20 11:59 ` Paul Cercueil
2020-08-20 17:52   ` Madhuparna Bhowmik [this message]
2020-08-20 18:23   ` Lars-Peter Clausen
2020-08-20 18:46     ` Paul Cercueil
2020-08-21  3:16       ` Madhuparna Bhowmik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200820175228.GA7168@madhuparna-HP-Notebook \
    --to=madhuparnabhowmik10@gmail.com \
    --cc=andrianov@ispras.ru \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox