[PATCH] firewire: core: reduce stack usage in bus reset tasklet

From: Stefan Richter
Date: Fri Aug 28 2009 - 09:20:58 EST


fw_compute_block_crc() used 1024 bytes of the kernel stack. This
function is called
- in process context when the local node's config ROM is updated,
- in tasklet context of the bus reset handler.

Replace the stack-allocated buffer by a static buffer.
Serialize buffer accesses by a static local spinlock.

Signed-off-by: Stefan Richter <stefanr@xxxxxxxxxxxxxxxxx>
---
drivers/firewire/core-card.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

Index: linux-2.6.31-rc8/drivers/firewire/core-card.c
===================================================================
--- linux-2.6.31-rc8.orig/drivers/firewire/core-card.c
+++ linux-2.6.31-rc8/drivers/firewire/core-card.c
@@ -40,13 +40,19 @@

int fw_compute_block_crc(u32 *block)
{
- __be32 be32_block[256];
+ static DEFINE_SPINLOCK(buffer_lock);
+ static __be32 buffer[256];
+ unsigned long flags;
int i, length;

+ spin_lock_irqsave(&buffer_lock, flags);
+
length = (*block >> 16) & 0xff;
for (i = 0; i < length; i++)
- be32_block[i] = cpu_to_be32(block[i + 1]);
- *block |= crc_itu_t(0, (u8 *) be32_block, length * 4);
+ buffer[i] = cpu_to_be32(block[i + 1]);
+ *block |= crc_itu_t(0, (u8 *)buffer, length * 4);
+
+ spin_unlock_irqrestore(&buffer_lock, flags);

return length;
}

--
Stefan Richter
-=====-==--= =--- ===--
http://arcgraph.de/sr/

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/