Skip to contentSkip to conversation

target: Make se_dev_check_online() locking IRQ-safe

PATCH In review Roland Dreier 2 participants 2 messages Jun 14, 2011 – Jun 15, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: Make se_dev_check_online() locking IRQ-safe

From: Roland Dreier <[email protected]>

se_dev_check_online() is called from transport_lookup_cmd_lun(), which as discussed before may be called from interrupt context. So it needs to use spin_lock_irqsave() instead of spin_lock_irq() to avoid enabling interrupts at the wrong time.

---
 drivers/target/target_core_device.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/target/target_core_device.c +3 -2
index fcb8161..f2a4bf2 100644
@@ -815,12 +815,13 @@ static void se_dev_stop(struct se_device *dev)
 
 int se_dev_check_online(struct se_device *dev)
 {
+	unsigned long flags;
 	int ret;
 
-	spin_lock_irq(&dev->dev_status_lock);
+	spin_lock_irqsave(&dev->dev_status_lock, flags);
 	ret = ((dev->dev_status & TRANSPORT_DEVICE_ACTIVATED) ||
 	       (dev->dev_status & TRANSPORT_DEVICE_DEACTIVATED)) ? 0 : 1;
-	spin_unlock_irq(&dev->dev_status_lock);
+	spin_unlock_irqrestore(&dev->dev_status_lock, flags);
 
 	return ret;
 }
#1 lore raw
Quoted 8 lines · Roland Dreier

From: Roland Dreier <[email protected]>

se_dev_check_online() is called from transport_lookup_cmd_lun(), which as discussed before may be called from interrupt context. So it needs to use spin_lock_irqsave() instead of spin_lock_irq() to avoid enabling interrupts at the wrong time.

Committed as 91e8524637

Thanks Roland!

--nab

Quoted 28 lines
---
 drivers/target/target_core_device.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/target/target_core_device.c +3 -3
index fcb8161..f2a4bf2 100644
@@ -815,12 +815,13 @@ static void se_dev_stop(struct se_device *dev)
 
 int se_dev_check_online(struct se_device *dev)
 {
+	unsigned long flags;
 	int ret;
 
-	spin_lock_irq(&dev->dev_status_lock);
+	spin_lock_irqsave(&dev->dev_status_lock, flags);
 	ret = ((dev->dev_status & TRANSPORT_DEVICE_ACTIVATED) ||
 	       (dev->dev_status & TRANSPORT_DEVICE_DEACTIVATED)) ? 0 : 1;
-	spin_unlock_irq(&dev->dev_status_lock);
+	spin_unlock_irqrestore(&dev->dev_status_lock, flags);
 
 	return ret;
 }
--

To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html