All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] can: fix sja1000 pre_irq/post_irq handling
@ 2013-11-18 13:01 Oliver Hartkopp
  2013-11-18 19:38 ` Wolfgang Grandegger
  2013-11-18 21:15 ` Kurt Van Dijck
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2013-11-18 13:01 UTC (permalink / raw)
  To: linux-can@vger.kernel.org; +Cc: Wolfgang Grandegger

The SJA1000 driver provides optional function pointers to handle specific
hardware setups at interrupt time.

This patch fixes the issue that the sja1000_interrupt() function may have
returned IRQ_NONE without processing the post_irq function. Additionally
an introduced and documented return value from the pre_irq function is
checked to skip the entire interrupt handling on pre_irq function errors.

Reported-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

---

v2: move irq processing counter 'n' to the end of the while statement to
return correct IRQ_[NONE|HANDLED] values at error conditions.

v3: added comments about the pre_irq() return values.

diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 7164a99..f7733d6 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -494,20 +494,21 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
 	uint8_t isrc, status;
 	int n = 0;
 
+	/* skip irq handling if the optional pre_irq() returns non-zero */
+	if (priv->pre_irq && priv->pre_irq(priv))
+		goto out;
+
 	/* Shared interrupts and IRQ off? */
 	if (priv->read_reg(priv, SJA1000_IER) == IRQ_OFF)
-		return IRQ_NONE;
-
-	if (priv->pre_irq)
-		priv->pre_irq(priv);
+		goto out;
 
 	while ((isrc = priv->read_reg(priv, SJA1000_IR)) &&
 	       (n < SJA1000_MAX_IRQ)) {
-		n++;
+
 		status = priv->read_reg(priv, SJA1000_SR);
 		/* check for absent controller due to hw unplug */
 		if (status == 0xFF && sja1000_is_absent(priv))
-			return IRQ_NONE;
+			goto out;
 
 		if (isrc & IRQ_WUI)
 			netdev_warn(dev, "wakeup interrupt\n");
@@ -535,7 +536,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
 				status = priv->read_reg(priv, SJA1000_SR);
 				/* check for absent controller */
 				if (status == 0xFF && sja1000_is_absent(priv))
-					return IRQ_NONE;
+					goto out;
 			}
 		}
 		if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
@@ -543,8 +544,9 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
 			if (sja1000_err(dev, isrc, status))
 				break;
 		}
+		n++;
 	}
-
+out:
 	if (priv->post_irq)
 		priv->post_irq(priv);
 
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h
index 9d46398..d7aaa42 100644
--- a/drivers/net/can/sja1000/sja1000.h
+++ b/drivers/net/can/sja1000/sja1000.h
@@ -157,7 +157,13 @@ struct sja1000_priv {
 	/* the lower-layer is responsible for appropriate locking */
 	u8 (*read_reg) (const struct sja1000_priv *priv, int reg);
 	void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);
-	void (*pre_irq) (const struct sja1000_priv *priv);
+
+	/*
+	 * Hardware specific optional pre_irq() and post_irq() hooks.
+	 * When pre_irq() returns a non-zero value the sja1000 irq register
+	 * handling is skipped but post_irq() is still called.
+	 */
+	int (*pre_irq) (const struct sja1000_priv *priv);
 	void (*post_irq) (const struct sja1000_priv *priv);
 
 	void *priv;		/* for board-specific data */



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

* Re: [PATCH v3] can: fix sja1000 pre_irq/post_irq handling
  2013-11-18 13:01 [PATCH v3] can: fix sja1000 pre_irq/post_irq handling Oliver Hartkopp
@ 2013-11-18 19:38 ` Wolfgang Grandegger
  2013-11-18 21:15 ` Kurt Van Dijck
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfgang Grandegger @ 2013-11-18 19:38 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can@vger.kernel.org

On 11/18/2013 02:01 PM, Oliver Hartkopp wrote:
> The SJA1000 driver provides optional function pointers to handle specific
> hardware setups at interrupt time.
> 
> This patch fixes the issue that the sja1000_interrupt() function may have
> returned IRQ_NONE without processing the post_irq function. Additionally
> an introduced and documented return value from the pre_irq function is
> checked to skip the entire interrupt handling on pre_irq function errors.
> 
> Reported-by: Wolfgang Grandegger <wg@grandegger.com>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

Acked-by: Wolfgang Grandegger <wg@grandegger.com>

Thanks,

Wolfgang.

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

* Re: [PATCH v3] can: fix sja1000 pre_irq/post_irq handling
  2013-11-18 13:01 [PATCH v3] can: fix sja1000 pre_irq/post_irq handling Oliver Hartkopp
  2013-11-18 19:38 ` Wolfgang Grandegger
@ 2013-11-18 21:15 ` Kurt Van Dijck
  2013-11-20  6:33   ` Oliver Hartkopp
  1 sibling, 1 reply; 5+ messages in thread
From: Kurt Van Dijck @ 2013-11-18 21:15 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can@vger.kernel.org, Wolfgang Grandegger

Oliver,

On Mon, Nov 18, 2013 at 02:01:14PM +0100, Oliver Hartkopp wrote:
> The SJA1000 driver provides optional function pointers to handle specific
> hardware setups at interrupt time.
> 
> This patch fixes the issue that the sja1000_interrupt() function may have
> returned IRQ_NONE without processing the post_irq function. Additionally
> an introduced and documented return value from the pre_irq function is
> checked to skip the entire interrupt handling on pre_irq function errors.

You combine fixes and new features in 1 patch.
Both are tried in addressing the problem with peak_pci,
but that doesn't make them depend on each other.

Kind regards,
Kurt

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

* Re: [PATCH v3] can: fix sja1000 pre_irq/post_irq handling
  2013-11-18 21:15 ` Kurt Van Dijck
@ 2013-11-20  6:33   ` Oliver Hartkopp
  2013-11-20  9:28     ` Kurt Van Dijck
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Hartkopp @ 2013-11-20  6:33 UTC (permalink / raw)
  To: Kurt Van Dijck; +Cc: linux-can@vger.kernel.org, Wolfgang Grandegger



On 18.11.2013 22:15, Kurt Van Dijck wrote:
> Oliver,
> 
> On Mon, Nov 18, 2013 at 02:01:14PM +0100, Oliver Hartkopp wrote:
>> The SJA1000 driver provides optional function pointers to handle specific
>> hardware setups at interrupt time.
>>
>> This patch fixes the issue that the sja1000_interrupt() function may have
>> returned IRQ_NONE without processing the post_irq function. Additionally
>> an introduced and documented return value from the pre_irq function is
>> checked to skip the entire interrupt handling on pre_irq function errors.
> 
> You combine fixes and new features in 1 patch.

You are right. The return value is not really a fix.

> Both are tried in addressing the problem with peak_pci,
> but that doesn't make them depend on each other.

It mainly isn't related to peak_pci. It just emerged in the code review when
investigating an issue with the peak_pci driver.

I have no strong opinion about splitting up the patch.

Regards,
Oliver


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

* Re: [PATCH v3] can: fix sja1000 pre_irq/post_irq handling
  2013-11-20  6:33   ` Oliver Hartkopp
@ 2013-11-20  9:28     ` Kurt Van Dijck
  0 siblings, 0 replies; 5+ messages in thread
From: Kurt Van Dijck @ 2013-11-20  9:28 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can@vger.kernel.org, Wolfgang Grandegger

Oliver,

On Wed, Nov 20, 2013 at 07:33:21AM +0100, Oliver Hartkopp wrote:
> 
> 
> On 18.11.2013 22:15, Kurt Van Dijck wrote:
> > Oliver,
> > 
> > On Mon, Nov 18, 2013 at 02:01:14PM +0100, Oliver Hartkopp wrote:
> >> The SJA1000 driver provides optional function pointers to handle specific
> >> hardware setups at interrupt time.
> >>
> >> This patch fixes the issue that the sja1000_interrupt() function may have
> >> returned IRQ_NONE without processing the post_irq function. Additionally
> >> an introduced and documented return value from the pre_irq function is
> >> checked to skip the entire interrupt handling on pre_irq function errors.
> > 
> > You combine fixes and new features in 1 patch.
> 
> You are right. The return value is not really a fix.
> 
> > Both are tried in addressing the problem with peak_pci,
> > but that doesn't make them depend on each other.
> 
> It mainly isn't related to peak_pci. It just emerged in the code review when
> investigating an issue with the peak_pci driver.
> 
> I have no strong opinion about splitting up the patch.

I propose you split up into 2 patches.

Kurt

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

end of thread, other threads:[~2013-11-20  9:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-18 13:01 [PATCH v3] can: fix sja1000 pre_irq/post_irq handling Oliver Hartkopp
2013-11-18 19:38 ` Wolfgang Grandegger
2013-11-18 21:15 ` Kurt Van Dijck
2013-11-20  6:33   ` Oliver Hartkopp
2013-11-20  9:28     ` Kurt Van Dijck

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.