All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
@ 2017-04-02  7:08 ` Finn Thain
  0 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2017-04-02  7:08 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen; +Cc: linux-scsi, linux-kernel

Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
ESP chips (a normal shared IRQ did not work).

Proper mutual exclusion was missing from that patch. This patch fixes
race conditions between comparison and assignment of esp_chips[]
pointers.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/scsi/mac_esp.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index 14c0334..586efd1 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -55,6 +55,7 @@ struct mac_esp_priv {
 	int error;
 };
 static struct esp *esp_chips[2];
+static DEFINE_SPINLOCK(esp_chips_lock);
 
 #define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \
 			       platform_get_drvdata((struct platform_device *) \
@@ -562,15 +563,18 @@ static int esp_mac_probe(struct platform_device *dev)
 	}
 
 	host->irq = IRQ_MAC_SCSI;
-	esp_chips[dev->id] = esp;
-	mb();
-	if (esp_chips[!dev->id] == NULL) {
-		err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL);
-		if (err < 0) {
-			esp_chips[dev->id] = NULL;
-			goto fail_free_priv;
-		}
+
+	/* The request_irq() call is intended to succeed for the first device
+	 * and fail for the second device.
+	 */
+	err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL);
+	spin_lock(&esp_chips_lock);
+	if (err < 0 && esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
+		goto fail_free_priv;
 	}
+	esp_chips[dev->id] = esp;
+	spin_unlock(&esp_chips_lock);
 
 	err = scsi_esp_register(esp, &dev->dev);
 	if (err)
@@ -579,8 +583,13 @@ static int esp_mac_probe(struct platform_device *dev)
 	return 0;
 
 fail_free_irq:
-	if (esp_chips[!dev->id] == NULL)
+	spin_lock(&esp_chips_lock);
+	esp_chips[dev->id] = NULL;
+	if (esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
 		free_irq(host->irq, esp);
+	} else
+		spin_unlock(&esp_chips_lock);
 fail_free_priv:
 	kfree(mep);
 fail_free_command_block:
@@ -599,9 +608,13 @@ static int esp_mac_remove(struct platform_device *dev)
 
 	scsi_esp_unregister(esp);
 
+	spin_lock(&esp_chips_lock);
 	esp_chips[dev->id] = NULL;
-	if (!(esp_chips[0] || esp_chips[1]))
+	if (esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
 		free_irq(irq, NULL);
+	} else
+		spin_unlock(&esp_chips_lock);
 
 	kfree(mep);
 
-- 
2.10.2

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

* [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
@ 2017-04-02  7:08 ` Finn Thain
  0 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2017-04-02  7:08 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen; +Cc: linux-scsi, linux-kernel

Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
ESP chips (a normal shared IRQ did not work).

Proper mutual exclusion was missing from that patch. This patch fixes
race conditions between comparison and assignment of esp_chips[]
pointers.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/scsi/mac_esp.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index 14c0334..586efd1 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -55,6 +55,7 @@ struct mac_esp_priv {
 	int error;
 };
 static struct esp *esp_chips[2];
+static DEFINE_SPINLOCK(esp_chips_lock);
 
 #define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \
 			       platform_get_drvdata((struct platform_device *) \
@@ -562,15 +563,18 @@ static int esp_mac_probe(struct platform_device *dev)
 	}
 
 	host->irq = IRQ_MAC_SCSI;
-	esp_chips[dev->id] = esp;
-	mb();
-	if (esp_chips[!dev->id] == NULL) {
-		err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL);
-		if (err < 0) {
-			esp_chips[dev->id] = NULL;
-			goto fail_free_priv;
-		}
+
+	/* The request_irq() call is intended to succeed for the first device
+	 * and fail for the second device.
+	 */
+	err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL);
+	spin_lock(&esp_chips_lock);
+	if (err < 0 && esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
+		goto fail_free_priv;
 	}
+	esp_chips[dev->id] = esp;
+	spin_unlock(&esp_chips_lock);
 
 	err = scsi_esp_register(esp, &dev->dev);
 	if (err)
@@ -579,8 +583,13 @@ static int esp_mac_probe(struct platform_device *dev)
 	return 0;
 
 fail_free_irq:
-	if (esp_chips[!dev->id] == NULL)
+	spin_lock(&esp_chips_lock);
+	esp_chips[dev->id] = NULL;
+	if (esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
 		free_irq(host->irq, esp);
+	} else
+		spin_unlock(&esp_chips_lock);
 fail_free_priv:
 	kfree(mep);
 fail_free_command_block:
@@ -599,9 +608,13 @@ static int esp_mac_remove(struct platform_device *dev)
 
 	scsi_esp_unregister(esp);
 
+	spin_lock(&esp_chips_lock);
 	esp_chips[dev->id] = NULL;
-	if (!(esp_chips[0] || esp_chips[1]))
+	if (esp_chips[!dev->id] == NULL) {
+		spin_unlock(&esp_chips_lock);
 		free_irq(irq, NULL);
+	} else
+		spin_unlock(&esp_chips_lock);
 
 	kfree(mep);
 
-- 
2.10.2

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
  2017-04-02  7:08 ` Finn Thain
@ 2017-04-24 22:29   ` Martin K. Petersen
  -1 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2017-04-24 22:29 UTC (permalink / raw)
  To: Finn Thain, Ondrej Zary, Michael Schmitz
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi, linux-kernel


Finn,

> Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
> added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
> ESP chips (a normal shared IRQ did not work).
>
> Proper mutual exclusion was missing from that patch. This patch fixes
> race conditions between comparison and assignment of esp_chips[]
> pointers.

Ondrej/Michael: Mind reviewing this change?

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
@ 2017-04-24 22:29   ` Martin K. Petersen
  0 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2017-04-24 22:29 UTC (permalink / raw)
  To: Finn Thain, Ondrej Zary, Michael Schmitz
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi, linux-kernel


Finn,

> Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
> added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
> ESP chips (a normal shared IRQ did not work).
>
> Proper mutual exclusion was missing from that patch. This patch fixes
> race conditions between comparison and assignment of esp_chips[]
> pointers.

Ondrej/Michael: Mind reviewing this change?

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
  2017-04-24 22:29   ` Martin K. Petersen
  (?)
@ 2017-04-24 23:25   ` Michael Schmitz
  2017-04-24 23:29     ` Martin K. Petersen
  -1 siblings, 1 reply; 8+ messages in thread
From: Michael Schmitz @ 2017-04-24 23:25 UTC (permalink / raw)
  To: Martin K. Petersen, Finn Thain, Ondrej Zary
  Cc: James E.J. Bottomley, linux-scsi

Hi Martin,

I must have missed that one - where was it posted to?

Cheers,

	Michael


Am 25.04.2017 um 10:29 schrieb Martin K. Petersen:
> 
> Finn,
> 
>> Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
>> added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
>> ESP chips (a normal shared IRQ did not work).
>>
>> Proper mutual exclusion was missing from that patch. This patch fixes
>> race conditions between comparison and assignment of esp_chips[]
>> pointers.
> 
> Ondrej/Michael: Mind reviewing this change?
> 

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
  2017-04-24 23:25   ` Michael Schmitz
@ 2017-04-24 23:29     ` Martin K. Petersen
  0 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2017-04-24 23:29 UTC (permalink / raw)
  To: Michael Schmitz
  Cc: Martin K. Petersen, Finn Thain, Ondrej Zary,
	James E.J. Bottomley, linux-scsi


Michael,

> I must have missed that one - where was it posted to?

Usual bat channel:

https://patchwork.kernel.org/patch/9658369/

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
  2017-04-24 22:29   ` Martin K. Petersen
  (?)
  (?)
@ 2017-04-25  2:14   ` Michael Schmitz
  2017-04-25 16:53     ` Martin K. Petersen
  -1 siblings, 1 reply; 8+ messages in thread
From: Michael Schmitz @ 2017-04-25  2:14 UTC (permalink / raw)
  To: Martin K. Petersen, Finn Thain, Ondrej Zary
  Cc: James E.J. Bottomley, linux-scsi, linux-kernel

Martin,

looks good to me, so:

Reviewed-By: Michael Schmitz <schmitzmic@gmail.com>


Am 25.04.2017 um 10:29 schrieb Martin K. Petersen:
> 
> Finn,
> 
>> Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips")
>> added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board
>> ESP chips (a normal shared IRQ did not work).
>>
>> Proper mutual exclusion was missing from that patch. This patch fixes
>> race conditions between comparison and assignment of esp_chips[]
>> pointers.
> 
> Ondrej/Michael: Mind reviewing this change?
> 

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

* Re: [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock
  2017-04-25  2:14   ` Michael Schmitz
@ 2017-04-25 16:53     ` Martin K. Petersen
  0 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2017-04-25 16:53 UTC (permalink / raw)
  To: Michael Schmitz
  Cc: Martin K. Petersen, Finn Thain, Ondrej Zary,
	James E.J. Bottomley, linux-scsi, linux-kernel


Michael,

> looks good to me, so:
>
> Reviewed-By: Michael Schmitz <schmitzmic@gmail.com>

Applied to 4.12/scsi-queue.

Thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2017-04-25 16:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-02  7:08 [PATCH] scsi/mac_esp: Replace bogus memory barrier with spinlock Finn Thain
2017-04-02  7:08 ` Finn Thain
2017-04-24 22:29 ` Martin K. Petersen
2017-04-24 22:29   ` Martin K. Petersen
2017-04-24 23:25   ` Michael Schmitz
2017-04-24 23:29     ` Martin K. Petersen
2017-04-25  2:14   ` Michael Schmitz
2017-04-25 16:53     ` Martin K. Petersen

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.