All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IRQ : bug fix in setup_irq
@ 2008-07-18 10:21 sasa sasa
  2008-07-18 22:18 ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: sasa sasa @ 2008-07-18 10:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner

[-- Attachment #1: Type: text/plain, Size: 2121 bytes --]

>From ebb5cb875363822e7c2dc17dae36f14dd4a0e71e Mon Sep 17 00:00:00 2001
From: Sandeep Kaushik <sandeep-mmc.kaushik@st.com>
Date: Fri, 18 Jul 2008 14:58:19 +0530
Subject: [PATCH] IRQ : bug fix in setup_irq

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@st.com>
---
 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

[-- Attachment #2: 0001-IRQ-bug-fix-in-setup_irq.patch --]
[-- Type: application/octet-stream, Size: 2127 bytes --]

From ebb5cb875363822e7c2dc17dae36f14dd4a0e71e Mon Sep 17 00:00:00 2001
From: Sandeep Kaushik <sandeep-mmc.kaushik@st.com>
Date: Fri, 18 Jul 2008 14:58:19 +0530
Subject: [PATCH] IRQ : bug fix in setup_irq

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@st.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] IRQ : bug fix in setup_irq
  2008-07-18 10:21 sasa sasa
@ 2008-07-18 22:18 ` Thomas Gleixner
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2008-07-18 22:18 UTC (permalink / raw)
  To: sasa sasa; +Cc: linux-kernel

On Fri, 18 Jul 2008, sasa sasa wrote:
> 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;

No need to initialize to zero.

>  		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
> +					 */

		That's not desc->action. That's the end of the desc->action list

> +					*p = NULL;

Can we have a printk here, which tells us what went wrong ?

> +					spin_unlock_irqrestore(&desc->lock,
> +								flags);
> +					return -EBUSY;

  Please use the already existing error exit via "goto ..." instead

> +				}
> +			}
>  			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);

We dont want to know that the setup function returned -EBUSY. We
rather want to have a printk in the path above.

Thanks,
	tglx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] IRQ : bug fix in setup_irq
@ 2008-07-22  8:42 sasa sasa
  2008-07-22 11:23 ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: sasa sasa @ 2008-07-22  8:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

>From cf76c764e891a90ab0aaf322327e47e3a3302492 Mon Sep 17 00:00:00 2001
From: Sandeep Kaushik <sandeep-mmc.kaushik@st.com>
Date: Tue, 22 Jul 2008 13:20:51 +0530
Subject: [PATCH] IRQ : bug fix in setup_irq

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
architecture dependent pin's set_type function returned error.

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

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

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

 #if defined(CONFIG_IRQ_PER_CPU)
@@ -346,11 +348,25 @@ 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))) {
+					printk(KERN_ERR "IRQF_TRIGGER set_type"
+							"function for IRQ"
+							"%d (%s) failed\n",
+							irq, desc->chip->name);
+					/*
+					 * Action handler gets freed but
+					 * last action handler on desc->action
+					 * list also needs to bet to NULL.
+					 */
+					*p = NULL;
+					goto mismatch;
+				}
+			}
 			else
 				/*
 				 * IRQF_TRIGGER_* but the PIC does not support
-- 
1.5.6.GIT

[-- Attachment #2: 0001-IRQ-bug-fix-in-setup_irq_new1.patch --]
[-- Type: application/octet-stream, Size: 1856 bytes --]

From cf76c764e891a90ab0aaf322327e47e3a3302492 Mon Sep 17 00:00:00 2001
From: Sandeep Kaushik <sandeep-mmc.kaushik@st.com>
Date: Tue, 22 Jul 2008 13:20:51 +0530
Subject: [PATCH] IRQ : bug fix in setup_irq

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
architecture dependent pin's set_type function returned error.

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

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 1f31422..a90ed1c 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -339,6 +339,8 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 		desc->status |= IRQ_NO_BALANCING;
 
 	if (!shared) {
+		int trigger_type;
+
 		irq_chip_set_defaults(desc->chip);
 
 #if defined(CONFIG_IRQ_PER_CPU)
@@ -346,11 +348,25 @@ 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))) {
+					printk(KERN_ERR "IRQF_TRIGGER set_type"
+							"function for IRQ"
+							"%d (%s) failed\n",
+							irq, desc->chip->name);
+					/*
+					 * Action handler gets freed but
+					 * last action handler on desc->action
+					 * list also needs to bet to NULL.
+					 */
+					*p = NULL;
+					goto mismatch;
+				}
+			}
 			else
 				/*
 				 * IRQF_TRIGGER_* but the PIC does not support
-- 
1.5.6.GIT


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] IRQ : bug fix in setup_irq
  2008-07-22  8:42 [PATCH] IRQ : bug fix in setup_irq sasa sasa
@ 2008-07-22 11:23 ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2008-07-22 11:23 UTC (permalink / raw)
  To: sasa sasa; +Cc: Thomas Gleixner, linux-kernel

Hello Sandeep,

there is a patch in -mm that does the same (and more, so it asserts that
irqaction *new isn't added to the desc->action list if set_type fails.)

See http://thread.gmane.org/gmane.linux.kernel/698011/focus=702236 or 

	handle-failure-of-irqchip-set_type-in-setup_irq.patch
	handle-failure-of-irqchip-set_type-in-setup_irq-update.patch

in mmotm.

Best regards
Uwe

-- 
Uwe Kleine-König, Software Engineer
Digi International GmbH Branch Breisach, Küferstrasse 8, 79206 Breisach, Germany
Tax: 315/5781/0242 / VAT: DE153662976 / Reg. Amtsgericht Dortmund HRB 13962

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-22 11:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-22  8:42 [PATCH] IRQ : bug fix in setup_irq sasa sasa
2008-07-22 11:23 ` Uwe Kleine-König
  -- strict thread matches above, loose matches on Subject: below --
2008-07-18 10:21 sasa sasa
2008-07-18 22:18 ` Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.