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



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/



Relevant Pages

  • Re: About the NEITHER method to read and write data
    ... process context change occurs you are in trouble, ... Second you have to validate the buffer pointer yourself, ...
    (microsoft.public.development.device.drivers)
  • [PATCH 1/6] firewire: core: reduce stack usage in bus reset tasklet
    ... in process context when the local node's config ROM is updated, ... Slab-allocate the buffer instead. ... very unlikely though and the damage is limited (Config ROM or Topology ... u32 max_receive, u32 link_speed, u64 guid); ...
    (Linux-Kernel)
  • Re: determining process context
    ... I highly recommend using a method direct or method buffered IOCTL. ... > I am developing WDM driver and curious about process context. ... > 1) Is my Thread running in the same process context where Irp buffer ...
    (microsoft.public.development.device.drivers)

Loading