ARM: Tegra: DMA: Fail safe if initialization fails
Subsystems (3)
PATCH 1/1 ARM: Tegra: DMA: Fail safe if initialization fails
tegra_dma_init currently simply bails out early if any initialization fails. This skips various data-structure initialization. In turn, this means that tegra_dma_allocate_channel can still hand out channels. In this case, when tegra_dma_free_channel is called, which calls tegra_dma_cancel, the walking on ch->list will OOPS since the list's next/prev pointers may still be NULL.
To solve this:
* Mark all possible channels as in-use before doing anything else in init.
* Only mark a channel as free once all channel-related initialization has completed.
This prevents allocate_channel from handing out uninitialized channels.
There is still one small hole; allocate_channel can't check the usage array for the shared channel, since this channel is permanently marked in-use. This could be solved using an explicit "init OK" flag that allocate_channel could check.
--- arch/arm/mach-tegra/dma.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
arch/arm/mach-tegra/dma.c +8 -12
@@ -678,6 +678,12 @@ int __init tegra_dma_init(void)void __iomem *addr;struct clk *c; +memset (channel_usage,0 ,sizeof (channel_usage)); +memset (dma_channels,0 ,sizeof (dma_channels)); + +for (i =0 ; i <NV_DMA_MAX_CHANNELS ; i++) +__set_bit (i, channel_usage); + c =clk_get_sys ("tegra-dma" ,NULL );if (IS_ERR (c)) {pr_err ("Unable to get clock for APB DMA\n" );
@@ -696,18 +702,9 @@ int __init tegra_dma_init(void)writel (0xFFFFFFFFul >> (31 -TEGRA_SYSTEM_DMA_CH_MAX ), addr +APB_DMA_IRQ_MASK_SET ); -memset (channel_usage,0 ,sizeof (channel_usage)); -memset (dma_channels,0 ,sizeof (dma_channels)); - -/* Reserve all the channels we are not supposed to touch */ -for (i =0 ; i <TEGRA_SYSTEM_DMA_CH_MIN ; i++) -__set_bit (i, channel_usage); -for (i =TEGRA_SYSTEM_DMA_CH_MIN ; i <=TEGRA_SYSTEM_DMA_CH_MAX ; i++) {struct tegra_dma_channel *ch = &dma_channels[i]; -__clear_bit (i, channel_usage); - ch->id = i;snprintf (ch->name,TEGRA_DMA_NAME_SIZE ,"dma_channel_%d" , i);
@@ -726,13 +723,12 @@ int __init tegra_dma_init(void) goto fail; } ch->irq = irq; + +__clear_bit (i, channel_usage); }/* mark the shared channel allocated */ __set_bit (TEGRA_SYSTEM_DMA_CH_MIN , channel_usage); -for (i =TEGRA_SYSTEM_DMA_CH_MAX +1 ; i <NV_DMA_MAX_CHANNELS ; i++) -__set_bit (i, channel_usage); -return ret; fail:writel (0 , addr +APB_DMA_GEN );
Signature · 1 line
1.7.1
PATCH 1/1 ARM: Tegra: DMA: Fail safe if initialization fails
Quoted 12 lines · Stephen Warren
tegra_dma_initcurrently simply bails out early if any initialization fails. This skips various data-structure initialization. In turn, this means thattegra_dma_allocate_channelcan still hand out channels. In this case, whentegra_dma_free_channelis called, which callstegra_dma_cancel, the walking onch->listwill OOPS since the list's next/prev pointers may still be NULL.To solve this:
* Mark all possible channels as in-use before doing anything else in init.
* Only mark a channel as free once all channel-related initialization has ?completed.
Quoted 6 lines
This prevents
allocate_channelfrom handing out uninitialized channels.There is still one small hole;
allocate_channelcan't check the usage array for the shared channel, since this channel is permanently marked in-use. This could be solved using an explicit "init OK" flag thatallocate_channelcould check.
If we still need an init complete flag, why not skip this patch and just add that?
Quoted 11 lines
Signed-off-by Stephen Warren <[email protected]>---
?arch/arm/mach-tegra/dma.c | ? 20 ++++++++------------ ?1 files changed, 8 insertions(+), 12 deletions(-)arch/arm/mach-tegra/dma.c +0
-0
arch/arm/mach-tegra/dma.c int __init tegra_dma_init(void) · line 682
Quoted 5 lines
arch/arm/mach-tegra/dma.c +2
-0@@ -678,6 +678,12 @@ int __init tegra_dma_init(void) ? ? ? ?void __iomem *addr; ? ? ? ?struct clk *c; + ? ? ? memset(channel_usage, 0, sizeof(channel_usage)); + ? ? ? memset(dma_channels, 0, sizeof(dma_channels));
I noticed yesterday these memsets were unnecessary, channel_usage and dma_channels will be allocated as 0.
Quoted 50 lines
arch/arm/mach-tegra/dma.c +6
-9+ + ? ? ? for (i = 0; i < NV_DMA_MAX_CHANNELS; i++) + ? ? ? ? ? ? ? __set_bit(i, channel_usage); + ? ? ? ?c = clk_get_sys("tegra-dma", NULL); ? ? ? ?if (IS_ERR(c)) { ? ? ? ? ? ? ? ?pr_err("Unable to get clock for APB DMA\n");@@ -696,18 +702,9 @@ int __init tegra_dma_init(void) ? ? ? ?writel(0xFFFFFFFFul >> (31 - TEGRA_SYSTEM_DMA_CH_MAX), ? ? ? ? ? ? ? addr + APB_DMA_IRQ_MASK_SET); - ? ? ? memset(channel_usage, 0, sizeof(channel_usage)); - ? ? ? memset(dma_channels, 0, sizeof(dma_channels)); - - ? ? ? /* Reserve all the channels we are not supposed to touch */ - ? ? ? for (i = 0; i < TEGRA_SYSTEM_DMA_CH_MIN; i++) - ? ? ? ? ? ? ? __set_bit(i, channel_usage); - ? ? ? ?for (i = TEGRA_SYSTEM_DMA_CH_MIN; i <= TEGRA_SYSTEM_DMA_CH_MAX; i++) { ? ? ? ? ? ? ? ?struct tegra_dma_channel *ch = &dma_channels[i]; - ? ? ? ? ? ? ? __clear_bit(i, channel_usage); - ? ? ? ? ? ? ? ?ch->id = i; ? ? ? ? ? ? ? ?snprintf(ch->name, TEGRA_DMA_NAME_SIZE, "dma_channel_%d", i);@@ -726,13 +723,12 @@ int __init tegra_dma_init(void) ? ? ? ? ? ? ? ? ? ? ? ?goto fail; ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?ch->irq = irq; + + ? ? ? ? ? ? ? __clear_bit(i, channel_usage); ? ? ? ?}? ? ? ?/* mark the shared channel allocated */
? ? ? ?__set_bit(TEGRA_SYSTEM_DMA_CH_MIN,channel_usage);- ? ? ? for (i = TEGRA_SYSTEM_DMA_CH_MAX+1; i <
NV_DMA_MAX_CHANNELS; i++)
- ? ? ? ? ? ? ?__set_bit(i, channel_usage);
-
? ? ? ?return ret;
?fail:
? ? ? ?writel(0, addr +APB_DMA_GEN);
--
1.7.1--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html
PATCH 1/1 ARM: Tegra: DMA: Fail safe if initialization fails
Colin Cross wrote at Wednesday, February 23, 2011 10:38 AM:
Quoted 16 lines · Stephen Warren
Quoted 14 lines
tegra_dma_initcurrently simply bails out early if any initialization fails. This skips various data-structure initialization. In turn, this means thattegra_dma_allocate_channelcan still hand out channels. In this case, whentegra_dma_free_channelis called, which callstegra_dma_cancel, the walking onch->listwill OOPS since the list's next/prev pointers may still be NULL.To solve this:
* Mark all possible channels as in-use before doing anything else in init.
* Only mark a channel as free once all channel-related initialization has ?completed.This prevents
allocate_channelfrom handing out uninitialized channels.
Quoted 7 lines
Quoted 4 lines
There is still one small hole;
allocate_channelcan't check the usage array for the shared channel, since this channel is permanently marked in-use. This could be solved using an explicit "init OK" flag thatallocate_channelcould check.If we still need an init complete flag, why not skip this patch and just add that?
I tend to like the cleanup in this patch; it simplifies the channel_usage initialization. I'll let you make the call on whether to take this or not.
I can certainly throw together a second patch, or modify this patch, to also use an init_ok flag to completely solve the shared channel case too though.
Signature · 1 line
nvpublic
PATCH 1/1 ARM: Tegra: DMA: Fail safe if initialization fails
Quoted 22 lines · Stephen Warren
Colin Cross wrote at Wednesday, February 23, 2011 10:38 AM:
Quoted 21 lines · Stephen Warren
Quoted 18 lines
tegra_dma_initcurrently simply bails out early if any initialization fails. This skips various data-structure initialization. In turn, this means thattegra_dma_allocate_channelcan still hand out channels. In this case, whentegra_dma_free_channelis called, which callstegra_dma_cancel, the walking onch->listwill OOPS since the list's next/prev pointers may still be NULL.To solve this:
* Mark all possible channels as in-use before doing anything else in init.
* Only mark a channel as free once all channel-related initialization has ?completed.This prevents
allocate_channelfrom handing out uninitialized channels.There is still one small hole;
allocate_channelcan't check the usage array for the shared channel, since this channel is permanently marked in-use. This could be solved using an explicit "init OK" flag thatallocate_channelcould check.
Quoted 5 lines
Quoted 2 lines
If we still need an init complete flag, why not skip this patch and just add that?
I tend to like the cleanup in this patch; it simplifies the
channel_usageinitialization. I'll let you make the call on whether to take this or not.
Ok, it seems like a reasonable cleanup. Can I request a few changes? Get rid of the redundant memsets
Replace the initial for loop to set all the bits with bitmap_set Might as well add the init complete flag to this patch as well. You could also do it by checking the channel_usage bit for the shared channel, and never setting it in tegra_dma_allocate_channel.
Quoted 7 lines
I can certainly throw together a second patch, or modify this patch, to also use an
init_okflag to completely solve the shared channel case too though.--
nvpublic