Skip to contentSkip to conversation

efi: locking fix in efivar_entry_set_safe()

PATCH In review Dan Carpenter 2 participants 2 messages Apr 30, 2013 1 message not in the archive

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

PATCH 1/1 efi: locking fix in efivar_entry_set_safe()

The intent is that if we aren't allowed to block because we're in an NMI or an emergency then we only take the lock if it is uncontended.

Part of the problem is the test is reversed so we return -EBUSY if we acquire the lock.

---
Static checker stuff. I haven't tested this.

drivers/firmware/efi/vars.c +5 -3
index 1d80c1c..f34d8fe 100644
@@ -622,10 +622,12 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
 	if (!ops->query_variable_store)
 		return -ENOSYS;
 
-	if (!block && spin_trylock_irqsave(&__efivars->lock, flags))
-		return -EBUSY;
-	else
+	if (!block) {
+		if (!spin_trylock_irqsave(&__efivars->lock, flags))
+			return -EBUSY;
+	} else {
 		spin_lock_irqsave(&__efivars->lock, flags);
+	}
 
 	status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
 	if (status != EFI_SUCCESS) {

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 9 lines · Dan Carpenter

The intent is that if we aren't allowed to block because we're in an NMI or an emergency then we only take the lock if it is uncontended.

Part of the problem is the test is reversed so we return -EBUSY if we acquire the lock.

---
Static checker stuff. I haven't tested this.

This looks correct to me. Thanks!

Quoted 20 lines
drivers/firmware/efi/vars.c +5 -3
index 1d80c1c..f34d8fe 100644
@@ -622,10 +622,12 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
 	if (!ops->query_variable_store)
 		return -ENOSYS;
 
-	if (!block && spin_trylock_irqsave(&__efivars->lock, flags))
-		return -EBUSY;
-	else
+	if (!block) {
+		if (!spin_trylock_irqsave(&__efivars->lock, flags))
+			return -EBUSY;
+	} else {
 		spin_lock_irqsave(&__efivars->lock, flags);
+	}
 
 	status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
 	if (status != EFI_SUCCESS) {
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center