Skip to contentSkip to conversation

PCI: pciehp_core, fix lock imbalance

PATCH Applied Jiri Slaby 3 participants 3 messages Jan 17, 2009 – Jan 19, 2009 PCI

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 PCI: pciehp_core, fix lock imbalance

set_lock_status omits mutex_unlock in fail path. Add the omitted unlock.

As a result a lockup caused by this can be triggered from userspace by writing 1 to /sys/bus/pci/slots/.../lock often enough.

Cc Kristen Carlson Accardi <[email protected]>
Cc Jesse Barnes <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/pci/hotplug/pciehp_core.c +3 -1
index 5482d4e..c248554 100644
@@ -126,8 +126,10 @@ static int set_lock_status(struct hotplug_slot *hotplug_slot, u8 status)
 	mutex_lock(&slot->ctrl->crit_sect);
 
 	/* has it been >1 sec since our last toggle? */
-	if ((get_seconds() - slot->last_emi_toggle) < 1)
+	if ((get_seconds() - slot->last_emi_toggle) < 1) {
+		mutex_unlock(&slot->ctrl->crit_sect);
 		return -EINVAL;
+	}
 
 	/* see what our current state is */
 	retval = get_lock_status(hotplug_slot, &value);
Signature · 2 lines
1.6.1
caught by stanse
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Jiri Slaby

set_lock_status omits mutex_unlock in fail path. Add the omitted unlock.

As a result a lockup caused by this can be triggered from userspace by writing 1 to /sys/bus/pci/slots/.../lock often enough.

Cc Kristen Carlson Accardi <[email protected]>
Cc Jesse Barnes <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/pci/hotplug/pciehp_core.c +0 -0
index 5482d4e..c248554 100644
@@ -126,8 +126,10 @@ static int set_lock_status(struct hotplug_slot *hotplug_slot, u8 status)
 	mutex_lock(&slot->ctrl->crit_sect);

drivers/pci/hotplug/pciehp_core.c static int set_lock_status(struct hotplug_slot *hotplug_slot, u8 status) · line 135

Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +3 -1
 
 	/* has it been >1 sec since our last toggle? */
-	if ((get_seconds() - slot->last_emi_toggle) < 1)
+	if ((get_seconds() - slot->last_emi_toggle) < 1) {
+		mutex_unlock(&slot->ctrl->crit_sect);
 		return -EINVAL;
+	}
 
 	/* see what our current state is */
 	retval = get_lock_status(hotplug_slot, &value);

Good catch!

Thanks,
Kenji Kaneshige

Applied
#2 lore raw
In reply to Jiri Slaby
Quoted 19 lines · Jiri Slaby

set_lock_status omits mutex_unlock in fail path. Add the omitted unlock.

As a result a lockup caused by this can be triggered from userspace by writing 1 to /sys/bus/pci/slots/.../lock often enough.

Cc Kristen Carlson Accardi <[email protected]>
Cc Jesse Barnes <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/hotplug/pciehp_core.c index 5482d4e..c248554 100644

drivers/pci/hotplug/pciehp_core.c +0 -0
@@ -126,8 +126,10 @@ static int set_lock_status(struct hotplug_slot
 *hotplug_slot, u8 status) mutex_lock(&slot->ctrl->crit_sect);

drivers/pci/hotplug/pciehp_core.c static int set_lock_status(struct hotplug_slot · line 135

Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +3 -1
 
 	/* has it been >1 sec since our last toggle? */
-	if ((get_seconds() - slot->last_emi_toggle) < 1)
+	if ((get_seconds() - slot->last_emi_toggle) < 1) {
+		mutex_unlock(&slot->ctrl->crit_sect);
 		return -EINVAL;
+	}
 
 	/* see what our current state is */
 	retval = get_lock_status(hotplug_slot, &value);

Applied to my for-linus branch (with Kenji-san's reviewed-by), thanks.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center