Skip to content

Commit

Permalink
omap_hwmod: use a terminator record with omap_hwmod_mpu_irqs arrays
Browse files Browse the repository at this point in the history
Previously, struct omap_hwmod_mpu_irqs arrays were unterminated; and
users of these arrays used the ARRAY_SIZE() macro to determine the
length of the array.  However, ARRAY_SIZE() only works when the array
is in the same scope as the macro user.

So far this hasn't been a problem.  However, to reduce duplicated
data, a subsequent patch will move common data to a separate, shared
file.  When this is done, ARRAY_SIZE() will no longer be usable.

This patch removes ARRAY_SIZE() usage for struct omap_hwmod_mpu_irqs
arrays and uses a sentinel value (irq == -1) as the array terminator
instead.

Signed-off-by: Paul Walmsley <paul@pwsan.com>
  • Loading branch information
Paul Walmsley committed Jul 10, 2011
1 parent ded1138 commit 212738a
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 180 deletions.
30 changes: 27 additions & 3 deletions arch/arm/mach-omap2/omap_hwmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,29 @@ static void _disable_optional_clocks(struct omap_hwmod *oh)
}
}

/**
* _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
* @oh: struct omap_hwmod *oh
*
* Count and return the number of MPU IRQs associated with the hwmod
* @oh. Used to allocate struct resource data. Returns 0 if @oh is
* NULL.
*/
static int _count_mpu_irqs(struct omap_hwmod *oh)
{
struct omap_hwmod_irq_info *ohii;
int i = 0;

if (!oh || !oh->mpu_irqs)
return 0;

do {
ohii = &oh->mpu_irqs[i++];
} while (ohii->irq != -1);

return i;
}

/**
* _count_ocp_if_addr_spaces - count the number of address space entries for @oh
* @oh: struct omap_hwmod *oh
Expand Down Expand Up @@ -1964,7 +1987,7 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh)
{
int ret, i;

ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
ret = _count_mpu_irqs(oh) + oh->sdma_reqs_cnt;

for (i = 0; i < oh->slaves_cnt; i++)
ret += _count_ocp_if_addr_spaces(oh->slaves[i]);
Expand All @@ -1984,12 +2007,13 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh)
*/
int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
{
int i, j;
int i, j, mpu_irqs_cnt;
int r = 0;

/* For each IRQ, DMA, memory area, fill in array.*/

for (i = 0; i < oh->mpu_irqs_cnt; i++) {
mpu_irqs_cnt = _count_mpu_irqs(oh);
for (i = 0; i < mpu_irqs_cnt; i++) {
(res + r)->name = (oh->mpu_irqs + i)->name;
(res + r)->start = (oh->mpu_irqs + i)->irq;
(res + r)->end = (oh->mpu_irqs + i)->irq;
Expand Down
Loading

0 comments on commit 212738a

Please sign in to comment.