[PATCH 2/2] drivers/crypto/bfin_crc.c: reposition free_irq to avoid access to invalid data

From: Julia Lawall
Date: Mon Jan 07 2013 - 04:00:21 EST

From: Julia Lawall <Julia.Lawall@xxxxxxx>

The data referenced by an interrupt handler should not be freed before the
interrupt is ended. The handler is bfin_crypto_crc_handler. It may refer
to crc->regs, which is released by the iounmap.

Furthermore, the second argument to all calls to free_irq is incorrect. It
should be the same as the last argument of request_irq, which is crc,
rather than crc->dev.

The semantic match that finds the first problem is as follows:

// <smpl>
@fn exists@
expression list es;
expression a,b;
identifier f;

if (...) {
... when any
... when any
... when any
return ...;

expression list fn.es;
expression fn.a,fn.b;
identifier fn.f;

... when any
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@xxxxxxx>

Not compiled. I have not observed the problems in practice; the code just
looks suspicious.

drivers/crypto/bfin_crc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/bfin_crc.c b/drivers/crypto/bfin_crc.c
index a22f1a9..827913d 100644
--- a/drivers/crypto/bfin_crc.c
+++ b/drivers/crypto/bfin_crc.c
@@ -694,7 +694,7 @@ out_error_dma:
dma_free_coherent(&pdev->dev, PAGE_SIZE, crc->sg_cpu, crc->sg_dma);
- free_irq(crc->irq, crc->dev);
+ free_irq(crc->irq, crc);
iounmap((void *)crc->regs);
@@ -720,10 +720,10 @@ static int bfin_crypto_crc_remove(struct platform_device *pdev)

- iounmap((void *)crc->regs);
if (crc->irq > 0)
- free_irq(crc->irq, crc->dev);
+ free_irq(crc->irq, crc);
+ iounmap((void *)crc->regs);

return 0;
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/