Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1736638

Re: [PATCH v4 2/4] dmaengine: Add STM32 DMAMUX driver

From Pierre Yves MORDRET <pierre-yves.mordret@st.com>
Newsgroups linux.kernel
Subject Re: [PATCH v4 2/4] dmaengine: Add STM32 DMAMUX driver
Date 2017-09-21 14:50 +0200
Message-ID <us95w-13h-15@gated-at.bofh.it> (permalink)
References <un3Dr-7Vp-3@gated-at.bofh.it> <un3Dr-7Vp-5@gated-at.bofh.it> <us7Q7-kv-33@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 09/21/2017 01:25 PM, Peter Ujfalusi wrote:
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> 
> 
> Great that you got it working w/o a custom API!
> I have one comment, which actually valid for the ti-dma-crossbar driver
> as well...

Yes. That cleans up a little bit the sw architecture. But still this custom API
allowed both DMAMUX and DMA at the same time since using the same channel ID
allocator.
Ok this is another story to be addressed out of this thread ;)

> 
>> +static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
>> +					 struct of_dma *ofdma)
>> +
>> +	spin_lock_irqsave(&dmamux->lock, flags);
>> +	mux->chan_id = find_first_zero_bit(dmamux->dma_inuse,
>> +					   dmamux->dma_requests);
> 
> you pick the first available chan_id here under the lock.
> 
>> +	spin_unlock_irqrestore(&dmamux->lock, flags);
>> +	if (mux->chan_id == dmamux->dma_requests) {
>> ...
>> +	/* Set dma request */
>> +	spin_lock_irqsave(&dmamux->lock, flags);
>> +	if (!IS_ERR(dmamux->clk)) {
>> ...
>> +	spin_unlock_irqrestore(&dmamux->lock, flags);
>> +
>> +	set_bit(mux->chan_id, dmamux->dma_inuse);
> 
> But nothing stops other parallel threads to pick the same chan_id since
> you have released the lock (released, got the lock to protect the set
> dma request and released it again). imho the find_first_zero_bit() and
> the set_bit() should be done within the same lock to avoid race conditions.
> 
> - Péter
> 

Yep good catch : That's correct. Even if probability to happen is rather low, it
may happen.
Will solve that.

Py

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: [PATCH v4 2/4] dmaengine: Add STM32 DMAMUX driver Peter Ujfalusi <peter.ujfalusi@ti.com> - 2017-09-21 13:30 +0200
  Re: [PATCH v4 2/4] dmaengine: Add STM32 DMAMUX driver Pierre Yves MORDRET <pierre-yves.mordret@st.com> - 2017-09-21 14:50 +0200

csiph-web