[PATCH] IRQ : bug fix in setup_irq

From: Sandeep Kaushik
Date: Fri Jul 18 2008 - 05:28:19 EST


This patch is for bug fix in setup_irq function.
Error handling is added in setup_irq function. This is required in case if some
rchitecture dependent pins like gpio pins are requested as interrupt pin and
they are already occupied by other devices in some other modes, then setup_irq
must return error.

Signed-off-by: Sandeep Kaushik <sandeep-mmc.kaushik@xxxxxx>
---
kernel/irq/manage.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 1f31422..ca92f97 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -339,6 +339,7 @@ int setup_irq(unsigned int irq, struct irqaction *new)
desc->status |= IRQ_NO_BALANCING;

if (!shared) {
+ int trigger_type = 0;
irq_chip_set_defaults(desc->chip);

#if defined(CONFIG_IRQ_PER_CPU)
@@ -346,11 +347,22 @@ int setup_irq(unsigned int irq, struct irqaction *new)
desc->status |= IRQ_PER_CPU;
#endif

+ trigger_type = new->flags & IRQF_TRIGGER_MASK;
+
/* Setup the type (level, edge polarity) if configured: */
- if (new->flags & IRQF_TRIGGER_MASK) {
- if (desc->chip && desc->chip->set_type)
- desc->chip->set_type(irq,
- new->flags & IRQF_TRIGGER_MASK);
+ if (trigger_type) {
+ if (desc->chip && desc->chip->set_type) {
+ if ((desc->chip->set_type(irq, trigger_type))) {
+ /* Action handler gets freed but
+ * desc->action also needs to be
+ * set to NULL
+ */
+ *p = NULL;
+ spin_unlock_irqrestore(&desc->lock,
+ flags);
+ return -EBUSY;
+ }
+ }
else
/*
* IRQF_TRIGGER_* but the PIC does not support
@@ -571,8 +583,10 @@ int request_irq(unsigned int irq, irq_handler_t handler,
#endif

retval = setup_irq(irq, action);
- if (retval)
+ if (retval) {
+ printk(KERN_WARNING"Failed to allocate interrupt %d\n", retval);
kfree(action);
+ }

return retval;
}
--
1.5.6.GIT

------=_Part_47759_14874118.1216376462261
Content-Type: application/octet-stream;
name=0001-IRQ-bug-fix-in-setup_irq.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fisn22io0
Content-Disposition: attachment;
filename=0001-IRQ-bug-fix-in-setup_irq.patch

RnJvbSBlYmI1Y2I4NzUzNjM4MjJlN2MyZGMxN2RhZTM2ZjE0ZGQ0YTBlNzFlIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBTYW5kZWVwIEthdXNoaWsgPHNhbmRlZXAtbW1jLmthdXNoaWtA
c3QuY29tPgpEYXRlOiBGcmksIDE4IEp1bCAyMDA4IDE0OjU4OjE5ICswNTMwClN1YmplY3Q6IFtQ
QVRDSF0gSVJRIDogYnVnIGZpeCBpbiBzZXR1cF9pcnEKClRoaXMgcGF0Y2ggaXMgZm9yIGJ1ZyBm
aXggaW4gc2V0dXBfaXJxIGZ1bmN0aW9uLgpFcnJvciBoYW5kbGluZyBpcyBhZGRlZCBpbiBzZXR1
cF9pcnEgZnVuY3Rpb24uIFRoaXMgaXMgcmVxdWlyZWQgaW4gY2FzZSBpZiBzb21lCnJjaGl0ZWN0
dXJlIGRlcGVuZGVudCBwaW5zIGxpa2UgZ3BpbyBwaW5zIGFyZSByZXF1ZXN0ZWQgYXMgaW50ZXJy
dXB0IHBpbiBhbmQgCnRoZXkgYXJlIGFscmVhZHkgb2NjdXBpZWQgYnkgb3RoZXIgZGV2aWNlcyBp
biBzb21lIG90aGVyIG1vZGVzLCB0aGVuIHNldHVwX2lycQptdXN0IHJldHVybiBlcnJvci4KClNp
Z25lZC1vZmYtYnk6IFNhbmRlZXAgS2F1c2hpayA8c2FuZGVlcC1tbWMua2F1c2hpa0BzdC5jb20+
Ci0tLQoga2VybmVsL2lycS9tYW5hZ2UuYyB8ICAgMjQgKysrKysrKysrKysrKysrKysrKy0tLS0t
CiAxIGZpbGVzIGNoYW5nZWQsIDE5IGluc2VydGlvbnMoKyksIDUgZGVsZXRpb25zKC0pCgpkaWZm
IC0tZ2l0IGEva2VybmVsL2lycS9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aGlwLT5zZXRfdHlwZSkJeworCQkJCWlmICgoZGVzYy0+Y2hpcC0+c2V0X3R5cGUoaXJx
LCB0cmlnZ2VyX3R5cGUpKSkgeworCQkJCQkvKiBBY3Rpb24gaGFuZGxlciBnZXRzIGZyZWVkIGJ1
dAorCQkJCQkgKiBkZXNjLT5hY3Rpb24gYWxzbyBuZWVkcyB0byBiZQorCQkJCQkgKiBzZXQgdG8g
TlVMTAorCQkJCQkgKi8KKwkJCQkJKnAgPSBOVUxMOworCQkJCQlzcGluX3VubG9ja19pcnFyZXN0
b3JlKCZkZXNjLT5sb2NrLAorCQkJCQkJCQlmbGFncyk7CisJCQkJCXJldHVybiAtRUJVU1k7CisJ
CQkJfQorCQkJfQogCQkJZWxzZQogCQkJCS8qCiAJCQkJICogSVJRRl9UUklHR0VSXyogYnV0IHRo
ZSBQSUMgZG9lcyBub3Qgc3VwcG9ydApAQCAtNTcxLDggKzU4MywxMCBAQCBpbnQgcmVxdWVzdF9p
cnEodW5zaWduZWQgaW50IGlycSwgaXJxX2hhbmRsZXJfdCBoYW5kbGVyLAogI2VuZGlmCiAKIAly
ZXR2YWwgPSBzZXR1cF9pcnEoaXJxLCBhY3Rpb24pOwotCWlmIChyZXR2YWwpCisJaWYgKHJldHZh
bCkgeworCQlwcmludGsoS0VSTl9XQVJOSU5HIkZhaWxlZCB0byBhbGxvY2F0ZSBpbnRlcnJ1cHQg
JWRcbiIsIHJldHZhbCk7CiAJCWtmcmVlKGFjdGlvbik7CisJfQogCiAJcmV0dXJuIHJldHZhbDsK
IH0KLS0gCjEuNS42LkdJVAoK
------=_Part_47759_14874118.1216376462261--
--
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/